Skip to content

Commit

Permalink
Format bullet list: keep selecting whole paragraphs after formattin…
Browse files Browse the repository at this point in the history
…g rather than set cursor at the end.
  • Loading branch information
Benature committed Mar 10, 2024
1 parent 229c535 commit 2d30e89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
17 changes: 8 additions & 9 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
Expand All @@ -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);
}
Expand Down

0 comments on commit 2d30e89

Please sign in to comment.