-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add select message at cursor command
- Loading branch information
Showing
4 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { App, Command, Editor, MarkdownView, Notice } from 'obsidian' | ||
import { buildRunEnv, getMsgPositionByLine } from 'src/editor' | ||
import { t } from 'src/lang/helper' | ||
import { PluginSettings } from 'src/settings' | ||
|
||
export const selectMsgAtCursorCmd = (app: App, settings: PluginSettings): Command => ({ | ||
id: 'select-message-at-cursor', | ||
name: t('Select message at cursor'), | ||
editorCallback: async (editor: Editor, view: MarkdownView) => { | ||
const env = await buildRunEnv(app, settings) | ||
const currentLine = editor.getCursor('to').line | ||
const [startOffset, endOffset] = getMsgPositionByLine(env, currentLine) | ||
if (startOffset === -1 || endOffset === -1) { | ||
new Notice(t('No message found at cursor')) | ||
return | ||
} | ||
editor.setSelection(editor.offsetToPos(startOffset), editor.offsetToPos(endOffset)) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters