diff --git a/main.js b/main.js index 5cd4c2f1..99216480 100644 --- a/main.js +++ b/main.js @@ -9977,7 +9977,27 @@ async function waitForCache(plugin) { } } const linkClass = (app, to, realQ = true) => `internal-link BC-Link ${isInVault(app, to) ? "" : "is-unresolved"} ${realQ ? "" : "BC-Implied"}`; -const getDVApi = (plugin) => { var _a; return (_a = plugin.app.plugins.plugins.dataview) === null || _a === void 0 ? void 0 : _a.api; }; +const getDVApi = (plugin) => { var _a; return (_a = plugin.app.plugins.plugins.dataview) === null || _a === void 0 ? void 0 : _a.api; }; +function isInsideYaml(app) { + const { workspace, metadataCache } = app; + const { activeLeaf } = workspace; + const { state: { mode }, } = activeLeaf.getViewState(); + if (mode !== "source") + return null; + const { editor } = activeLeaf.view; + const file = workspace.getActiveFile(); + if (!file) + return null; + const { frontmatter } = metadataCache.getFileCache(file); + if (!frontmatter) + return false; + const { start, end } = frontmatter.position; + const currOff = editor.posToOffset(editor.getCursor()); + if (currOff >= start.offset + 4 && currOff <= end.offset - 4) + return true; + else + return false; +} function noop() { } function assign(tar, src) { @@ -10420,7 +10440,7 @@ class SvelteComponent { /* src\Components\ModifyHNItemComp.svelte generated by Svelte v3.35.0 */ -function add_css$e() { +function add_css$f() { var style = element("style"); style.id = "svelte-13g4k7i-style"; style.textContent = "pre.svelte-13g4k7i{display:inline}"; @@ -10830,7 +10850,7 @@ function instance$p($$self, $$props, $$invalidate) { class ModifyHNItemComp extends SvelteComponent { constructor(options) { super(); - if (!document.getElementById("svelte-13g4k7i-style")) add_css$e(); + if (!document.getElementById("svelte-13g4k7i-style")) add_css$f(); init(this, options, instance$p, create_fragment$p, safe_not_equal, { modal: 1, @@ -29710,7 +29730,7 @@ const indexToLinePairs = (index, flat = false) => index /* src\Components\RenderMarkdown.svelte generated by Svelte v3.35.0 */ -function add_css$d() { +function add_css$e() { var style = element("style"); style.id = "svelte-7e9i10-style"; style.textContent = "div.BC-note-content.svelte-7e9i10{padding-left:20px}"; @@ -29810,14 +29830,14 @@ function instance$o($$self, $$props, $$invalidate) { class RenderMarkdown extends SvelteComponent { constructor(options) { super(); - if (!document.getElementById("svelte-7e9i10-style")) add_css$d(); + if (!document.getElementById("svelte-7e9i10-style")) add_css$e(); init(this, options, instance$o, create_fragment$o, safe_not_equal, { path: 1, app: 2 }); } } /* src\Components\CBTree.svelte generated by Svelte v3.35.0 */ -function add_css$c() { +function add_css$d() { var style = element("style"); style.id = "svelte-1df5nr5-style"; style.textContent = ".BC-tree.svelte-1df5nr5{padding-left:5px}pre.indent.svelte-1df5nr5{display:inline;background-color:transparent;position:top}details.svelte-1df5nr5{display:inline-block}.is-unresolved.svelte-1df5nr5{color:var(--text-muted)}"; @@ -30311,7 +30331,7 @@ function instance$n($$self, $$props, $$invalidate) { class CBTree extends SvelteComponent { constructor(options) { super(); - if (!document.getElementById("svelte-1df5nr5-style")) add_css$c(); + if (!document.getElementById("svelte-1df5nr5-style")) add_css$d(); init(this, options, instance$n, create_fragment$n, safe_not_equal, { plugin: 10, @@ -31905,7 +31925,7 @@ function addTraverseNotesToGraph(plugin, traverseNotes, mainG, obsG) { /* src\Components\NextPrev.svelte generated by Svelte v3.35.0 */ -function add_css$b() { +function add_css$c() { var style = element("style"); style.id = "svelte-11g23nm-style"; style.textContent = ".BC-nexts.svelte-11g23nm div.svelte-11g23nm{text-align:right}.BC-nexts.svelte-11g23nm.svelte-11g23nm{border-left:1px solid var(--background-modifier-border)}.BC-prevs.svelte-11g23nm.svelte-11g23nm{border-right:1px solid var(--background-modifier-border)}.BC-NextPrev-Container.svelte-11g23nm.svelte-11g23nm{display:grid;grid-template-columns:1fr 1fr}"; @@ -32183,14 +32203,14 @@ function instance$k($$self, $$props, $$invalidate) { class NextPrev extends SvelteComponent { constructor(options) { super(); - if (!document.getElementById("svelte-11g23nm-style")) add_css$b(); + if (!document.getElementById("svelte-11g23nm-style")) add_css$c(); init(this, options, instance$k, create_fragment$k, safe_not_equal, { plugin: 3, next: 0, prev: 1 }); } } /* src\Components\TrailGrid.svelte generated by Svelte v3.35.0 */ -function add_css$a() { +function add_css$b() { var style = element("style"); style.id = "svelte-1a33qd9-style"; style.textContent = "div.BC-trail-grid.svelte-1a33qd9{border:2px solid var(--background-modifier-border);display:grid;align-items:stretch;width:auto;height:auto}div.BC-trail-grid-item.svelte-1a33qd9{display:flex;flex-direction:column;border:1px solid var(--background-modifier-border);align-items:center;justify-content:center;padding:2px;font-size:smaller}div.BC-trail-grid-item.BC-filler.svelte-1a33qd9{opacity:0.7}.dot.svelte-1a33qd9{height:5px;width:5px;border-radius:50%;display:inline-block}"; @@ -32559,14 +32579,14 @@ function instance$j($$self, $$props, $$invalidate) { class TrailGrid extends SvelteComponent { constructor(options) { super(); - if (!document.getElementById("svelte-1a33qd9-style")) add_css$a(); + if (!document.getElementById("svelte-1a33qd9-style")) add_css$b(); init(this, options, instance$j, create_fragment$j, safe_not_equal, { sortedTrails: 0, plugin: 1 }, [-1, -1]); } } /* src\Components\TrailPath.svelte generated by Svelte v3.35.0 */ -function add_css$9() { +function add_css$a() { var style = element("style"); style.id = "svelte-3c1frp-style"; style.textContent = "span.BC-trail-path-container.svelte-3c1frp{display:flex;justify-content:space-between}"; @@ -32963,26 +32983,28 @@ function instance$i($$self, $$props, $$invalidate) { class TrailPath extends SvelteComponent { constructor(options) { super(); - if (!document.getElementById("svelte-3c1frp-style")) add_css$9(); + if (!document.getElementById("svelte-3c1frp-style")) add_css$a(); init(this, options, instance$i, create_fragment$i, safe_not_equal, { sortedTrails: 0, plugin: 1 }); } } function getLimitedTrailSub(plugin) { - const { settings, mainG } = plugin; + const { settings, mainG, closedG } = plugin; const { limitTrailCheckboxes, userHiers } = settings; - let subGraph; if (getFields(userHiers).every((field) => limitTrailCheckboxes.includes(field))) { - subGraph = getSubInDirs(mainG, "up", "down"); + return getSubInDirs(closedG, "up"); } else { const oppFields = limitTrailCheckboxes .map((field) => { var _a; return (_a = getOppFields(userHiers, field, "up")) === null || _a === void 0 ? void 0 : _a[0]; }) .filter((field) => field !== undefined); - subGraph = getSubForFields(mainG, [...limitTrailCheckboxes, ...oppFields]); + const subGraph = getSubForFields(mainG, [ + ...limitTrailCheckboxes, + ...oppFields, + ]); + const closed = getReflexiveClosure(subGraph, userHiers); + return getSubInDirs(closed, "up"); } - const closed = getReflexiveClosure(subGraph, userHiers); - return getSubInDirs(closed, "up"); } function getBreadcrumbs(settings, g, currFile) { const { basename, extension } = currFile; @@ -33494,6 +33516,13 @@ class RelationSuggestor extends obsidian.EditorSuggest { /* src\Components\KoFi.svelte generated by Svelte v3.35.0 */ +function add_css$9() { + var style = element("style"); + style.id = "svelte-1j4tt4j-style"; + style.textContent = ".BC-Kofi-button.svelte-1j4tt4j{margin-top:10px}"; + append(document.head, style); +} + function create_fragment$h(ctx) { let script; let script_src_value; @@ -33509,6 +33538,7 @@ function create_fragment$h(ctx) { div = element("div"); attr(script, "type", "text/javascript"); if (script.src !== (script_src_value = "https://ko-fi.com/widgets/widget_2.js")) attr(script, "src", script_src_value); + attr(div, "class", "BC-Kofi-button svelte-1j4tt4j"); }, m(target, anchor) { append(document.head, script); @@ -33556,6 +33586,7 @@ function instance$h($$self, $$props, $$invalidate) { class KoFi extends SvelteComponent { constructor(options) { super(); + if (!document.getElementById("svelte-1j4tt4j-style")) add_css$9(); init(this, options, instance$h, create_fragment$h, safe_not_equal, {}); } } @@ -33681,7 +33712,7 @@ function get_each_context$7(ctx, list, i) { return child_ctx; } -// (43:2) {#each options as option} +// (42:2) {#each options as option} function create_each_block$7(ctx) { let div; let label; @@ -33835,6 +33866,8 @@ function create_fragment$g(ctx) { } function instance$g($$self, $$props, $$invalidate) { + let toNone; + var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P @@ -33877,7 +33910,6 @@ function instance$g($$self, $$props, $$invalidate) { let { options } = $$props; const { settings } = plugin; let selected = settings[settingName]; - let toNone = selected.length === 0 ? false : true; function save() { return __awaiter(this, void 0, void 0, function* () { @@ -34027,17 +34059,6 @@ function addGeneralSettings(plugin, containerEl) { settings.parseJugglLinksWithoutJuggl = value; await plugin.saveSettings(); })); - generalDetails.createDiv().createEl("strong", { - text: "When running `Jump to first ` command, limit which fields it can use.", - }); - new Checkboxes({ - target: generalDetails, - props: { - plugin, - settingName: "limitJumpToFirstFields", - options: getFields(settings.userHiers), - }, - }); if (plugin.app.plugins.plugins.dataview !== undefined) { new obsidian.Setting(generalDetails) .setName("Dataview Wait Time") @@ -34499,22 +34520,22 @@ function add_css$6() { function get_each_context$6(ctx, list, i) { const child_ctx = ctx.slice(); - child_ctx[12] = list[i]; - child_ctx[14] = i; + child_ctx[13] = list[i]; + child_ctx[15] = i; return child_ctx; } function get_each_context_1$5(ctx, list, i) { const child_ctx = ctx.slice(); - child_ctx[15] = list[i]; + child_ctx[16] = list[i]; return child_ctx; } -// (100:6) {#each DIRECTIONS as dir} +// (118:6) {#each DIRECTIONS as dir} function create_each_block_1$5(ctx) { let div; let label; - let t0_value = ARROW_DIRECTIONS[/*dir*/ ctx[15]] + ""; + let t0_value = ARROW_DIRECTIONS[/*dir*/ ctx[16]] + ""; let t0; let label_for_value; let t1; @@ -34525,7 +34546,7 @@ function create_each_block_1$5(ctx) { let dispose; function change_handler(...args) { - return /*change_handler*/ ctx[10](/*i*/ ctx[14], /*dir*/ ctx[15], ...args); + return /*change_handler*/ ctx[11](/*i*/ ctx[15], /*dir*/ ctx[16], ...args); } return { @@ -34536,11 +34557,11 @@ function create_each_block_1$5(ctx) { t1 = space(); input = element("input"); attr(label, "class", "BC-Arrow-Label svelte-1e9on6f"); - attr(label, "for", label_for_value = /*dir*/ ctx[15]); + attr(label, "for", label_for_value = /*dir*/ ctx[16]); attr(input, "type", "text"); attr(input, "size", "20"); - attr(input, "name", input_name_value = /*dir*/ ctx[15]); - input.value = input_value_value = /*hier*/ ctx[12][/*dir*/ ctx[15]]?.join(", ") ?? ""; + attr(input, "name", input_name_value = /*dir*/ ctx[16]); + input.value = input_value_value = /*hier*/ ctx[13][/*dir*/ ctx[16]]?.join(", ") ?? ""; }, m(target, anchor) { insert(target, div, anchor); @@ -34557,7 +34578,7 @@ function create_each_block_1$5(ctx) { p(new_ctx, dirty) { ctx = new_ctx; - if (dirty & /*currHiers*/ 1 && input_value_value !== (input_value_value = /*hier*/ ctx[12][/*dir*/ ctx[15]]?.join(", ") ?? "") && input.value !== input_value_value) { + if (dirty & /*currHiers*/ 2 && input_value_value !== (input_value_value = /*hier*/ ctx[13][/*dir*/ ctx[16]]?.join(", ") ?? "") && input.value !== input_value_value) { input.value = input_value_value; } }, @@ -34569,7 +34590,7 @@ function create_each_block_1$5(ctx) { }; } -// (62:2) {#each currHiers as hier, i} +// (63:2) {#each currHiers as hier, i} function create_each_block$6(ctx) { let details; let summary; @@ -34588,19 +34609,19 @@ function create_each_block$6(ctx) { let dispose; function func(...args) { - return /*func*/ ctx[6](/*hier*/ ctx[12], ...args); + return /*func*/ ctx[7](/*hier*/ ctx[13], ...args); } function click_handler_3() { - return /*click_handler_3*/ ctx[7](/*i*/ ctx[14]); + return /*click_handler_3*/ ctx[8](/*i*/ ctx[15]); } function click_handler_4() { - return /*click_handler_4*/ ctx[8](/*i*/ ctx[14]); + return /*click_handler_4*/ ctx[9](/*i*/ ctx[15]); } function click_handler_5() { - return /*click_handler_5*/ ctx[9](/*i*/ ctx[14]); + return /*click_handler_5*/ ctx[10](/*i*/ ctx[15]); } let each_value_1 = DIRECTIONS$1; @@ -34673,9 +34694,9 @@ function create_each_block$6(ctx) { }, p(new_ctx, dirty) { ctx = new_ctx; - if (dirty & /*currHiers*/ 1 && t0_value !== (t0_value = DIRECTIONS$1.map(func).map(func_1).join(" ") + "")) set_data(t0, t0_value); + if (dirty & /*currHiers*/ 2 && t0_value !== (t0_value = DIRECTIONS$1.map(func).map(func_1).join(" ") + "")) set_data(t0, t0_value); - if (dirty & /*DIRECTIONS, currHiers, splitAndTrim, update, ARROW_DIRECTIONS*/ 3) { + if (dirty & /*DIRECTIONS, currHiers, splitAndTrim, update, settings, plugin, ARROW_DIRECTIONS*/ 15) { each_value_1 = DIRECTIONS$1; let i; @@ -34728,7 +34749,7 @@ function create_fragment$b(ctx) { faplus = new FaPlus({}); faregtrashalt = new FaRegTrashAlt({}); falistul = new FaListUl({}); - let each_value = /*currHiers*/ ctx[0]; + let each_value = /*currHiers*/ ctx[1]; let each_blocks = []; for (let i = 0; i < each_value.length; i += 1) { @@ -34788,17 +34809,17 @@ function create_fragment$b(ctx) { if (!mounted) { dispose = [ - listen(button0, "click", /*click_handler*/ ctx[3]), - listen(button1, "click", /*click_handler_1*/ ctx[4]), - listen(button2, "click", /*click_handler_2*/ ctx[5]) + listen(button0, "click", /*click_handler*/ ctx[4]), + listen(button1, "click", /*click_handler_1*/ ctx[5]), + listen(button2, "click", /*click_handler_2*/ ctx[6]) ]; mounted = true; } }, p(ctx, [dirty]) { - if (dirty & /*DIRECTIONS, currHiers, splitAndTrim, update, ARROW_DIRECTIONS, swapItems*/ 3) { - each_value = /*currHiers*/ ctx[0]; + if (dirty & /*DIRECTIONS, currHiers, splitAndTrim, update, settings, plugin, ARROW_DIRECTIONS, swapItems*/ 15) { + each_value = /*currHiers*/ ctx[1]; let i; for (i = 0; i < each_value.length; i += 1) { @@ -34887,20 +34908,21 @@ function instance$b($$self, $$props, $$invalidate) { let { plugin } = $$props; + const { settings } = plugin; let currHiers = [...plugin.settings.userHiers]; function update(currHiers) { return __awaiter(this, void 0, void 0, function* () { - $$invalidate(2, plugin.settings.userHiers = currHiers, plugin); + $$invalidate(0, plugin.settings.userHiers = currHiers, plugin); yield plugin.saveSettings(); }); } - const click_handler = async () => $$invalidate(0, currHiers = [...currHiers, blankUserHier()]); + const click_handler = async () => $$invalidate(1, currHiers = [...currHiers, blankUserHier()]); const click_handler_1 = async () => { if (window.confirm("Are you sure you want to reset all hierarchies?")) { - $$invalidate(0, currHiers = []); + $$invalidate(1, currHiers = []); await update(currHiers); } }; @@ -34909,35 +34931,60 @@ function instance$b($$self, $$props, $$invalidate) { const func = (hier, dir) => hier[dir]?.join(", ") ?? ""; const click_handler_3 = async i => { - $$invalidate(0, currHiers = swapItems(i, i - 1, currHiers)); + $$invalidate(1, currHiers = swapItems(i, i - 1, currHiers)); await update(currHiers); }; const click_handler_4 = async i => { - $$invalidate(0, currHiers = swapItems(i, i + 1, currHiers)); + $$invalidate(1, currHiers = swapItems(i, i + 1, currHiers)); await update(currHiers); }; const click_handler_5 = async i => { - currHiers.splice(i, 1); - $$invalidate(0, currHiers); + const oldHier = currHiers.splice(i, 1)[0]; + + oldHier.up.forEach(upField => { + const index = settings.limitTrailCheckboxes.indexOf(upField); + if (index > -1) settings.limitTrailCheckboxes.splice(index, 1); + }); + + DIRECTIONS$1.forEach(dir => { + oldHier[dir].forEach(field => { + const indexI = settings.limitJumpToFirstFields.indexOf(field); + if (indexI > -1) settings.limitJumpToFirstFields.splice(indexI, 1); + const indexJ = settings.limitWriteBCCheckboxes.indexOf(field); + if (indexJ > -1) settings.limitJumpToFirstFields.splice(indexJ, 1); + }); + }); + + $$invalidate(1, currHiers); await update(currHiers); }; const change_handler = async (i, dir, e) => { const { value } = e.target; - $$invalidate(0, currHiers[i][dir] = splitAndTrim(value), currHiers); + const splits = splitAndTrim(value); + $$invalidate(1, currHiers[i][dir] = splits, currHiers); await update(currHiers); + + splits.forEach(split => { + if (dir === "up" && !settings.limitTrailCheckboxes.includes(split)) settings.limitTrailCheckboxes.push(split); + if (!settings.limitJumpToFirstFields.includes(split)) settings.limitJumpToFirstFields.push(split); + if (!settings.limitWriteBCCheckboxes.includes(split)) settings.limitWriteBCCheckboxes.push(split); + }); + + await plugin.saveSettings(); }; $$self.$$set = $$props => { - if ("plugin" in $$props) $$invalidate(2, plugin = $$props.plugin); + if ("plugin" in $$props) $$invalidate(0, plugin = $$props.plugin); }; return [ + plugin, currHiers, + settings, update, - plugin, click_handler, click_handler_1, click_handler_2, @@ -34953,7 +35000,7 @@ class UserHierarchies extends SvelteComponent { constructor(options) { super(); if (!document.getElementById("svelte-1e9on6f-style")) add_css$6(); - init(this, options, instance$b, create_fragment$b, safe_not_equal, { plugin: 2 }); + init(this, options, instance$b, create_fragment$b, safe_not_equal, { plugin: 0 }); } } @@ -34963,7 +35010,7 @@ function addHierarchySettings(plugin, containerEl) { text: "Here you can set up different hierarchies you use in your vault. To add a new hierarchy, click the plus button. Then, fill in the field names of your hierachy into the 3 boxes that appear. The ↑ field is for parent relations, the → field is for siblings, and ↓ is for child relations.", }); fieldDetails.createEl("p", { - text: "For each direction (up, same, down), you can enter multiple field names in a comma seperated list. For example: `parent, broader, upper`", + text: "For each direction (up, same, down, next, previous), you can enter multiple field names in a comma seperated list. For example: `parent, broader, upper`", }); new UserHierarchies({ target: fieldDetails, @@ -34971,6 +35018,19 @@ function addHierarchySettings(plugin, containerEl) { }); } +function addJumpToNextSettings(plugin, viewDetails) { + const { settings } = plugin; + const jumpToDirDetails = subDetails("Jump to Next Direction", viewDetails); + new Checkboxes({ + target: jumpToDirDetails, + props: { + plugin, + settingName: "limitJumpToFirstFields", + options: getFields(settings.userHiers), + }, + }); +} + /* src\Components\Lists.svelte generated by Svelte v3.35.0 */ function add_css$5() { @@ -37451,8 +37511,7 @@ function addTrailViewSettings(plugin, viewDetails) { })); new obsidian.Setting(trailDetails) .setName("Juggl view layout") - .setDesc("The layout type to use for the Juggl view. " + - "The hierarchy layout is most natural for Breadcrumbs, but for large graphs D3 Force is recommended.") + .setDesc(fragWithHTML("The layout type to use for the Juggl view.
The hierarchy layout is most natural for Breadcrumbs, but for large graphs D3 Force is recommended.")) .addDropdown((dc) => { dc.addOption("hierarchy", "Hierarchy"); dc.addOption("d3-force", "D3 Force"); @@ -37631,6 +37690,7 @@ class BCSettingTab extends obsidian.PluginSettingTab { addWriteBCsSettings(plugin, cmdsDetails); addCreateIndexSettings(plugin, cmdsDetails); addThreadingSettings(plugin, cmdsDetails); + addJumpToNextSettings(plugin, cmdsDetails); addDebuggingsSettings(plugin, containerEl); new KoFi({ target: containerEl }); } @@ -61892,6 +61952,8 @@ class BCPlugin extends obsidian.Plugin { this.visited = []; this.activeLeafChange = undefined; this.layoutChange = undefined; + this.loadSettings = async () => (this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData())); + this.saveSettings = async () => await this.saveData(this.settings); } registerActiveLeafChangeEvent() { this.activeLeafChange = this.app.workspace.on("active-leaf-change", async () => { @@ -62026,30 +62088,35 @@ class BCPlugin extends obsidian.Plugin { this.addCommand({ id: "Write-Breadcrumbs-to-All-Files", name: "Write Breadcrumbs to **ALL** Files", - callback: async () => writeBCsToAllFiles(this), + callback: async () => await writeBCsToAllFiles(this), }); this.addCommand({ id: "local-index", name: "Copy a Local Index to the clipboard", - callback: async () => copyLocalIndex(this), + callback: async () => await copyLocalIndex(this), }); this.addCommand({ id: "global-index", name: "Copy a Global Index to the clipboard", - callback: async () => copyGlobalIndex(this), + callback: async () => await copyGlobalIndex(this), + }); + this.addCommand({ + id: "in-yaml", + name: "TEST: Inside YAML", + callback: async () => console.log(isInsideYaml(this.app)), }); ["up", "down", "next", "prev"].forEach((dir) => { this.addCommand({ id: `jump-to-first-${dir}`, name: `Jump to first '${dir}'`, - callback: async () => jumpToFirstDir(this, dir), + callback: async () => await jumpToFirstDir(this, dir), }); }); getFields(userHiers).forEach((field) => { this.addCommand({ id: `new-file-with-curr-as-${field}`, name: `Create a new '${field}' from the current note`, - callback: async () => thread(this, field), + callback: async () => await thread(this, field), }); }); this.addRibbonIcon(addFeatherIcon("tv"), "Breadcrumbs Visualisation", () => new VisModal(app, this).open()); @@ -62065,12 +62132,6 @@ class BCPlugin extends obsidian.Plugin { } return null; } - async loadSettings() { - this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); - } - async saveSettings() { - await this.saveData(this.settings); - } onunload() { console.log("unloading"); this.VIEWS.forEach(async (view) => { diff --git a/src/Utils/ObsidianUtils.ts b/src/Utils/ObsidianUtils.ts index 265a7ee1..f2fd47d1 100644 --- a/src/Utils/ObsidianUtils.ts +++ b/src/Utils/ObsidianUtils.ts @@ -147,3 +147,26 @@ export const linkClass = (app: App, to: string, realQ = true) => export const getDVApi = (plugin: BCPlugin) => plugin.app.plugins.plugins.dataview?.api; + +export function isInsideYaml(app: App): boolean | null { + const { workspace, metadataCache } = app; + const { activeLeaf } = workspace; + const { + state: { mode }, + } = activeLeaf.getViewState(); + + if (mode !== "source") return null; + + const { editor } = activeLeaf.view; + + const file = workspace.getActiveFile(); + if (!file) return null; + + const { frontmatter } = metadataCache.getFileCache(file); + if (!frontmatter) return false; + + const { start, end } = frontmatter.position; + const currOff = editor.posToOffset(editor.getCursor()); + if (currOff >= start.offset + 4 && currOff <= end.offset - 4) return true; + else return false; +} diff --git a/src/interfaces.ts b/src/interfaces.ts index 68b9aef5..40ee657b 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -287,6 +287,9 @@ declare module "obsidian" { }; commands: { executeCommandById: (id: string) => void }; } + interface View { + editor: Editor; + } } export interface ParsedCodeblock extends IJugglSettings {