mirror of
https://github.com/esm7/obsidian-vimrc-support.git
synced 2026-07-22 05:00:25 +00:00
Fixed surround with backward selection
This commit is contained in:
parent
4d1a76cb3f
commit
9f9898abac
4 changed files with 11 additions and 3 deletions
|
|
@ -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.
|
||||
|
|
|
|||
4
main.ts
4
main.ts
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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": "",
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue