generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
38 lines (32 loc) · 751 Bytes
/
main.ts
File metadata and controls
38 lines (32 loc) · 751 Bytes
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
import {
App,
MarkdownView,
Plugin,
Editor,
PluginSettingTab,
Setting
} from 'obsidian';
export default class InsertHeadingLink extends Plugin {
async onload() {
console.log('loading insert-heading-link');
this.addCommand({
id: 'addHeadingLink',
name: 'Add Heading Link',
hotkeys: [
{
modifiers: ['Mod', 'Shift'],
key: 'L',
},
],
editorCallback: (editor) => this.addHeadingLink(editor),
});
}
private addHeadingLink(editor: Editor) {
const selected_text = editor.getSelection()
editor.replaceSelection(
'[[##'+selected_text+']]'
);
const position = editor.getCursor();
editor.setCursor({ line: position.line, ch: position.ch - 2})
}
}