Skip to content

Commit

Permalink
fix: maintain the order of positions for the Selection (#1550)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed Oct 18, 2023
1 parent f4a6ac5 commit 8d76d51
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NeovimClient } from "neovim";
import { VimValue } from "neovim/lib/types/VimValue";
import { ConfigurationTarget, Disposable, Range, Selection, commands, window, workspace } from "vscode";
import { ConfigurationTarget, Disposable, Position, Range, Selection, commands, window, workspace } from "vscode";

function getActionName(action: string) {
return `neovim:${action}`;
Expand Down Expand Up @@ -113,9 +113,13 @@ class ActionManager implements Disposable {
if (!window.activeTextEditor || ranges.length === 0) return;
const doc = window.activeTextEditor.document;
window.activeTextEditor.selections = ranges.map((range) => {
const { start, end } = range;
range = doc.validateRange(new Range(start.line, start.character, end.line, end.character));
return new Selection(range.start, range.end);
const start = new Position(range.start.line, range.start.character);
const end = new Position(range.end.line, range.end.character);
const reversed = start.isAfter(end);
range = doc.validateRange(new Range(start, end));
return range.start.isBefore(range.end) && reversed
? new Selection(range.end, range.start)
: new Selection(range.start, range.end);
});
});
}
Expand Down

0 comments on commit 8d76d51

Please sign in to comment.