Skip to content

Commit c2404d0

Browse files
authored
Merge pull request #20 from alx-plugins/master
add unload method for paste handler
2 parents 359b2f0 + 83287fc commit c2404d0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import {
1010
export default class UrlIntoSel_Plugin extends Plugin {
1111
settings: PluginSettings;
1212

13+
pasteHandler = (cm: CodeMirror.Editor, e: ClipboardEvent) =>
14+
UrlIntoSelection(cm, e, this.settings);
15+
1316
async onload() {
17+
console.log("loading url-into-selection");
18+
1419
await this.loadSettings();
1520
this.addSettingTab(new UrlIntoSelectionSettingsTab(this.app, this));
1621
this.addCommand({
@@ -24,10 +29,16 @@ export default class UrlIntoSel_Plugin extends Plugin {
2429
});
2530

2631
this.registerCodeMirror((cm: CodeMirror.Editor) => {
27-
cm.on("paste", (cm, e) => UrlIntoSelection(cm, e, this.settings));
32+
cm.on("paste", this.pasteHandler);
2833
});
2934
}
3035

36+
onunload() {
37+
console.log("unloading url-into-selection");
38+
39+
this.registerCodeMirror((cm) => cm.off("paste", this.pasteHandler));
40+
}
41+
3142
async loadSettings() {
3243
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
3344
}

0 commit comments

Comments
 (0)