This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
56 lines (47 loc) · 1.49 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {MarkdownView, Plugin} from 'obsidian';
declare const CodeMirror: any;
export default class ImprovedVimCursor extends Plugin {
async onload() {
this.setup()
}
async onunload() {
CodeMirror.Vim.defineEx("g0", false, undefined);
CodeMirror.Vim.defineEx("gDollar", false, undefined);
CodeMirror.Vim.defineEx("pHead", false, undefined);
CodeMirror.Vim.defineEx("nHead", false, undefined);
}
setup() {
CodeMirror.Vim.defineEx("g0", false, (cm: CodeMirror.Editor) => {
cm.execCommand("goLineLeftSmart");
})
CodeMirror.Vim.defineEx("gDollar", false, (cm: CodeMirror.Editor) => {
cm.execCommand("goLineRight");
})
CodeMirror.Vim.defineEx("pHead", false, (cm: CodeMirror.Editor) => {
const { line } = cm.getCursor()
const text = cm.getValue()
const split = text.split("\n");
let last = 0;
for (let i = 0; i < line; i++) {
const text = split[i];
if (text.match(/^#{1,6} /)) {
last = i;
}
}
cm.setCursor(last, 0);
})
CodeMirror.Vim.defineEx("nHead", false, (cm: CodeMirror.Editor) => {
const { line } = cm.getCursor()
const text = cm.getValue()
const split = text.split("\n");
let last = split.length - 1;
for (let i = last; i > line; i--) {
const text = split[i];
if (text.match(/^#{1,6} /)) {
last = i;
}
}
cm.setCursor(last, 0);
})
}
}