Skip to content

Commit

Permalink
Detect Vim mode.
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan McQuen <rpcm@linux.com>
  • Loading branch information
ryanpcmcquen committed May 14, 2021
1 parent 9450ea9 commit 500b856
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 42 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-org-mode",
"name": "Org Mode",
"version": "1.1.1",
"version": "1.2.0",
"minAppVersion": "0.10.12",
"description": "Add Org Mode support to Obsidian.",
"author": "ryanpcmcquen",
Expand Down
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "obsidian-org-mode",
"version": "1.1.1",
"description": "Add Org Mode support to Obsidian.",
"main": "main.js",
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js --environment BUILD:production"
},
"keywords": [],
"author": "",
"license": "MPL-2.0",
"devDependencies": {
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.1",
"@types/node": "^14.14.37",
"obsidian": "^0.12.0",
"rollup": "^2.32.1",
"tslib": "^2.2.0",
"typescript": "^4.2.4"
}
"name": "obsidian-org-mode",
"version": "1.2.0",
"description": "Add Org Mode support to Obsidian.",
"main": "main.js",
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js --environment BUILD:production"
},
"keywords": [],
"author": "",
"license": "MPL-2.0",
"devDependencies": {
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.1",
"@types/node": "^14.14.37",
"obsidian": "^0.12.0",
"rollup": "^2.32.1",
"tslib": "^2.2.0",
"typescript": "^4.2.4"
}
}
49 changes: 29 additions & 20 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import './lib/codemirror.js';
import './mode/simple/simple.min.js';
import './mode/orgmode/orgmode-fold.min.js';
import './mode/orgmode/orgmode-mode.min.js';
import { Plugin, WorkspaceLeaf, TextFileView } from 'obsidian';
import "./lib/codemirror.js";
import "./mode/simple/simple.min.js";
import "./mode/orgmode/orgmode-fold.min.js";
import "./mode/orgmode/orgmode-mode.min.js";
import { Plugin, TextFileView, WorkspaceLeaf } from "obsidian";

export default class OrgMode extends Plugin {
async onload() {
super.onload();
console.log('Loading Org Mode plugin ...');
console.log("Loading Org Mode plugin ...");

this.registerView('orgmode', this.orgViewCreator);
this.registerExtensions(['org'], 'orgmode');
this.registerView("orgmode", this.orgViewCreator);
this.registerExtensions(["org"], "orgmode");
}

orgViewCreator = (leaf: WorkspaceLeaf) => {
return new OrgView(leaf);
};

onunload() {
console.log('Unloading Org Mode plugin ...');
console.log("Unloading Org Mode plugin ...");
}
}

Expand All @@ -37,20 +37,20 @@ class OrgView extends TextFileView {
super(leaf);
// @ts-ignore
this.codeMirror = CodeMirror(this.extContentEl, {
theme: 'obsidian',
theme: "obsidian",

// I am not sure autofocus is necessary ...
autofocus: true,
foldGutter: {
minFoldSize: 1,
},
foldOptions: {
widget: ' ...',
widget: " ...",
},
gutters: ['CodeMirror-foldgutter'],
gutters: ["CodeMirror-foldgutter"],
});

this.codeMirror.on('changes', this.changed);
this.codeMirror.on("changes", this.changed);
}

// When the view is resized, refresh CodeMirror (thanks Licat!).
Expand All @@ -59,8 +59,8 @@ class OrgView extends TextFileView {
}

changed = async (
instance: CodeMirror.Editor,
changes: CodeMirror.EditorChangeLinkedList[]
_instance: CodeMirror.Editor,
_changes: CodeMirror.EditorChangeLinkedList[]
) => {
this.requestSave();
};
Expand All @@ -72,10 +72,19 @@ class OrgView extends TextFileView {
setViewData = (data: string, clear: boolean) => {
if (clear) {
// @ts-ignore
this.codeMirror.swapDoc(CodeMirror.Doc(data, 'orgmode'));
this.codeMirror.swapDoc(CodeMirror.Doc(data, "orgmode"));
} else {
this.codeMirror.setValue(data);
}

// HACK:
// Ideally this would actually be able to find the user defined
// keyMap, and not just check the 'vimMode' boolean.
// @ts-ignore
if (this.app?.vault?.config?.vimMode) {
this.codeMirror.setOption("keyMap", "vim");
}

// This seems to fix some odd visual bugs:
this.codeMirror.refresh();

Expand All @@ -85,23 +94,23 @@ class OrgView extends TextFileView {
};

clear = () => {
this.codeMirror.setValue('');
this.codeMirror.setValue("");
this.codeMirror.clearHistory();
};

getDisplayText() {
if (this.file) {
return this.file.basename;
} else {
return 'org (no file)';
return "org (No File)";
}
}

canAcceptExtension(extension: string) {
return extension === 'org';
return extension === "org";
}

getViewType() {
return 'orgmode';
return "orgmode";
}
}
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"1.2.0": "0.10.12",
"1.1.1": "0.10.12",
"1.1.0": "0.10.12",
"1.0.1": "0.10.12",
Expand Down

0 comments on commit 500b856

Please sign in to comment.