mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Move cursor position when using item movers
This commit is contained in:
parent
10a243ea55
commit
30aae2cefb
7 changed files with 83 additions and 74 deletions
|
@ -148,34 +148,16 @@ export function moveItem(ctx: Ctx, direction: ra.Direction): Cmd {
|
|||
const client = ctx.client;
|
||||
if (!editor || !client) return;
|
||||
|
||||
const edit = await client.sendRequest(ra.moveItem, {
|
||||
const lcEdits = await client.sendRequest(ra.moveItem, {
|
||||
range: client.code2ProtocolConverter.asRange(editor.selection),
|
||||
textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
|
||||
direction
|
||||
});
|
||||
|
||||
if (!edit) return;
|
||||
if (!lcEdits) 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(() => {
|
||||
const newPosition = cursor ?? editor.selection.start;
|
||||
editor.selection = new vscode.Selection(newPosition, newPosition);
|
||||
});
|
||||
const edits = client.protocol2CodeConverter.asTextEdits(lcEdits);
|
||||
await applySnippetTextEdits(editor, edits);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue