diff options
Diffstat (limited to 'editors/code/src/commands.ts')
-rw-r--r-- | editors/code/src/commands.ts | 28 |
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 | ||
137 | export function moveItemUp(ctx: Ctx): Cmd { | ||
138 | return moveItem(ctx, ra.Direction.Up); | ||
139 | } | ||
140 | |||
141 | export function moveItemDown(ctx: Ctx): Cmd { | ||
142 | return moveItem(ctx, ra.Direction.Down); | ||
143 | } | ||
144 | |||
145 | export 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 | |||
137 | export function onEnter(ctx: Ctx): Cmd { | 165 | export function onEnter(ctx: Ctx): Cmd { |
138 | async function handleKeypress() { | 166 | async function handleKeypress() { |
139 | const editor = ctx.activeRustEditor; | 167 | const editor = ctx.activeRustEditor; |