aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorivan770 <[email protected]>2021-03-18 09:21:23 +0000
committerivan770 <[email protected]>2021-03-18 09:22:28 +0000
commit236abe2e60efd4b50ffe0bd0a9a40d9716c192d5 (patch)
treeb582bdeb1ff9507d0aaa2de82f0efa54d8b1d4e8 /editors
parentf62944f416e733e01a304efe43c1e66e237d905f (diff)
Improve cursor positioning after moving
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/commands.ts15
1 files changed, 14 insertions, 1 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 59ef98ecf..1a0805bd3 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -156,12 +156,25 @@ export function moveItem(ctx: Ctx, direction: ra.Direction): Cmd {
156 156
157 if (!edit) return; 157 if (!edit) return;
158 158
159 let cursor: vscode.Position | null = null;
160
159 await editor.edit((builder) => { 161 await editor.edit((builder) => {
160 client.protocol2CodeConverter.asTextEdits(edit.edits).forEach((edit: any) => { 162 client.protocol2CodeConverter.asTextEdits(edit.edits).forEach((edit: any) => {
161 builder.replace(edit.range, edit.newText); 163 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 }
162 }); 174 });
163 }).then(() => { 175 }).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);
165 }); 178 });
166 }; 179 };
167} 180}