Skip to content

Commit

Permalink
feat: support custom defualt level per file
Browse files Browse the repository at this point in the history
  • Loading branch information
guopenghui committed Jun 23, 2024
1 parent d99b3d8 commit 160f28d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 51 deletions.
47 changes: 1 addition & 46 deletions main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-quiet-outline",
"name": "Quiet Outline",
"version": "0.3.32",
"version": "0.3.33",
"minAppVersion": "0.15.6",
"description": "Make outline quiet and more powerful, including no-auto-expand, rendering heading as markdown, and search support.",
"author": "the_tree",
Expand Down
27 changes: 23 additions & 4 deletions src/Outline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,20 @@ function nearestHeading(line: number): undefined | number {
return i;
}
function getDefaultLevel(): number {
let level = undefined
if(plugin.current_note?.file) {
const cache = plugin.app.metadataCache.getFileCache(plugin.current_note.file)
level = cache?.frontmatter?.["qo-default-level"];
if(typeof level === "string") {
level = parseInt(level)
}
}
return level || parseInt(plugin.settings.expand_level)
}
function autoExpand(index: number) {
if (plugin.settings.auto_expand_ext !== "disable") {
let current_heading = store.headers[index];
Expand All @@ -438,7 +452,9 @@ function autoExpand(index: number) {
if(plugin.settings.auto_expand_ext === "expand-and-collapse-rest-to-setting") {
expanded.value = filterKeysLessThanEqual(level.value);
} else if(plugin.settings.auto_expand_ext === "expand-and-collapse-rest-to-default") {
expanded.value = filterKeysLessThanEqual(parseInt(plugin.settings.expand_level));
const defaultLevel = getDefaultLevel()
expanded.value = filterKeysLessThanEqual(defaultLevel);
// expanded.value = filterKeysLessThanEqual(parseInt(plugin.settings.expand_level));
}
modifyExpandKeys(
Expand Down Expand Up @@ -572,7 +588,8 @@ onUnmounted(() => {
});
// switch heading expand levels
let level = ref(parseInt(plugin.settings.expand_level));
// let level = ref(parseInt(plugin.settings.expand_level));
let level = ref(getDefaultLevel());
let expanded = ref<string[]>([]);
switchLevel(level.value);
Expand Down Expand Up @@ -689,7 +706,8 @@ watch(
const old_pattern = pattern.value;
pattern.value = "";
level.value = parseInt(plugin.settings.expand_level);
level.value = getDefaultLevel()
// parseInt(plugin.settings.expand_level);
const old_state = plugin.heading_states[plugin.current_file];
if (plugin.settings.remember_state && old_state) {
Expand Down Expand Up @@ -910,7 +928,8 @@ async function toBottom() {
// reset button
function reset() {
pattern.value = "";
level.value = parseInt(plugin.settings.expand_level);
level.value = getDefaultLevel()
// parseInt(plugin.settings.expand_level);
switchLevel(level.value);
}
Expand Down

0 comments on commit 160f28d

Please sign in to comment.