Fix RangeError when executing surround command with backward selection (#234)

This commit is contained in:
ko-shin-ryo 2024-09-11 17:29:45 +09:00 committed by GitHub
parent 2a5fffa2d1
commit 10c2b613bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

10
main.ts
View file

@ -494,12 +494,10 @@ export default class VimrcPlugin extends Plugin {
chosenSelection = {anchor: wordAt.from, head: wordAt.to};
}
}
let currText;
if (editor.posToOffset(chosenSelection.anchor) > editor.posToOffset(chosenSelection.head)) {
currText = editor.getRange(chosenSelection.head, chosenSelection.anchor);
} else {
currText = editor.getRange(chosenSelection.anchor, chosenSelection.head);
}
if (editor.posToOffset(chosenSelection.anchor) > editor.posToOffset(chosenSelection.head)) {
[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);
// If no selection, place cursor between beginning and ending
if (editor.posToOffset(chosenSelection.anchor) === editor.posToOffset(chosenSelection.head)) {