Skip to content

Commit

Permalink
Improve cursor positioning after moving
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan770 committed Mar 18, 2021
1 parent c901dbd commit 6ece4b1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion editors/code/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,25 @@ export function moveItem(ctx: Ctx, direction: ra.Direction): Cmd {

if (!edit) return;

let cursor: vscode.Position | null = null;

await editor.edit((builder) => {
client.protocol2CodeConverter.asTextEdits(edit.edits).forEach((edit: any) => {
builder.replace(edit.range, edit.newText);

if (direction === ra.Direction.Up) {
if (!cursor || edit.range.end.isBeforeOrEqual(cursor)) {
cursor = edit.range.end;
}
} else {
if (!cursor || edit.range.end.isAfterOrEqual(cursor)) {
cursor = edit.range.end;
}
}
});
}).then(() => {
editor.selection = new vscode.Selection(editor.selection.end, editor.selection.end);
const newPosition = cursor ?? editor.selection.start;
editor.selection = new vscode.Selection(newPosition, newPosition);
});
};
}
Expand Down

0 comments on commit 6ece4b1

Please sign in to comment.