Fixed surround with backward selection

This commit is contained in:
Erez Shermer 2022-04-10 20:37:02 +03:00
parent 4d1a76cb3f
commit 9f9898abac
4 changed files with 11 additions and 3 deletions

View file

@ -218,7 +218,7 @@ If you understand the risks and choose to use this feature, turn on "Support JS
There are two ways to define JS-based commands.
**The `jscommand` Ex command** defines a JS function that has an `editor: Editor` and `view: MarkdownView` arguments (see the [Obsidian API](https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts) if you're not sure what these are).
You define only the syntax of the function, in a single line wrapped by curly braces, e.g.:
You define only the body of the function, in a single line wrapped by curly braces, e.g.:
```
jscommand { console.log(editor.getCursor()); }
@ -250,6 +250,10 @@ See [here](JsSnippets.md) for the full example, and please contribute your own!
## Changelog
### 0.6.1
- Fixed backward selection error in `surround` (https://github.com/esm7/obsidian-vimrc-support/issues/91)
### 0.6.0
- The `surround` and `pasteinto` commands now work with the new (CM6-based) editor.

View file

@ -400,6 +400,10 @@ export default class VimrcPlugin extends Plugin {
head: {line: chosenSelection.head.line, ch: wordEnd}
};
}
// If the selection is reverse, switch the variables
if (chosenSelection.anchor.line > chosenSelection.head.line ||
(chosenSelection.anchor.line == chosenSelection.head.line && chosenSelection.anchor.ch > chosenSelection.head.ch))
[chosenSelection.anchor, chosenSelection.head] = [chosenSelection.head, chosenSelection.anchor];
let currText = editor.getRange(chosenSelection.anchor, chosenSelection.head);
editor.replaceRange(beginning + currText + ending, chosenSelection.anchor, chosenSelection.head);
}

View file

@ -1,7 +1,7 @@
{
"id": "obsidian-vimrc-support",
"name": "Vimrc Support",
"version": "0.6.0",
"version": "0.6.1",
"description": "Auto-load a startup file with Obsidian Vim commands.",
"author": "esm",
"authorUrl": "",

View file

@ -1,6 +1,6 @@
{
"name": "obsidian-vimrc-support",
"version": "0.6.0",
"version": "0.6.1",
"description": "Auto-load a startup file with Obsidian Vim commands.",
"main": "main.js",
"scripts": {