diff --git a/CHANGELOG.md b/CHANGELOG.md index 542be74..947cfe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.5.6 +- Properly unhook clickListener +- Minor refactoring + # 0.5.5 - Check current editor also on keyup event - Github workflow: Properly fix bash if else statement diff --git a/README.md b/README.md index 9895066..96630ce 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ This plugin provides a text autocomplete feature to enhance typing speed. ## Features There are the current and planned features: -- [x] Triggers with `ctrl+space` or `Toggle Autocomplete` command -- [x] Change suggestion with `Ctrl-n/p` and select with `enter` +- [x] Trigger autocomplete with `ctrl+space` or `Toggle Autocomplete` command +- [x] Change suggestion with `Ctrl-n/p` or `up/down arrows` and select with `enter` - [x] Autocomplete view style as Obsidian - [x] Supports multiple autocomplete providers (for now Latex) - [x] Seamless integration with vim mode diff --git a/manifest.json b/manifest.json index 5225736..33446db 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-autocomplete-plugin", "name": "Autocomplete", - "version": "0.5.5", + "version": "0.5.6", "minAppVersion": "0.10.0", "description": "This plugin provides a text autocomplete feature to enhance typing speed.", "author": "Yeboster", diff --git a/package.json b/package.json index 2c94679..61875ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "autocomplete-obsidian", - "version": "0.5.5", + "version": "0.5.6", "description": "An Obsidian plugin to provide text autocomplete.", "main": "index.js", "author": "Yeboster ", diff --git a/src/autocomplete.ts b/src/autocomplete.ts index 92fd445..5180b15 100644 --- a/src/autocomplete.ts +++ b/src/autocomplete.ts @@ -62,23 +62,16 @@ export default class AutocompleteView { this.addClickListener(view, editor) this.view = view - } else if (this.view.children && - this.view.children[0] && - this.view.children[0].children) { + } else if (this.view.firstChild && this.view.firstChild.nextSibling) { // Somehow first child is in nextSibling cachedView = true - const children = this.view.children[0].children + const children = (this.view.firstChild.nextSibling as HTMLElement).children const selectedIndex = this.selected.index - const selectedClass = 'is-selected' + for (let index = 0; index < children.length; index++) { const child = children[index] - const classes = child.classList - if (index === selectedIndex) { - if (!classes.contains(selectedClass)) - classes.add(selectedClass) - } else if (classes.contains(selectedClass)) - classes.remove(selectedClass) + child.toggleClass('is-selected', index === selectedIndex) } } diff --git a/src/main.ts b/src/main.ts index cd3beb5..b32479d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -81,7 +81,7 @@ export default class AutocompletePlugin extends Plugin { async onunload() { const workspace = this.app.workspace workspace.iterateCodeMirrors(cm => { - cm.off('keyup', this.keyupListener.bind(this)) + cm.off('keyup', this.keyupListener) this.autocompleteView.removeView(cm) }) console.log('Unloaded Obsidian Autocomplete') @@ -106,10 +106,6 @@ export default class AutocompletePlugin extends Plugin { private getCurrentEditor(): CodeMirror.Editor | null { const view = this.app.workspace.getActiveViewOfType(MarkdownView) - let editor = undefined - if (view) - editor = view.sourceMode.cmEditor - - return editor + return view ? view.sourceMode.cmEditor : null } } diff --git a/versions.json b/versions.json index a1f20a6..4f2cd96 100644 --- a/versions.json +++ b/versions.json @@ -3,5 +3,6 @@ "0.5.2": "0.10.1", "0.5.3": "0.10.0", "0.5.4": "0.10.0", - "0.5.5": "0.10.0" + "0.5.5": "0.10.0", + "0.5.6": "0.10.0" }