mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Improve cursor positioning after moving
This commit is contained in:
parent
f62944f416
commit
236abe2e60
1 changed files with 14 additions and 1 deletions
|
@ -156,12 +156,25 @@ export function moveItem(ctx: Ctx, direction: ra.Direction): Cmd {
|
||||||
|
|
||||||
if (!edit) return;
|
if (!edit) return;
|
||||||
|
|
||||||
|
let cursor: vscode.Position | null = null;
|
||||||
|
|
||||||
await editor.edit((builder) => {
|
await editor.edit((builder) => {
|
||||||
client.protocol2CodeConverter.asTextEdits(edit.edits).forEach((edit: any) => {
|
client.protocol2CodeConverter.asTextEdits(edit.edits).forEach((edit: any) => {
|
||||||
builder.replace(edit.range, edit.newText);
|
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(() => {
|
}).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);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue