Skip to content

Commit

Permalink
Clean up on unload
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavspi committed Dec 27, 2020
1 parent 0f1206e commit 3f03f83
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
12 changes: 12 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Plugin } from "obsidian";

export default class RelativeLineNumbers extends Plugin {
initialLineNumberFormatter: (line: number) => string;

onload() {
// @ts-ignore
const showLineNumber: Boolean = this.app.vault.getConfig("showLineNumber");
Expand All @@ -10,6 +12,16 @@ export default class RelativeLineNumbers extends Plugin {

this.registerCodeMirror((cm) => {
cm.on("cursorActivity", this.relativeLineNumbers);
// I haven't found a way to get the default value for an option,
// so we'll store the value at the time we loaded
this.initialLineNumberFormatter = cm.getOption("lineNumberFormatter");
});
}

onunload() {
this.app.workspace.iterateCodeMirrors((cm) => {
cm.off("cursorActivity", this.relativeLineNumbers);
cm.setOption("lineNumberFormatter", this.initialLineNumberFormatter);
});
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-relative-line-numbers",
"name": "Relative Line Numbers",
"version": "1.0.1",
"version": "1.0.2",
"minAppVersion": "0.10.0",
"description": "Enables relative line numbers in editor mode",
"author": "Nadav Spiegelman",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-relative-line-numbers",
"version": "1.0.1",
"version": "1.0.2",
"description": "Enables relative line numbers in editor mode",
"main": "main.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"1.0.2": "0.10.0",
"1.0.1": "0.10.0"
}

0 comments on commit 3f03f83

Please sign in to comment.