Skip to content

Commit 236abe2

Browse files
committed
Improve cursor positioning after moving
1 parent f62944f commit 236abe2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

editors/code/src/commands.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,25 @@ export function moveItem(ctx: Ctx, direction: ra.Direction): Cmd {
156156

157157
if (!edit) return;
158158

159+
let cursor: vscode.Position | null = null;
160+
159161
await editor.edit((builder) => {
160162
client.protocol2CodeConverter.asTextEdits(edit.edits).forEach((edit: any) => {
161163
builder.replace(edit.range, edit.newText);
164+
165+
if (direction === ra.Direction.Up) {
166+
if (!cursor || edit.range.end.isBeforeOrEqual(cursor)) {
167+
cursor = edit.range.end;
168+
}
169+
} else {
170+
if (!cursor || edit.range.end.isAfterOrEqual(cursor)) {
171+
cursor = edit.range.end;
172+
}
173+
}
162174
});
163175
}).then(() => {
164-
editor.selection = new vscode.Selection(editor.selection.end, editor.selection.end);
176+
const newPosition = cursor ?? editor.selection.start;
177+
editor.selection = new vscode.Selection(newPosition, newPosition);
165178
});
166179
};
167180
}

0 commit comments

Comments
 (0)