Skip to content

Commit

Permalink
Restore to CodeMirror default on unload
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavspi committed Dec 27, 2020
1 parent 3f03f83 commit 4552be8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
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 @@ -12,16 +10,18 @@ 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);
// @ts-ignore
cm.setOption(
"lineNumberFormatter",
// @ts-ignore
CodeMirror.defaults["lineNumberFormatter"]
);
});
}

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.2",
"version": "1.0.3",
"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.2",
"version": "1.0.3",
"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,4 +1,5 @@
{
"1.0.3": "0.10.0",
"1.0.2": "0.10.0",
"1.0.1": "0.10.0"
}

0 comments on commit 4552be8

Please sign in to comment.