From 05e27deb22e5675c9de9944ad08d7cd9efdf1372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Sch=C3=A4ferdiek?= Date: Fri, 19 Jan 2024 17:36:23 +0100 Subject: [PATCH] Manual backup: 2024-01-19 17:36:23 --- .obsidian/plugins/obsidian-git/main.js | 179 +++++++++++++++--- .obsidian/plugins/obsidian-git/manifest.json | 2 +- .obsidian/plugins/templater-obsidian/main.js | 69 ++++--- .../plugins/templater-obsidian/manifest.json | 4 +- .obsidian/workspace.json | 6 +- 5 files changed, 199 insertions(+), 61 deletions(-) diff --git a/.obsidian/plugins/obsidian-git/main.js b/.obsidian/plugins/obsidian-git/main.js index dc70752..0815026 100644 --- a/.obsidian/plugins/obsidian-git/main.js +++ b/.obsidian/plugins/obsidian-git/main.js @@ -29417,6 +29417,11 @@ function getDisplayPath(path2) { return path2; return path2.split("/").last().replace(".md", ""); } +function formatMinutes(minutes) { + if (minutes === 1) + return "1 minute"; + return `${minutes} minutes`; +} // src/gitManager/gitManager.ts init_polyfill_buffer(); @@ -29942,10 +29947,15 @@ var SimpleGit = class extends GitManager { }; } async getRemoteUrl(remote) { - return await this.git.remote( - ["get-url", remote], - (err, url) => this.onError(err) - ) || void 0; + try { + await this.git.remote(["get-url", remote]); + } catch (error) { + if (error.toString().contains(remote)) { + return void 0; + } else { + this.onError(error); + } + } } // https://github.com/kometenstaub/obsidian-version-history-diff/issues/3 async log(file, relativeToVault = true, limit) { @@ -31280,7 +31290,7 @@ var IsomorphicGit = class extends GitManager { await this.checkAuthorInfo(); this.plugin.setState(4 /* commit */); const formatMessage = await this.formatCommitMessage(message); - const hadConflict = this.plugin.localStorage.getConflict() === "true"; + const hadConflict = this.plugin.localStorage.getConflict(); let parent = void 0; if (hadConflict) { const branchInfo = await this.branchInfo(); @@ -31293,7 +31303,7 @@ var IsomorphicGit = class extends GitManager { parent }) ); - this.plugin.localStorage.setConflict("false"); + this.plugin.localStorage.setConflict(false); return; } catch (error) { this.plugin.displayError(error); @@ -32167,7 +32177,9 @@ var ObsidianGitSettingsTab = class extends import_obsidian8.PluginSettingTab { plugin.settings.autoSaveInterval ); new import_obsidian8.Notice( - `Automatic ${commitOrBackup} enabled! Every ${plugin.settings.autoSaveInterval} minutes.` + `Automatic ${commitOrBackup} enabled! Every ${formatMinutes( + plugin.settings.autoSaveInterval + )}.` ); } else if (plugin.settings.autoSaveInterval <= 0) { plugin.clearAutoBackup() && new import_obsidian8.Notice( @@ -32180,8 +32192,12 @@ var ObsidianGitSettingsTab = class extends import_obsidian8.PluginSettingTab { }) ); if (!plugin.settings.setLastSaveToLastCommit) - new import_obsidian8.Setting(containerEl).setName(`Auto Backup after stop editing any file`).setDesc( - `Requires the ${commitOrBackup} interval not to be 0. If turned on, do auto ${commitOrBackup} every ${plugin.settings.autoSaveInterval} minutes after stop editing any file. This also prevents auto ${commitOrBackup} while editing a file. If turned off, it's independent from the last change.` + new import_obsidian8.Setting(containerEl).setName(`Auto Backup after stopping file edits`).setDesc( + `Requires the ${commitOrBackup} interval not to be 0. + If turned on, do auto ${commitOrBackup} every ${formatMinutes( + plugin.settings.autoSaveInterval + )} after stopping file edits. + This also prevents auto ${commitOrBackup} while editing a file. If turned off, it's independent from the last change.` ).addToggle( (toggle) => toggle.setValue(plugin.settings.autoBackupAfterFileChange).onChange((value) => { plugin.settings.autoBackupAfterFileChange = value; @@ -32221,7 +32237,9 @@ var ObsidianGitSettingsTab = class extends import_obsidian8.PluginSettingTab { plugin.settings.autoPushInterval ); new import_obsidian8.Notice( - `Automatic push enabled! Every ${plugin.settings.autoPushInterval} minutes.` + `Automatic push enabled! Every ${formatMinutes( + plugin.settings.autoPushInterval + )}.` ); } else if (plugin.settings.autoPushInterval <= 0) { plugin.clearAutoPush() && new import_obsidian8.Notice( @@ -32249,7 +32267,9 @@ var ObsidianGitSettingsTab = class extends import_obsidian8.PluginSettingTab { plugin.settings.autoPullInterval ); new import_obsidian8.Notice( - `Automatic pull enabled! Every ${plugin.settings.autoPullInterval} minutes.` + `Automatic pull enabled! Every ${formatMinutes( + plugin.settings.autoPullInterval + )}.` ); } else if (plugin.settings.autoPullInterval <= 0) { plugin.clearAutoPull() && new import_obsidian8.Notice("Automatic pull disabled!"); @@ -32413,7 +32433,7 @@ var ObsidianGitSettingsTab = class extends import_obsidian8.PluginSettingTab { plugin.saveSettings(); }) ); - new import_obsidian8.Setting(containerEl).setName("Show changes files count in status bar").addToggle( + new import_obsidian8.Setting(containerEl).setName("Show the count of modified files in the status bar").addToggle( (toggle) => toggle.setValue(plugin.settings.changedFilesInStatusBar).onChange((value) => { plugin.settings.changedFilesInStatusBar = value; plugin.saveSettings(); @@ -33972,6 +33992,7 @@ var StatusBar = class { this.messages = []; this.base = "obsidian-git-statusbar-"; this.statusBarEl.setAttribute("aria-label-position", "top"); + this.statusBarEl.setAttribute("data-tooltip-position", "top"); addEventListener("git-refresh", this.refreshCommitTimestamp.bind(this)); } displayMessage(message, timeout) { @@ -34224,7 +34245,7 @@ async function getData(manager) { `remote.${remote}.url` ); const [isGitHub, httpsUser, httpsRepo, sshUser, sshRepo] = remoteUrl.match( - /(?:^https:\/\/github\.com\/(.*)\/(.*)\.git$)|(?:^git@github\.com:(.*)\/(.*)\.git$)/ + /(?:^https:\/\/github\.com\/(.*)\/(.*)\.git$)|(?:^[a-zA-Z]+@github\.com:(.*)\/(.*)\.git$)/ ); return { result: "success", @@ -34282,10 +34303,10 @@ var LocalStorageSettings = class { return app.saveLocalStorage(this.prefix + "hostname", value); } getConflict() { - return app.loadLocalStorage(this.prefix + "conflict"); + return app.loadLocalStorage(this.prefix + "conflict") == "true"; } setConflict(value) { - return app.saveLocalStorage(this.prefix + "conflict", value); + return app.saveLocalStorage(this.prefix + "conflict", `${value}`); } getLastAutoPull() { return app.loadLocalStorage(this.prefix + "lastAutoPull"); @@ -37069,6 +37090,12 @@ function create_fragment(ctx) { /*side*/ ctx[3] ); + attr( + div3, + "data-tooltip-position", + /*side*/ + ctx[3] + ); attr(div3, "aria-label", div3_aria_label_value = /*diff*/ ctx[0].vault_path); toggle_class( @@ -37164,6 +37191,15 @@ function create_fragment(ctx) { ctx2[3] ); } + if (dirty & /*side*/ + 8) { + attr( + div3, + "data-tooltip-position", + /*side*/ + ctx2[3] + ); + } if (dirty & /*diff*/ 1 && div3_aria_label_value !== (div3_aria_label_value = /*diff*/ ctx2[0].vault_path)) { @@ -37330,6 +37366,12 @@ function create_else_block(ctx) { /*side*/ ctx[5] ); + attr( + div3, + "data-tooltip-position", + /*side*/ + ctx[5] + ); attr(div3, "aria-label", div3_aria_label_value = /*entity*/ ctx[8].vaultPath); attr(div4, "class", "tree-item nav-folder"); @@ -37389,6 +37431,15 @@ function create_else_block(ctx) { ctx[5] ); } + if (!current || dirty & /*side*/ + 32) { + attr( + div3, + "data-tooltip-position", + /*side*/ + ctx[5] + ); + } if (!current || dirty & /*hierarchy*/ 1 && div3_aria_label_value !== (div3_aria_label_value = /*entity*/ ctx[8].vaultPath)) { @@ -38178,6 +38229,12 @@ function create_fragment3(ctx) { /*side*/ ctx[5] ); + attr( + div1, + "data-tooltip-position", + /*side*/ + ctx[5] + ); attr(div3, "class", "tree-item-self is-clickable nav-folder-title"); attr(div4, "class", "tree-item nav-folder"); toggle_class( @@ -38256,6 +38313,15 @@ function create_fragment3(ctx) { ctx2[5] ); } + if (!current || dirty & /*side*/ + 32) { + attr( + div1, + "data-tooltip-position", + /*side*/ + ctx2[5] + ); + } if (!/*isCollapsed*/ ctx2[4]) { if (if_block1) { @@ -39038,6 +39104,12 @@ function create_fragment5(ctx) { /*side*/ ctx[3] ); + attr( + div6, + "data-tooltip-position", + /*side*/ + ctx[3] + ); attr(div6, "aria-label", div6_aria_label_value = /*change*/ ctx[0].vault_path); toggle_class( @@ -39154,6 +39226,15 @@ function create_fragment5(ctx) { ctx2[3] ); } + if (dirty & /*side*/ + 8) { + attr( + div6, + "data-tooltip-position", + /*side*/ + ctx2[3] + ); + } if (dirty & /*change*/ 1 && div6_aria_label_value !== (div6_aria_label_value = /*change*/ ctx2[0].vault_path)) { @@ -39349,6 +39430,12 @@ function create_fragment6(ctx) { /*side*/ ctx[1] ); + attr( + div2, + "data-tooltip-position", + /*side*/ + ctx[1] + ); attr(div2, "aria-label", div2_aria_label_value = /*change*/ ctx[0].vault_path); attr(main, "class", "tree-item nav-file svelte-1wbh8tp"); @@ -39418,6 +39505,15 @@ function create_fragment6(ctx) { ctx2[1] ); } + if (dirty & /*side*/ + 2) { + attr( + div2, + "data-tooltip-position", + /*side*/ + ctx2[1] + ); + } if (dirty & /*change*/ 1 && div2_aria_label_value !== (div2_aria_label_value = /*change*/ ctx2[0].vault_path)) { @@ -39585,6 +39681,12 @@ function create_fragment7(ctx) { /*side*/ ctx[3] ); + attr( + div5, + "data-tooltip-position", + /*side*/ + ctx[3] + ); attr(div5, "aria-label", div5_aria_label_value = /*change*/ ctx[0].vault_path); toggle_class( @@ -39694,6 +39796,15 @@ function create_fragment7(ctx) { ctx2[3] ); } + if (dirty & /*side*/ + 8) { + attr( + div5, + "data-tooltip-position", + /*side*/ + ctx2[3] + ); + } if (dirty & /*change*/ 1 && div5_aria_label_value !== (div5_aria_label_value = /*change*/ ctx2[0].vault_path)) { @@ -39727,7 +39838,6 @@ function create_fragment7(ctx) { }; } function instance7($$self, $$props, $$invalidate) { - let formattedPath; let side; let { change } = $$props; let { view } = $$props; @@ -39783,11 +39893,6 @@ function instance7($$self, $$props, $$invalidate) { $$invalidate(8, manager = $$props2.manager); }; $$self.$$.update = () => { - if ($$self.$$.dirty & /*change*/ - 1) { - $: - formattedPath = change.vault_path; - } if ($$self.$$.dirty & /*view*/ 2) { $: @@ -39920,6 +40025,12 @@ function create_else_block3(ctx) { /*side*/ ctx[6] ); + attr( + div6, + "data-tooltip-position", + /*side*/ + ctx[6] + ); attr(div6, "aria-label", div6_aria_label_value = /*entity*/ ctx[15].vaultPath); attr(div7, "class", "tree-item nav-folder"); @@ -39995,6 +40106,15 @@ function create_else_block3(ctx) { ctx[6] ); } + if (!current || dirty & /*side*/ + 64) { + attr( + div6, + "data-tooltip-position", + /*side*/ + ctx[6] + ); + } if (!current || dirty & /*hierarchy*/ 1 && div6_aria_label_value !== (div6_aria_label_value = /*entity*/ ctx[15].vaultPath)) { @@ -43597,7 +43717,7 @@ var ObsidianGit = class extends import_obsidian30.Plugin { }) { if (!await this.isAllInitialized()) return false; - let hadConflict = this.localStorage.getConflict() === "true"; + let hadConflict = this.localStorage.getConflict(); let changedFiles; let status2; let unstagedFiles; @@ -43605,7 +43725,7 @@ var ObsidianGit = class extends import_obsidian30.Plugin { this.mayDeleteConflictFile(); status2 = await this.updateCachedStatus(); if (status2.conflicted.length == 0) { - this.localStorage.setConflict("false"); + this.localStorage.setConflict(false); hadConflict = false; } if (fromAutoBackup && status2.conflicted.length > 0) { @@ -43671,7 +43791,7 @@ var ObsidianGit = class extends import_obsidian30.Plugin { } if (this.gitManager instanceof SimpleGit) { if ((await this.updateCachedStatus()).conflicted.length == 0) { - this.localStorage.setConflict("false"); + this.localStorage.setConflict(false); } } let roughly = false; @@ -43723,7 +43843,7 @@ var ObsidianGit = class extends import_obsidian30.Plugin { if (!await this.remotesAreSet()) { return false; } - const hadConflict = this.localStorage.getConflict() === "true"; + const hadConflict = this.localStorage.getConflict(); if (this.gitManager instanceof SimpleGit) await this.mayDeleteConflictFile(); let status2; @@ -43786,7 +43906,8 @@ var ObsidianGit = class extends import_obsidian30.Plugin { ); if (file) { this.app.workspace.iterateAllLeaves((leaf) => { - if (leaf.view instanceof import_obsidian30.MarkdownView && leaf.view.file.path == file.path) { + var _a2; + if (leaf.view instanceof import_obsidian30.MarkdownView && ((_a2 = leaf.view.file) == null ? void 0 : _a2.path) == file.path) { leaf.detach(); } }); @@ -43909,7 +44030,7 @@ var ObsidianGit = class extends import_obsidian30.Plugin { } } if (!this.timeoutIDBackup && !this.onFileModifyEventRef) { - const lastAutos = await this.loadLastAuto(); + const lastAutos = this.loadLastAuto(); if (this.settings.autoSaveInterval > 0) { const now2 = /* @__PURE__ */ new Date(); const diff2 = this.settings.autoSaveInterval - Math.round( @@ -43921,7 +44042,7 @@ var ObsidianGit = class extends import_obsidian30.Plugin { } async setUpAutos() { this.setUpAutoBackup(); - const lastAutos = await this.loadLastAuto(); + const lastAutos = this.loadLastAuto(); if (this.settings.differentIntervalCommitAndPush && this.settings.autoPushInterval > 0) { const now2 = /* @__PURE__ */ new Date(); const diff2 = this.settings.autoPushInterval - Math.round( @@ -44044,7 +44165,7 @@ var ObsidianGit = class extends import_obsidian30.Plugin { } async handleConflict(conflicted) { this.setState(6 /* conflicted */); - this.localStorage.setConflict("true"); + this.localStorage.setConflict(true); let lines; if (conflicted !== void 0) { lines = [ diff --git a/.obsidian/plugins/obsidian-git/manifest.json b/.obsidian/plugins/obsidian-git/manifest.json index a771a54..31fee23 100644 --- a/.obsidian/plugins/obsidian-git/manifest.json +++ b/.obsidian/plugins/obsidian-git/manifest.json @@ -5,5 +5,5 @@ "isDesktopOnly": false, "fundingUrl": "https://ko-fi.com/vinzent", "js": "main.js", - "version": "2.22.0" + "version": "2.22.1" } diff --git a/.obsidian/plugins/templater-obsidian/main.js b/.obsidian/plugins/templater-obsidian/main.js index 443cc44..2a5d1ff 100644 --- a/.obsidian/plugins/templater-obsidian/main.js +++ b/.obsidian/plugins/templater-obsidian/main.js @@ -2437,8 +2437,8 @@ var InternalModuleFile = class extends InternalModule { }; } generate_exists() { - return async (filename) => { - const path = (0, import_obsidian8.normalizePath)(filename); + return async (filepath) => { + const path = (0, import_obsidian8.normalizePath)(filepath); return await app.vault.exists(path); }; } @@ -2731,6 +2731,8 @@ var PromptModal = class extends import_obsidian9.Modal { textInput.inputEl.addEventListener("keydown", (evt) => this.enterCallback(evt)); } enterCallback(evt) { + if (evt.isComposing || evt.keyCode === 229) + return; if (this.multi_line) { if (import_obsidian9.Platform.isDesktop) { if (evt.shiftKey && evt.key === "Enter") { @@ -3658,13 +3660,14 @@ var Templater = class { async write_template_to_file(template_file, file) { this.start_templater_task(); const active_editor = app.workspace.activeEditor; + const active_file = get_active_file(app); const running_config = this.create_running_config(template_file, file, 2); const output_content = await errorWrapper(async () => this.read_and_parse_template(running_config), "Template parsing error, aborting."); if (output_content == null) { return; } await app.vault.modify(file, output_content); - if (active_editor && active_editor.editor) { + if (active_file?.path !== file.path && active_editor && active_editor.editor) { const editor = active_editor.editor; editor.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 0 }); } @@ -3803,7 +3806,7 @@ var EventHandler = class { this.settings = settings; } setup() { - app.workspace.onLayoutReady(() => { + this.plugin.app.workspace.onLayoutReady(() => { this.update_trigger_file_on_creation(); }); this.update_syntax_highlighting(); @@ -3813,35 +3816,24 @@ var EventHandler = class { const desktopShouldHighlight = this.plugin.editor_handler.desktopShouldHighlight(); const mobileShouldHighlight = this.plugin.editor_handler.mobileShouldHighlight(); if (desktopShouldHighlight || mobileShouldHighlight) { - this.syntax_highlighting_event = app.workspace.on("codemirror", (cm) => { - cm.setOption("mode", "templater"); - }); - app.workspace.iterateCodeMirrors((cm) => { - cm.setOption("mode", "templater"); - }); - this.plugin.registerEvent(this.syntax_highlighting_event); + this.plugin.editor_handler.enable_highlighter(); } else { - if (this.syntax_highlighting_event) { - app.vault.offref(this.syntax_highlighting_event); - } - app.workspace.iterateCodeMirrors((cm) => { - cm.setOption("mode", "hypermd"); - }); + this.plugin.editor_handler.disable_highlighter(); } } update_trigger_file_on_creation() { if (this.settings.trigger_on_file_creation) { - this.trigger_on_file_creation_event = app.vault.on("create", (file) => Templater.on_file_creation(this.templater, file)); + this.trigger_on_file_creation_event = this.plugin.app.vault.on("create", (file) => Templater.on_file_creation(this.templater, file)); this.plugin.registerEvent(this.trigger_on_file_creation_event); } else { if (this.trigger_on_file_creation_event) { - app.vault.offref(this.trigger_on_file_creation_event); + this.plugin.app.vault.offref(this.trigger_on_file_creation_event); this.trigger_on_file_creation_event = void 0; } } } update_file_menu() { - this.plugin.registerEvent(app.workspace.on("file-menu", (menu, file) => { + this.plugin.registerEvent(this.plugin.app.workspace.on("file-menu", (menu, file) => { if (file instanceof import_obsidian13.TFolder) { menu.addItem((item) => { item.setTitle("Create new note from template").setIcon("templater-icon").onClick(() => { @@ -3862,6 +3854,7 @@ var CommandHandler = class { this.plugin.addCommand({ id: "insert-templater", name: "Open Insert Template modal", + icon: "templater-icon", hotkeys: [ { modifiers: ["Alt"], @@ -3875,6 +3868,7 @@ var CommandHandler = class { this.plugin.addCommand({ id: "replace-in-file-templater", name: "Replace templates in the active file", + icon: "templater-icon", hotkeys: [ { modifiers: ["Alt"], @@ -3888,6 +3882,7 @@ var CommandHandler = class { this.plugin.addCommand({ id: "jump-to-next-cursor-location", name: "Jump to next cursor location", + icon: "text-cursor", hotkeys: [ { modifiers: ["Alt"], @@ -3901,6 +3896,7 @@ var CommandHandler = class { this.plugin.addCommand({ id: "create-new-note-from-template", name: "Create new note from template", + icon: "templater-icon", hotkeys: [ { modifiers: ["Alt"], @@ -3926,6 +3922,7 @@ var CommandHandler = class { this.plugin.addCommand({ id: new_template, name: `Insert ${new_template}`, + icon: "templater-icon", callback: () => { const template = errorWrapperSync(() => resolve_tfile(new_template), `Couldn't find the template file associated with this hotkey`); if (!template) { @@ -4038,7 +4035,7 @@ var CursorJumper = class { var import_obsidian15 = __toModule(require("obsidian")); // toml:/home/runner/work/Templater/Templater/docs/documentation.toml -var tp = { config: { name: "config", description: "This module exposes Templater's running configuration.\n\nThis is mostly useful when writing scripts requiring some context information.\n", functions: { template_file: { name: "template_file", description: "The `TFile` object representing the template file.", definition: "tp.config.template_file" }, target_file: { name: "target_file", description: "The `TFile` object representing the target file where the template will be inserted.", definition: "tp.config.target_file" }, run_mode: { name: "run_mode", description: "The `RunMode`, representing the way Templater was launched (Create new from template, Append to active file, ...)", definition: "tp.config.run_mode" }, active_file: { name: "active_file", description: "The active file (if existing) when launching Templater.", definition: "tp.config.active_file?" } } }, date: { name: "date", description: "This module contains every internal function related to dates.", functions: { now: { name: "now", description: "Retrieves the date.", definition: 'tp.date.now(format: string = "YYYY-MM-DD", offset?: number\u23AEstring, reference?: string, reference_format?: string)', args: [{ name: "format", description: "Format for the date, refer to [format reference](https://momentjs.com/docs/#/displaying/format/)" }, { name: "offset", description: "Offset for the day, e.g. set this to `-7` to get last week's date. You can also specify the offset as a string using the ISO 8601 format" }, { name: "reference", description: "The date referential, e.g. set this to the note's title" }, { name: "reference_format", description: "The date reference format." }] }, tomorrow: { name: "tomorrow", description: "Retrieves tomorrow's date.", definition: 'tp.date.tomorrow(format: string = "YYYY-MM-DD")', args: [{ name: "format", description: "Format for the date, refer to [format reference](https://momentjs.com/docs/#/displaying/format/)" }] }, yesterday: { name: "yesterday", description: "Retrieves yesterday's date.", definition: 'tp.date.yesterday(format: string = "YYYY-MM-DD")', args: [{ name: "format", description: "Format for the date, refer to [format reference](https://momentjs.com/docs/#/displaying/format/)" }] }, weekday: { name: "weekday", description: "", definition: 'tp.date.weekday(format: string = "YYYY-MM-DD", weekday: number, reference?: string, reference_format?: string)', args: [{ name: "format", description: "Format for the date, refer to [format reference](https://momentjs.com/docs/#/displaying/format/)" }, { name: "weekday", description: "Week day number. If the locale assigns Monday as the first day of the week, `0` will be Monday, `-7` will be last week's day." }, { name: "reference", description: "The date referential, e.g. set this to the note's title" }, { name: "reference_format", description: "The date reference format." }] } } }, file: { name: "file", description: "This module contains every internal function related to files.", functions: { content: { name: "content", description: "Retrieves the file's content", definition: "tp.file.content" }, create_new: { name: "create_new", description: "Creates a new file using a specified template or with a specified content.", definition: "tp.file.create_new(template: TFile \u23AE string, filename?: string, open_new: boolean = false, folder?: TFolder)", args: [{ name: "template", description: "Either the template used for the new file content, or the file content as a string. If it is the template to use, you retrieve it with `tp.file.find_tfile(TEMPLATENAME)`" }, { name: "filename", description: 'The filename of the new file, defaults to "Untitled".' }, { name: "open_new", description: "Whether to open or not the newly created file. Warning: if you use this option, since commands are executed asynchronously, the file can be opened first and then other commands are appended to that new file and not the previous file." }, { name: "folder", description: 'The folder to put the new file in, defaults to obsidian\'s default location. If you want the file to appear in a different folder, specify it with `app.vault.getAbstractFileByPath("FOLDERNAME")`' }] }, creation_date: { name: "creation_date", description: "Retrieves the file's creation date.", definition: 'tp.file.creation_date(format: string = "YYYY-MM-DD HH:mm")', args: [{ name: "format", description: "Format for the date, refer to format reference" }] }, cursor: { name: "cursor", description: "Sets the cursor to this location after the template has been inserted. \n\nYou can navigate between the different tp.file.cursor using the configured hotkey in obsidian settings.\n", definition: "tp.file.cursor(order?: number)", args: [{ name: "order", description: "The order of the different cursors jump, e.g. it will jump from 1 to 2 to 3, and so on.\nIf you specify multiple tp.file.cursor with the same order, the editor will switch to multi-cursor.\n" }] }, cursor_append: { name: "cursor_append", description: "Appends some content after the active cursor in the file.", definition: "tp.file.cursor_append(content: string)", args: [{ name: "content", description: "The content to append after the active cursor" }] }, exists: { name: "exists", description: "The filename of the file we want to check existence. The fullpath to the file, relative to the Vault and containing the extension, must be provided. e.g. MyFolder/SubFolder/MyFile.", definition: "tp.file.exists(filename: string)", args: [{ name: "filename", description: "The filename of the file we want to check existence, e.g. MyFile." }] }, find_tfile: { name: "find_tfile", description: "Search for a file and returns its `TFile` instance", definition: "tp.file.find_tfile(filename: string)", args: [{ name: "filename", description: "The filename we want to search and resolve as a `TFile`" }] }, folder: { name: "folder", description: "Retrieves the file's folder name.", definition: "tp.file.folder(relative: boolean = false)", args: [{ name: "relative", description: "If set to true, appends the vault relative path to the folder name." }] }, include: { name: "include", description: "Includes the file's link content. Templates in the included content will be resolved.", definition: "tp.file.include(include_link: string \u23AE TFile)", args: [{ name: "include_link", description: "The link to the file to include, e.g. [[MyFile]], or a TFile object. Also supports sections or blocks inclusions, e.g. [[MyFile#Section1]]" }] }, last_modified_date: { name: "last_modified_date", description: "Retrieves the file's last modification date.", definition: 'tp.file.last_modified_date(format: string = "YYYY-MM-DD HH:mm")', args: [{ name: "format", description: "Format for the date, refer to format reference." }] }, move: { name: "functions.move", description: "Moves the file to the desired vault location.", definition: "tp.file.move(new_path: string, file_to_move?: TFile)", example: '<% tp.file.move("/Notes/MyNote") %>', args: [{ name: "new_path", description: 'The new vault relative path of the file, without the file extension. Note: the new path needs to include the folder and the filename, e.g. `"/Notes/MyNote"`' }, { name: "file_to_move", description: "The file to move, defaults to the current file." }] }, path: { name: "path", description: "Retrieves the file's absolute path on the system.", definition: "tp.file.path(relative: boolean = false)", args: [{ name: "relative", description: "If set to true, only retrieves the vault's relative path." }] }, rename: { name: "rename", description: "Renames the file (keeps the same file extension).", definition: "tp.file.rename(new_title: string)", args: [{ name: "new_title", description: "The new file title." }] }, selection: { name: "selection", description: "Retrieves the active file's text selection.", definition: "tp.file.selection()" }, tags: { name: "tags", description: "Retrieves the file's tags (array of string)", definition: "tp.file.tags" }, title: { name: "title", definition: "tp.file.title", description: "Retrieves the file's title." } } }, frontmatter: { name: "frontmatter", description: "This modules exposes all the frontmatter variables of a file as variables." }, hooks: { name: "hooks", description: "This module exposes hooks that allow you to execute code when a Templater event occurs.", functions: { on_all_templates_executed: { name: "on_all_templates_executed", description: "Hooks into when all actively running templates have finished executing. Most of the time this will be a single template, unless you are using `tp.file.include` or `tp.file.create_new`.\n\nMultiple invokations of this method will have their callback functions run in parallel.", definition: "tp.hooks.on_all_templates_executed(callback_function: () => any)", args: [{ name: "callback_function", description: "Callback function that will be executed when all actively running templates have finished executing." }] } } }, obsidian: { name: "obsidian", description: "This module exposes all the functions and classes from the obsidian API." }, system: { name: "system", description: "This module contains system related functions.", functions: { clipboard: { name: "clipboard", description: "Retrieves the clipboard's content", definition: "tp.system.clipboard()" }, prompt: { name: "prompt", description: "Spawns a prompt modal and returns the user's input.", definition: "tp.system.prompt(prompt_text?: string, default_value?: string, throw_on_cancel: boolean = false, multiline?: boolean = false)", args: [{ name: "prompt_text", description: "Text placed above the input field" }, { name: "default_value", description: "A default value for the input field" }, { name: "throw_on_cancel", description: "Throws an error if the prompt is canceled, instead of returning a `null` value" }, { name: "multiline", description: "If set to true, the input field will be a multiline textarea" }] }, suggester: { name: "suggester", description: "Spawns a suggester prompt and returns the user's chosen item.", definition: 'tp.system.suggester(text_items: string[] \u23AE ((item: T) => string), items: T[], throw_on_cancel: boolean = false, placeholder: string = "", limit?: number = undefined)', args: [{ name: "text_items", description: "Array of strings representing the text that will be displayed for each item in the suggester prompt. This can also be a function that maps an item to its text representation." }, { name: "items", description: "Array containing the values of each item in the correct order." }, { name: "throw_on_cancel", description: "Throws an error if the prompt is canceled, instead of returning a `null` value" }, { name: "placeholder", description: "Placeholder string of the prompt" }, { name: "limit", description: "Limit the number of items rendered at once (useful to improve performance when displaying large lists)" }] } } }, web: { name: "web", description: "This modules contains every internal function related to the web (making web requests).", functions: { daily_quote: { name: "daily_quote", description: "Retrieves and parses the daily quote from the API https://api.quotable.io", definition: "tp.web.daily_quote()" }, random_picture: { name: "random_picture", description: "Gets a random image from https://unsplash.com/", definition: "tp.web.random_picture(size?: string, query?: string, include_size?: boolean)", args: [{ name: "size", description: "Image size in the format `x`" }, { name: "query", description: "Limits selection to photos matching a search term. Multiple search terms can be passed separated by a comma `,`" }, { name: "include_size", description: "Optional argument to include the specified size in the image link markdown. Defaults to false" }] } } } }; +var tp = { config: { name: "config", description: "This module exposes Templater's running configuration.\n\nThis is mostly useful when writing scripts requiring some context information.\n", functions: { template_file: { name: "template_file", description: "The `TFile` object representing the template file.", definition: "tp.config.template_file" }, target_file: { name: "target_file", description: "The `TFile` object representing the target file where the template will be inserted.", definition: "tp.config.target_file" }, run_mode: { name: "run_mode", description: "The `RunMode`, representing the way Templater was launched (Create new from template, Append to active file, ...).", definition: "tp.config.run_mode" }, active_file: { name: "active_file", description: "The active file (if existing) when launching Templater.", definition: "tp.config.active_file?" } } }, date: { name: "date", description: "This module contains every internal function related to dates.", functions: { now: { name: "now", description: "Retrieves the date.", definition: 'tp.date.now(format: string = "YYYY-MM-DD", offset?: number\u23AEstring, reference?: string, reference_format?: string)', args: [{ name: "format", description: 'The format for the date. Defaults to `"YYYY-MM-DD"`. Refer to [format reference](https://momentjs.com/docs/#/displaying/format/).' }, { name: "offset", description: "Duration to offset the date from. If a number is provided, duration will be added to the date in days. You can also specify the offset as a string using the ISO 8601 format." }, { name: "reference", description: "The date referential, e.g. set this to the note's title." }, { name: "reference_format", description: "The format for the reference date. Refer to [format reference](https://momentjs.com/docs/#/displaying/format/)." }], examples: [{ name: "Date now", example: "<% tp.date.now() %>" }, { name: "Date now with format", example: '<% tp.date.now("Do MMMM YYYY") %>' }, { name: "Last week", example: '<% tp.date.now("YYYY-MM-DD", -7) %>' }, { name: "Next week", example: '<% tp.date.now("YYYY-MM-DD", 7) %>' }, { name: "Last month", example: '<% tp.date.now("YYYY-MM-DD", "P-1M") %>' }, { name: "Next year", example: '<% tp.date.now("YYYY-MM-DD", "P1Y") %>' }, { name: "File's title date + 1 day (tomorrow)", example: '<% tp.date.now("YYYY-MM-DD", 1, tp.file.title, "YYYY-MM-DD") %>' }, { name: "File's title date - 1 day (yesterday)", example: '<% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %>' }] }, tomorrow: { name: "tomorrow", description: "Retrieves tomorrow's date.", definition: 'tp.date.tomorrow(format: string = "YYYY-MM-DD")', args: [{ name: "format", description: 'The format for the date. Defaults to `"YYYY-MM-DD"`. Refer to [format reference](https://momentjs.com/docs/#/displaying/format/).' }], examples: [{ name: "Date tomorrow", example: "<% tp.date.tomorrow() %>" }, { name: "Date tomorrow with format", example: '<% tp.date.tomorrow("Do MMMM YYYY") %>' }] }, yesterday: { name: "yesterday", description: "Retrieves yesterday's date.", definition: 'tp.date.yesterday(format: string = "YYYY-MM-DD")', args: [{ name: "format", description: 'The format for the date. Defaults to `"YYYY-MM-DD"`. Refer to [format reference](https://momentjs.com/docs/#/displaying/format/).' }], examples: [{ name: "Date yesterday", example: "<% tp.date.yesterday() %>" }, { name: "Date yesterday with format", example: '<% tp.date.yesterday("Do MMMM YYYY") %>' }] }, weekday: { name: "weekday", description: "", definition: 'tp.date.weekday(format: string = "YYYY-MM-DD", weekday: number, reference?: string, reference_format?: string)', args: [{ name: "format", description: 'The format for the date. Defaults to `"YYYY-MM-DD"`. Refer to [format reference](https://momentjs.com/docs/#/displaying/format/).' }, { name: "weekday", description: "Week day number. If the locale assigns Monday as the first day of the week, `0` will be Monday, `-7` will be last week's day." }, { name: "reference", description: "The date referential, e.g. set this to the note's title." }, { name: "reference_format", description: "The format for the reference date. Refer to [format reference](https://momentjs.com/docs/#/displaying/format/)." }], examples: [{ name: "This week's Monday", example: '<% tp.date.weekday("YYYY-MM-DD", 0) %>' }, { name: "Next Monday", example: '<% tp.date.weekday("YYYY-MM-DD", 7) %>' }, { name: "File's title Monday", example: '<% tp.date.weekday("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD") %>' }, { name: "File's title previous Monday", example: '<% tp.date.weekday("YYYY-MM-DD", -7, tp.file.title, "YYYY-MM-DD") %>' }] } }, momentjs: { examples: [{ name: "Date now", example: '<% moment(tp.file.title, "YYYY-MM-DD").format("YYYY-MM-DD") %>' }, { name: "Get start of month from note title", example: '<% moment(tp.file.title, "YYYY-MM-DD").startOf("month").format("YYYY-MM-DD") %>' }, { name: "Get end of month from note title", example: '<% moment(tp.file.title, "YYYY-MM-DD").endOf("month").format("YYYY-MM-DD") %>' }] } }, file: { name: "file", description: "This module contains every internal function related to files.", functions: { content: { name: "content", description: "The string contents of the file at the time that Templater was executed. Manipulating this string will *not* update the current file.", definition: "tp.file.content", examples: [{ name: "Retrieve file content", example: "<% tp.file.content %>" }] }, create_new: { name: "create_new", description: "Creates a new file using a specified template or with a specified content.", definition: "tp.file.create_new(template: TFile \u23AE string, filename?: string, open_new: boolean = false, folder?: TFolder)", args: [{ name: "template", description: "Either the template used for the new file content, or the file content as a string. If it is the template to use, you retrieve it with `tp.file.find_tfile(TEMPLATENAME)`." }, { name: "filename", description: 'The filename of the new file, defaults to "Untitled".' }, { name: "open_new", description: "Whether to open or not the newly created file. Warning: if you use this option, since commands are executed asynchronously, the file can be opened first and then other commands are appended to that new file and not the previous file." }, { name: "folder", description: 'The folder to put the new file in, defaults to Obsidian\'s default location. If you want the file to appear in a different folder, specify it with `app.vault.getAbstractFileByPath("FOLDERNAME")`.' }], examples: [{ name: "File creation", example: '<%* await tp.file.create_new("MyFileContent", "MyFilename") %>' }, { name: "File creation with template", example: '<%* await tp.file.create_new(tp.file.find_tfile("MyTemplate"), "MyFilename") %>' }, { name: "File creation and open created note", example: '<%* await tp.file.create_new("MyFileContent", "MyFilename", true) %>' }, { name: "File creation in current folder", example: '<%* await tp.file.create_new("MyFileContent", "MyFilename", false, tp.file.folder()) %>' }, { name: "File creation in specified folder", example: '<%* await tp.file.create_new("MyFileContent", "MyFilename", false, app.vault.getAbstractFileByPath("MyFolder")) %>' }, { name: "File creation and append link to current note", example: '[[<% (await tp.file.create_new("MyFileContent", "MyFilename")).basename %>]]' }] }, creation_date: { name: "creation_date", description: "Retrieves the file's creation date.", definition: 'tp.file.creation_date(format: string = "YYYY-MM-DD HH:mm")', args: [{ name: "format", description: 'The format for the date. Defaults to `"YYYY-MM-DD HH:mm"`. Refer to [format reference](https://momentjs.com/docs/#/displaying/format/).' }], examples: [{ name: "File creation date", example: "<% tp.file.creation_date() %>" }, { name: "File creation date with format", example: '<% tp.file.creation_date("dddd Do MMMM YYYY HH:mm") %>' }] }, cursor: { name: "cursor", description: "Sets the cursor to this location after the template has been inserted. \n\nYou can navigate between the different cursors using the configured hotkey in Obsidian settings.\n", definition: "tp.file.cursor(order?: number)", args: [{ name: "order", description: "The order of the different cursors jump, e.g. it will jump from 1 to 2 to 3, and so on.\nIf you specify multiple tp.file.cursor with the same order, the editor will switch to multi-cursor.\n" }], examples: [{ name: "File cursor", example: "<% tp.file.cursor() %>" }, { name: "File multi-cursor", example: "<% tp.file.cursor(1) %>Content<% tp.file.cursor(1) %>" }] }, cursor_append: { name: "cursor_append", description: "Appends some content after the active cursor in the file.", definition: "tp.file.cursor_append(content: string)", args: [{ name: "content", description: "The content to append after the active cursor." }], examples: [{ name: "File cursor append", example: '<% tp.file.cursor_append("Some text") %>' }] }, exists: { name: "exists", description: "Check to see if a file exists by it's file path. The full path to the file, relative to the Vault and containing the extension, must be provided.", definition: "tp.file.exists(filepath: string)", args: [{ name: "filepath", description: "The full file path of the file we want to check existence for." }], examples: [{ name: "File existence", example: '<% await tp.file.exists("MyFolder/MyFile.md") %>' }, { name: "File existence of current file", example: '<% await tp.file.exists(tp.file.folder(true) + "/" + tp.file.title + ".md") %>' }] }, find_tfile: { name: "find_tfile", description: "Search for a file and returns its `TFile` instance.", definition: "tp.file.find_tfile(filename: string)", args: [{ name: "filename", description: "The filename we want to search and resolve as a `TFile`." }], examples: [{ name: "File find TFile", example: '<% tp.file.find_tfile("MyFile").basename %>' }] }, folder: { name: "folder", description: "Retrieves the file's folder name.", definition: "tp.file.folder(relative: boolean = false)", args: [{ name: "relative", description: "If set to `true`, appends the vault relative path to the folder name. If `false`, only retrieves name of folder. Defaults to `false`." }], examples: [{ name: "File folder (Folder)", example: "<% tp.file.folder() %>" }, { name: "File folder with relative path (Path/To/Folder)", example: "<% tp.file.folder(true) %>" }] }, include: { name: "include", description: "Includes the file's link content. Templates in the included content will be resolved.", definition: "tp.file.include(include_link: string \u23AE TFile)", args: [{ name: "include_link", description: 'The link to the file to include, e.g. `"[[MyFile]]"`, or a TFile object. Also supports sections or blocks inclusions.' }], examples: [{ name: "File include", example: '<% tp.file.include("[[Template1]]") %>' }, { name: "File include TFile", example: '<% tp.file.include(tp.file.find_tfile("MyFile")) %>' }, { name: "File include section", example: '<% tp.file.include("[[MyFile#Section1]]") %>' }, { name: "File include block", example: '<% tp.file.include("[[MyFile#^block1]]") %>' }] }, last_modified_date: { name: "last_modified_date", description: "Retrieves the file's last modification date.", definition: 'tp.file.last_modified_date(format: string = "YYYY-MM-DD HH:mm")', args: [{ name: "format", description: 'The format for the date. Defaults to `"YYYY-MM-DD HH:mm"`. Refer to [format reference](https://momentjs.com/docs/#/displaying/format/).' }], examples: [{ name: "File last modified date", example: "<% tp.file.last_modified_date() %>" }, { name: "File last modified date with format", example: '<% tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm") %>' }] }, move: { name: "move", description: "Moves the file to the desired vault location.", definition: "tp.file.move(new_path: string, file_to_move?: TFile)", args: [{ name: "new_path", description: 'The new vault relative path of the file, without the file extension. Note: the new path needs to include the folder and the filename, e.g. `"/Notes/MyNote"`.' }, { name: "file_to_move", description: "The file to move, defaults to the current file." }], examples: [{ name: "File move", example: '<% await tp.file.move("/A/B/" + tp.file.title) %>' }, { name: "File move and rename", example: '<% await tp.file.move("/A/B/NewTitle") %>' }] }, path: { name: "path", description: "Retrieves the file's absolute path on the system.", definition: "tp.file.path(relative: boolean = false)", args: [{ name: "relative", description: "If set to `true`, only retrieves the vault's relative path." }], examples: [{ name: "File path", example: "<% tp.file.path() %>" }, { name: "File relative path (relative to vault root)", example: "<% tp.file.path(true) %>" }] }, rename: { name: "rename", description: "Renames the file (keeps the same file extension).", definition: "tp.file.rename(new_title: string)", args: [{ name: "new_title", description: "The new file title." }], examples: [{ name: "File rename", example: '<% await tp.file.rename("MyNewName") %>' }, { name: "File append a 2 to the file name", example: '<% await tp.file.rename(tp.file.title + "2") %>' }] }, selection: { name: "selection", description: "Retrieves the active file's text selection.", definition: "tp.file.selection()", examples: [{ name: "File selection", example: "<% tp.file.selection() %>" }] }, tags: { name: "tags", description: "Retrieves the file's tags (array of string).", definition: "tp.file.tags", examples: [{ name: "File tags", example: "<% tp.file.tags %>" }] }, title: { name: "title", definition: "tp.file.title", description: "Retrieves the file's title.", examples: [{ name: "File title", example: "<% tp.file.title %>" }, { name: "Strip the Zettelkasten ID of title (if space separated)", example: '<% tp.file.title.split(" ")[1] %>' }] } } }, frontmatter: { name: "frontmatter", description: "This modules exposes all the frontmatter variables of a file as variables." }, hooks: { name: "hooks", description: "This module exposes hooks that allow you to execute code when a Templater event occurs.", functions: { on_all_templates_executed: { name: "on_all_templates_executed", description: "Hooks into when all actively running templates have finished executing. Most of the time this will be a single template, unless you are using `tp.file.include` or `tp.file.create_new`.\n\nMultiple invokations of this method will have their callback functions run in parallel.", definition: "tp.hooks.on_all_templates_executed(callback_function: () => any)", args: [{ name: "callback_function", description: "Callback function that will be executed when all actively running templates have finished executing." }] } } }, obsidian: { name: "obsidian", description: "This module exposes all the functions and classes from the Obsidian API." }, system: { name: "system", description: "This module contains system related functions.", functions: { clipboard: { name: "clipboard", description: "Retrieves the clipboard's content.", definition: "tp.system.clipboard()", examples: [{ name: "Clipboard", example: "<% tp.system.clipboard() %>" }] }, prompt: { name: "prompt", description: "Spawns a prompt modal and returns the user's input.", definition: "tp.system.prompt(prompt_text?: string, default_value?: string, throw_on_cancel: boolean = false, multiline?: boolean = false)", args: [{ name: "prompt_text", description: "Text placed above the input field." }, { name: "default_value", description: "A default value for the input field." }, { name: "throw_on_cancel", description: "Throws an error if the prompt is canceled, instead of returning a `null` value." }, { name: "multiline", description: "If set to `true`, the input field will be a multiline textarea. Defaults to `false`." }], examples: [{ name: "Prompt", example: '<% tp.system.prompt("Please enter a value") %>' }, { name: "Prompt with default value", example: '<% tp.system.prompt("What is your mood today?", "happy") %>' }, { name: "Multiline prompt", example: '<% tp.system.prompt("What is your mood today?", null, false, true) %>' }] }, suggester: { name: "suggester", description: "Spawns a suggester prompt and returns the user's chosen item.", definition: 'tp.system.suggester(text_items: string[] \u23AE ((item: T) => string), items: T[], throw_on_cancel: boolean = false, placeholder: string = "", limit?: number = undefined)', args: [{ name: "text_items", description: "Array of strings representing the text that will be displayed for each item in the suggester prompt. This can also be a function that maps an item to its text representation." }, { name: "items", description: "Array containing the values of each item in the correct order." }, { name: "throw_on_cancel", description: "Throws an error if the prompt is canceled, instead of returning a `null` value." }, { name: "placeholder", description: "Placeholder string of the prompt." }, { name: "limit", description: "Limit the number of items rendered at once (useful to improve performance when displaying large lists)." }], examples: [{ name: "Suggester", example: '<% tp.system.suggester(["Happy", "Sad", "Confused"], ["Happy", "Sad", "Confused"]) %>' }, { name: "Suggester with mapping function (same as above example)", example: '<% tp.system.suggester((item) => item, ["Happy", "Sad", "Confused"]) %>' }, { name: "Suggester for files", example: "[[<% (await tp.system.suggester((item) => item.basename, app.vault.getMarkdownFiles())).basename %>]]" }, { name: "Suggester for tags", example: '<% tp.system.suggester(item => item, Object.keys(app.metadataCache.getTags()).map(x => x.replace("#", ""))) %>' }] } } }, web: { name: "web", description: "This modules contains every internal function related to the web (making web requests).", functions: { daily_quote: { name: "daily_quote", description: "Retrieves and parses the daily quote from the API `https://api.quotable.io` as a callout.", definition: "tp.web.daily_quote()", examples: [{ name: "Daily quote", example: "<% tp.web.daily_quote() %>" }] }, random_picture: { name: "random_picture", description: "Gets a random image from `https://unsplash.com/`.", definition: "tp.web.random_picture(size?: string, query?: string, include_size?: boolean)", args: [{ name: "size", description: "Image size in the format `x`." }, { name: "query", description: "Limits selection to photos matching a search term. Multiple search terms can be passed separated by a comma." }, { name: "include_size", description: "Optional argument to include the specified size in the image link markdown. Defaults to false." }], examples: [{ name: "Random picture", example: "<% tp.web.random_picture() %>" }, { name: "Random picture with size", example: '<% tp.web.random_picture("200x200") %>' }, { name: "Random picture with size and query", example: '<% tp.web.random_picture("200x200", "landscape,water") %>' }] } } } }; var documentation_default = { tp }; // src/editor/TpDocumentation.ts @@ -5440,7 +5437,7 @@ var Autocomplete = class extends import_obsidian15.EditorSuggest { return { state: state.base, mode: base }; }, blankLine: function(state) { - var baseToken, overlayToken; + let baseToken, overlayToken; if (base.blankLine) baseToken = base.blankLine(state.base); if (overlay.blankLine) @@ -5453,6 +5450,8 @@ var Autocomplete = class extends import_obsidian15.EditorSuggest { // src/editor/Editor.ts var import_language = __toModule(require("@codemirror/language")); +var import_state = __toModule(require("@codemirror/state")); +var TEMPLATER_MODE_NAME = "templater"; var TP_CMD_TOKEN_CLASS = "templater-command"; var TP_INLINE_CLASS = "templater-inline"; var TP_OPENING_TAG_TOKEN_CLASS = "templater-opening-tag"; @@ -5463,6 +5462,7 @@ var Editor2 = class { constructor(plugin) { this.plugin = plugin; this.cursor_jumper = new CursorJumper(); + this.activeEditorExtensions = []; } desktopShouldHighlight() { return import_obsidian16.Platform.isDesktopApp && this.plugin.settings.syntax_highlighting; @@ -5471,17 +5471,34 @@ var Editor2 = class { return import_obsidian16.Platform.isMobileApp && this.plugin.settings.syntax_highlighting_mobile; } async setup() { - await this.registerCodeMirrorMode(); this.plugin.registerEditorSuggest(new Autocomplete(this.plugin.settings)); + await this.registerCodeMirrorMode(); + this.templaterLanguage = import_state.Prec.high(import_language.StreamLanguage.define(window.CodeMirror.getMode({}, TEMPLATER_MODE_NAME))); + if (this.templaterLanguage === void 0) { + log_error(new TemplaterError("Unable to enable syntax highlighting. Could not define language.")); + } + this.plugin.registerEditorExtension(this.activeEditorExtensions); if (this.desktopShouldHighlight() || this.mobileShouldHighlight()) { - this.plugin.registerEditorExtension(import_language.StreamLanguage.define(window.CodeMirror.getMode({}, { name: "templater" }))); + await this.enable_highlighter(); + } + } + async enable_highlighter() { + if (this.activeEditorExtensions.length === 0 && this.templaterLanguage) { + this.activeEditorExtensions.push(this.templaterLanguage); + this.plugin.app.workspace.updateOptions(); + } + } + async disable_highlighter() { + if (this.activeEditorExtensions.length > 0) { + this.activeEditorExtensions.pop(); + this.plugin.app.workspace.updateOptions(); } } async jump_to_next_cursor_location(file = null, auto_jump = false) { if (auto_jump && !this.plugin.settings.auto_jump_to_cursor) { return; } - if (file && get_active_file(app) !== file) { + if (file && get_active_file(this.plugin.app) !== file) { return; } await this.cursor_jumper.jump_to_next_cursor_location(); @@ -5500,7 +5517,7 @@ var Editor2 = class { log_error(new TemplaterError("Couldn't find customOverlayMode, can't enable syntax highlighting.")); return; } - window.CodeMirror.defineMode("templater", function(config) { + window.CodeMirror.defineMode(TEMPLATER_MODE_NAME, function(config) { const templaterOverlay = { startState: function() { const js_state = window.CodeMirror.startState(js_mode); diff --git a/.obsidian/plugins/templater-obsidian/manifest.json b/.obsidian/plugins/templater-obsidian/manifest.json index c9404c9..fd8f2b5 100644 --- a/.obsidian/plugins/templater-obsidian/manifest.json +++ b/.obsidian/plugins/templater-obsidian/manifest.json @@ -1,9 +1,9 @@ { "id": "templater-obsidian", "name": "Templater", - "version": "1.18.3", + "version": "2.1.1", "description": "Create and use templates", - "minAppVersion": "0.11.13", + "minAppVersion": "1.5.0", "author": "SilentVoid", "authorUrl": "https://github.com/SilentVoid13", "helpUrl": "https://silentvoid13.github.io/Templater/", diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index e5b235c..f4963d2 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -4,11 +4,11 @@ "type": "split", "children": [ { - "id": "d847a69113acf89d", + "id": "47897c4d1315cd5a", "type": "tabs", "children": [ { - "id": "5808c3dac7e7fb1f", + "id": "7af4969d59fe9883", "type": "leaf", "state": { "type": "empty", @@ -128,7 +128,7 @@ "templater-obsidian:Templater": false } }, - "active": "5808c3dac7e7fb1f", + "active": "7af4969d59fe9883", "lastOpenFiles": [ "KB/Linux/Desktop/ArchLinux/Theming Qt and Gtk.md", "KB/Linux/Desktop/ArchLinux/sway.md",