From dc3127a906f53a9db541e55ea78b462737c330ca Mon Sep 17 00:00:00 2001 From: Diomede Date: Mon, 24 May 2021 20:52:57 +0200 Subject: [PATCH] fix: remove CodeMirror event on unload remove the CodeMirror event when unloading the plugin Filter the file returned by the auto-suggest by extension --- main.ts | 4 ++++ manifest.json | 2 +- package.json | 2 +- utils.ts | 3 +++ versions.json | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/main.ts b/main.ts index eb51701..2dbfada 100644 --- a/main.ts +++ b/main.ts @@ -18,6 +18,10 @@ export default class LiquidTemplates extends Plugin { onunload(): void { console.log('unloading liquid templates plugin'); + // remove the autosuggest handler when unloading the plugin + this.app.workspace.iterateCodeMirrors((cm: CodeMirror.Editor) => { + cm.off("change", this.autosuggestHandler); + }) } setupAutosuggest(): void { diff --git a/manifest.json b/manifest.json index 288a070..94a3076 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "liquid-templates", "name": "Liquid Templates", - "version": "0.1.4", + "version": "0.1.5", "minAppVersion": "0.12.3", "description": "Empower your template with LiquidJS tags", "author": "diomedet", diff --git a/package.json b/package.json index 510e76c..c8d1123 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "liquid-templates", - "version": "0.1.4", + "version": "0.1.5", "description": "Empower your template with LiquidJS tags", "main": "main.js", "scripts": { diff --git a/utils.ts b/utils.ts index 3428a82..b74edd8 100644 --- a/utils.ts +++ b/utils.ts @@ -1,6 +1,8 @@ import { App, normalizePath, TAbstractFile, TFile, TFolder, Vault } from "obsidian"; import { compact } from 'lodash'; +const ALLOWED_EXTENSIONS = ['md'] + export function getTFilesFromFolder(app: App, folderName: string, subfoldersToExclude?: string[]): Array { folderName = normalizePath(folderName); let folder = app.vault.getAbstractFileByPath(folderName); @@ -15,6 +17,7 @@ export function getTFilesFromFolder(app: App, folderName: string, subfoldersToEx Vault.recurseChildren(folder, (file: TAbstractFile) => { if (foldersToExclude.some(toExclude => file.path.startsWith(toExclude))) return; if (!(file instanceof TFile)) return; + if (!ALLOWED_EXTENSIONS.includes(file.extension)) return; files.push(file); }); diff --git a/versions.json b/versions.json index d1efb28..1395e56 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "0.1.4": "0.12.3" + "0.1.5": "0.12.3" }