diff options
| author | ivan770 <leshenko.ivan770@gmail.com> | 2021-03-18 11:21:23 +0200 |
|---|---|---|
| committer | ivan770 <leshenko.ivan770@gmail.com> | 2021-03-18 11:22:28 +0200 |
| commit | 236abe2e60efd4b50ffe0bd0a9a40d9716c192d5 (patch) | |
| tree | b582bdeb1ff9507d0aaa2de82f0efa54d8b1d4e8 | |
| parent | f62944f416e733e01a304efe43c1e66e237d905f (diff) | |
| download | rust-236abe2e60efd4b50ffe0bd0a9a40d9716c192d5.tar.gz rust-236abe2e60efd4b50ffe0bd0a9a40d9716c192d5.zip | |
Improve cursor positioning after moving
| -rw-r--r-- | editors/code/src/commands.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 59ef98ecf97..1a0805bd378 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 { 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); }); }; } |
