Skip to content

Commit

Permalink
properly unregister scopes when unloading the manager
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Dec 7, 2023
1 parent 95a840a commit f621507
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/popoverManager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { KeyboardEventAwareHoverParent } from "hoverParent";
import EnhancedLinkSuggestionsPlugin, { BuiltInAutocompletion, Item } from "main";
import { Component, Keymap, stripHeadingForLink } from "obsidian";
import { Component, Keymap, KeymapEventHandler, stripHeadingForLink } from "obsidian";
import { getSelectedItem } from "utils";


export class PopoverManager extends Component {
currentHoverParent: KeyboardEventAwareHoverParent | null = null;
currentOpenHoverParent: KeyboardEventAwareHoverParent | null = null;
handlers: KeymapEventHandler[] = [];

constructor(private plugin: EnhancedLinkSuggestionsPlugin, private suggest: BuiltInAutocompletion) {
super();
Expand All @@ -19,17 +20,24 @@ export class PopoverManager extends Component {
this.spawnPreview(item);
}
});
this.suggest.scope.register([this.plugin.settings.modifierToPreview], 'ArrowUp', (event) => {
this.suggest.suggestions.moveUp(event);
return false;
});
this.suggest.scope.register([this.plugin.settings.modifierToPreview], 'ArrowDown', (event) => {
this.suggest.suggestions.moveDown(event);
return false;
});
this.suggest.manager.registerDomEvent(window, 'keyup', (event: KeyboardEvent) => {
this.registerDomEvent(window, 'keyup', (event: KeyboardEvent) => {
if (event.key === this.plugin.settings.modifierToPreview) this.hide();
})
});

this.handlers.push(
this.suggest.scope.register([this.plugin.settings.modifierToPreview], 'ArrowUp', (event) => {
this.suggest.suggestions.moveUp(event);
return false;
}),
this.suggest.scope.register([this.plugin.settings.modifierToPreview], 'ArrowDown', (event) => {
this.suggest.suggestions.moveDown(event);
return false;
})
);
}

onunload() {
this.handlers.forEach((handler) => this.suggest.scope.unregister(handler));
}

hide(lazy: boolean = false) {
Expand Down

0 comments on commit f621507

Please sign in to comment.