From 2d30e89e8d341d154bfb4666f9daa5f6f343f949 Mon Sep 17 00:00:00 2001 From: Benature Date: Sun, 10 Mar 2024 14:46:58 +0800 Subject: [PATCH] `Format bullet list`: keep selecting whole paragraphs after formatting rather than set cursor at the end. --- CHANGELOG.md | 5 +++-- main.ts | 17 ++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dbae0b..dedd5ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,16 +6,17 @@ > to be updated in the next version # 2.7.0 +- [updated] `Format bullet list`: keep selecting whole paragraphs after formatting rather than set cursor at the end. - [notice] refactoring i18n, but zh-tw language will be deprecated later becasue of the limitation of developing time. - [feature] support [#68](https://github.com/Benature/obsidian-text-format/issues/68) -- [updated] Convert wikiLinks to plain markdown links in selection: Three path modes +- [updated] `Convert wikiLinks to plain markdown links in selection`: Three path modes - absolute - relative to Obsidian - relative to file - [feature] collapsible heading in settings - [feature] custom replacement - [updated] callout format: auto select whole paragraph -- [feature] math mode: +- [feature] `math mode`: - rename: Detect and convert characters to math mode (LaTeX) - two characters (sub case): e.g. `a0` -> `$a_0$` - [ ] More ignore case should be considered. For now: `/is|or|as|to|am|an|at|by|do|go|ha|he|hi|ho|if|in|it|my|no|of|on|so|up|us|we/g` diff --git a/main.ts b/main.ts index 1d548fb..8a876d6 100644 --- a/main.ts +++ b/main.ts @@ -659,12 +659,10 @@ export default class TextFormat extends Plugin { } editorTextFormat(editor: Editor, view: MarkdownView, cmd: string, args: any = ""): void { - let selectedText: string; - // if nothing is selected, select the whole line. - let somethingSelected = editor.somethingSelected(); - let origin_cursor_from = editor.getCursor("from"); - let origin_cursor_to = editor.getCursor("to"); + const somethingSelected = editor.somethingSelected(); + const origin_cursor_from = editor.getCursor("from"); + const origin_cursor_to = editor.getCursor("to"); if (!somethingSelected) { let cursor = editor.getCursor(); @@ -680,7 +678,7 @@ export default class TextFormat extends Plugin { editor.setSelection(editor.offsetToPos(aos), editor.offsetToPos(hos)); } - selectedText = editor.getSelection(); + let selectedText = editor.getSelection(); let from = editor.getCursor("from"), to = editor.getCursor("to"); @@ -727,7 +725,7 @@ export default class TextFormat extends Plugin { break; } - // modify selection text + //: Modify selected text let replacedText = this.textFormat(selectedText, cmd, args); if (replacedText === null) { switch (cmd) { @@ -776,11 +774,13 @@ export default class TextFormat extends Plugin { editor.replaceSelection(replacedText); } + //: Set cursor selection const fos = editor.posToOffset(editor.getCursor("from")); - // cursor selection switch (cmd) { case "merge": case "remove-blank-line": + case "bullet": + //: Select whole modifications const tos = editor.posToOffset(editor.getCursor("to")); // to offset editor.setSelection( editor.offsetToPos(tos - replacedText.length), @@ -800,7 +800,6 @@ export default class TextFormat extends Plugin { } break; default: - // console.log(cmd) let head = editor.getCursor("head"); editor.setSelection(editor.offsetToPos(fos), head); }