aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands.ts
diff options
context:
space:
mode:
authorivan770 <[email protected]>2021-03-16 12:37:00 +0000
committerivan770 <[email protected]>2021-03-18 09:22:27 +0000
commit7d604584954660d255ad0929d3be8ce03f879d0c (patch)
tree613fdfdfd7eeb170082800533fb8b669dc35d25b /editors/code/src/commands.ts
parentd704750ba982153d92ccff90cf236121641b9da3 (diff)
Item up and down movers
Diffstat (limited to 'editors/code/src/commands.ts')
-rw-r--r--editors/code/src/commands.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index bed1f0116..cc90fe889 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -134,6 +134,34 @@ export function joinLines(ctx: Ctx): Cmd {
134 }; 134 };
135} 135}
136 136
137export function moveItemUp(ctx: Ctx): Cmd {
138 return moveItem(ctx, ra.Direction.Up);
139}
140
141export function moveItemDown(ctx: Ctx): Cmd {
142 return moveItem(ctx, ra.Direction.Down);
143}
144
145export function moveItem(ctx: Ctx, direction: ra.Direction): Cmd {
146 return async () => {
147 const editor = ctx.activeRustEditor;
148 const client = ctx.client;
149 if (!editor || !client) return;
150
151 const edit: lc.TextDocumentEdit = await client.sendRequest(ra.moveItem, {
152 range: client.code2ProtocolConverter.asRange(editor.selection),
153 textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
154 direction
155 });
156
157 await editor.edit((builder) => {
158 client.protocol2CodeConverter.asTextEdits(edit.edits).forEach((edit: any) => {
159 builder.replace(edit.range, edit.newText);
160 });
161 });
162 };
163}
164
137export function onEnter(ctx: Ctx): Cmd { 165export function onEnter(ctx: Ctx): Cmd {
138 async function handleKeypress() { 166 async function handleKeypress() {
139 const editor = ctx.activeRustEditor; 167 const editor = ctx.activeRustEditor;