gokulk16_select-current-lin.../main.ts
2023-04-11 22:11:43 +05:30

28 lines
701 B
TypeScript

import { Editor, MarkdownView, Plugin } from 'obsidian';
// selects the entire line from index zero
function selectLine(editor: Editor) {
const { line } = editor.getCursor();
const lineText = editor.getLine(line);
editor.setSelection({ line, ch: 0 }, { line, ch: lineText.length });
}
export default class SelectCurrentLinePlugin extends Plugin {
async onload() {
// This adds an editor command on the current editor instance
this.addCommand({
id: 'select-current-line-on-keystroke',
name: 'select the current line in editor',
hotkeys: [{modifiers: [], key: 'Escape'}],
editorCallback: (editor: Editor) => {
selectLine(editor);
}
});
}
onunload() {
}
}