@tooee/ask 0.7.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ask-editor.d.ts +2 -1
- package/dist/ask-editor.d.ts.map +1 -1
- package/dist/ask-editor.js.map +1 -1
- package/dist/ask-panel.d.ts +5 -11
- package/dist/ask-panel.d.ts.map +1 -1
- package/dist/ask-panel.js +7 -18
- package/dist/ask-panel.js.map +1 -1
- package/dist/ask.d.ts +4 -4
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +6 -14
- package/dist/ask.js.map +1 -1
- package/dist/editor-scrollbar.d.ts +2 -1
- package/dist/editor-scrollbar.d.ts.map +1 -1
- package/dist/editor-scrollbar.js.map +1 -1
- package/dist/launch.d.ts +2 -2
- package/dist/launch.d.ts.map +1 -1
- package/dist/launch.js +9 -3
- package/dist/launch.js.map +1 -1
- package/dist/use-ask-dialog.d.ts.map +1 -1
- package/dist/use-ask-dialog.js +10 -74
- package/dist/use-ask-dialog.js.map +1 -1
- package/dist/use-ask-editor.d.ts +1 -1
- package/dist/use-ask-editor.d.ts.map +1 -1
- package/dist/use-ask-editor.js +222 -346
- package/dist/use-ask-editor.js.map +1 -1
- package/package.json +9 -8
- package/src/ask-editor.tsx +2 -1
- package/src/ask-panel.tsx +18 -95
- package/src/ask.tsx +9 -19
- package/src/editor-scrollbar.tsx +2 -1
- package/src/launch.tsx +24 -15
- package/src/use-ask-dialog.tsx +32 -102
- package/src/use-ask-editor.ts +234 -335
package/src/use-ask-editor.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import type {
|
|
3
3
|
InputRenderable,
|
|
4
4
|
KeyEvent,
|
|
@@ -9,20 +9,22 @@ import type {
|
|
|
9
9
|
import { copyToClipboard, readPrimaryText } from "@tooee/clipboard";
|
|
10
10
|
import {
|
|
11
11
|
useActiveCommandSurface,
|
|
12
|
-
|
|
12
|
+
useActions,
|
|
13
13
|
useCommandSurfaceId,
|
|
14
|
+
useLatest,
|
|
15
|
+
useLazyRef,
|
|
14
16
|
useMode,
|
|
15
17
|
useProvideCommandContext,
|
|
16
18
|
useSetMode,
|
|
17
19
|
} from "@tooee/commands";
|
|
18
|
-
import type { CommandContext, Mode } from "@tooee/commands";
|
|
20
|
+
import type { ActionDefinition, CommandContext, Mode } from "@tooee/commands";
|
|
19
21
|
import { appendAtCursor, openLineAtCursor } from "./vim-motions.js";
|
|
20
22
|
import type { VimMotionState } from "./vim-motions.js";
|
|
21
23
|
|
|
22
24
|
declare module "@tooee/commands" {
|
|
23
25
|
interface CommandContext {
|
|
24
26
|
/** Contributed by ask editors: the current input value. */
|
|
25
|
-
ask
|
|
27
|
+
ask?: { value: string };
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
|
|
@@ -107,6 +109,11 @@ export interface UseAskEditorResult {
|
|
|
107
109
|
editor: AskEditorViewModel;
|
|
108
110
|
}
|
|
109
111
|
|
|
112
|
+
interface AskEditorKeymapDefinition extends Omit<ActionDefinition, "group" | "when"> {
|
|
113
|
+
group: AskEditorCommandGroup;
|
|
114
|
+
when?: () => boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
110
117
|
/**
|
|
111
118
|
* Headless ask editor core: owns editor state and registers all editing
|
|
112
119
|
* commands (vim motions, insert entries, submit/cancel/escape) on the nearest
|
|
@@ -133,14 +140,10 @@ export const useAskEditor = function useAskEditor(
|
|
|
133
140
|
setScrollRevision((r) => r + 1);
|
|
134
141
|
}, []);
|
|
135
142
|
|
|
136
|
-
const optionsRef =
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
const multilineRef = useRef(multiline);
|
|
141
|
-
multilineRef.current = multiline;
|
|
142
|
-
const valueRef = useRef(value);
|
|
143
|
-
valueRef.current = value;
|
|
143
|
+
const optionsRef = useLatest(options);
|
|
144
|
+
const modeRef = useLatest(mode);
|
|
145
|
+
const multilineRef = useLatest(multiline);
|
|
146
|
+
const valueRef = useLatest(value);
|
|
144
147
|
|
|
145
148
|
// Suspension: while a modal command surface other than our own is topmost,
|
|
146
149
|
// our commands are already suspended by the surface stack; this mirrors that
|
|
@@ -152,11 +155,14 @@ export const useAskEditor = function useAskEditor(
|
|
|
152
155
|
|
|
153
156
|
const focused = (mode === "insert" || mode === "cursor") && !suspended;
|
|
154
157
|
|
|
155
|
-
const preventCursorModeEditorInput = useCallback(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
const preventCursorModeEditorInput = useCallback(
|
|
159
|
+
(event: KeyEvent | PasteEvent) => {
|
|
160
|
+
if (modeRef.current === "cursor") {
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
[modeRef],
|
|
165
|
+
);
|
|
160
166
|
|
|
161
167
|
useEffect(() => {
|
|
162
168
|
if (didPositionInitialCursorRef.current || (defaultValue?.length ?? 0) === 0) {
|
|
@@ -179,7 +185,7 @@ export const useAskEditor = function useAskEditor(
|
|
|
179
185
|
|
|
180
186
|
const getTarget = useCallback(
|
|
181
187
|
() => (multilineRef.current ? textareaRef.current : inputRef.current),
|
|
182
|
-
[],
|
|
188
|
+
[multilineRef],
|
|
183
189
|
);
|
|
184
190
|
|
|
185
191
|
// Controller mutations must be observable before React state synchronizes.
|
|
@@ -188,18 +194,18 @@ export const useAskEditor = function useAskEditor(
|
|
|
188
194
|
multilineRef.current
|
|
189
195
|
? (textareaRef.current?.plainText ?? "")
|
|
190
196
|
: (inputRef.current?.plainText ?? valueRef.current),
|
|
191
|
-
[],
|
|
197
|
+
[multilineRef, valueRef],
|
|
192
198
|
);
|
|
193
199
|
|
|
194
200
|
const submit = useCallback(() => {
|
|
195
201
|
void optionsRef.current.onSubmit?.(getText());
|
|
196
|
-
}, [getText]);
|
|
202
|
+
}, [getText, optionsRef]);
|
|
197
203
|
|
|
198
204
|
useProvideCommandContext(() => ({ ask: { value: getText() } }));
|
|
199
205
|
|
|
200
206
|
const enabled = useCallback(
|
|
201
207
|
(group: AskEditorCommandGroup) => !(optionsRef.current.disable?.includes(group) ?? false),
|
|
202
|
-
[],
|
|
208
|
+
[optionsRef],
|
|
203
209
|
);
|
|
204
210
|
|
|
205
211
|
const resolveSubmitKey = useCallback((): AskSubmitKey => {
|
|
@@ -210,17 +216,17 @@ export const useAskEditor = function useAskEditor(
|
|
|
210
216
|
const copyText = useCallback(
|
|
211
217
|
(text: string, emptyMessage: string, successMessage: string, ctx: CommandContext) => {
|
|
212
218
|
if (text === "") {
|
|
213
|
-
ctx.toast
|
|
219
|
+
ctx.toast?.toast({ level: "warning", message: emptyMessage });
|
|
214
220
|
return;
|
|
215
221
|
}
|
|
216
222
|
void copyToClipboard(text);
|
|
217
|
-
ctx.toast
|
|
223
|
+
ctx.toast?.toast({ level: "success", message: successMessage });
|
|
218
224
|
},
|
|
219
225
|
[],
|
|
220
226
|
);
|
|
221
227
|
|
|
222
|
-
|
|
223
|
-
|
|
228
|
+
const copyLine = useCallback(
|
|
229
|
+
(ctx: CommandContext) => {
|
|
224
230
|
const target = getTarget();
|
|
225
231
|
if (!target) {
|
|
226
232
|
copyText("", "Nothing to copy", "Copied line to clipboard", ctx);
|
|
@@ -233,37 +239,22 @@ export const useAskEditor = function useAskEditor(
|
|
|
233
239
|
const end = nextNewline === -1 ? text.length : nextNewline;
|
|
234
240
|
copyText(text.slice(start, end), "Nothing to copy", "Copied line to clipboard", ctx);
|
|
235
241
|
},
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
title: "Copy current line",
|
|
241
|
-
when: () => enabled("copy"),
|
|
242
|
-
});
|
|
243
|
-
useCommand({
|
|
244
|
-
handler: (ctx) => {
|
|
242
|
+
[copyText, getTarget],
|
|
243
|
+
);
|
|
244
|
+
const copyDocument = useCallback(
|
|
245
|
+
(ctx: CommandContext) => {
|
|
245
246
|
copyText(getText(), "Nothing to copy", "Copied document to clipboard", ctx);
|
|
246
247
|
},
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
title: "Copy document",
|
|
252
|
-
when: () => enabled("copy"),
|
|
253
|
-
});
|
|
254
|
-
useCommand({
|
|
255
|
-
handler: (ctx) => {
|
|
248
|
+
[copyText, getText],
|
|
249
|
+
);
|
|
250
|
+
const copySelection = useCallback(
|
|
251
|
+
(ctx: CommandContext) => {
|
|
256
252
|
const target = getTarget();
|
|
257
253
|
const text = target?.hasSelection() === true ? target.getSelectedText() : "";
|
|
258
254
|
copyText(text, "Nothing selected", "Copied selection to clipboard", ctx);
|
|
259
255
|
},
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
id: `${commandScope}:copy-selection`,
|
|
263
|
-
modes: ["cursor"],
|
|
264
|
-
title: "Copy selection",
|
|
265
|
-
when: () => enabled("copy"),
|
|
266
|
-
});
|
|
256
|
+
[copyText, getTarget],
|
|
257
|
+
);
|
|
267
258
|
|
|
268
259
|
const enterInsertMode = useCallback(() => {
|
|
269
260
|
vimMotionStateRef.current.pendingG = false;
|
|
@@ -283,7 +274,7 @@ export const useAskEditor = function useAskEditor(
|
|
|
283
274
|
vimMotionStateRef.current.pendingG = false;
|
|
284
275
|
openLineAtCursor(textareaRef.current, "above");
|
|
285
276
|
setMode("insert");
|
|
286
|
-
}, [setMode]);
|
|
277
|
+
}, [multilineRef, setMode]);
|
|
287
278
|
|
|
288
279
|
const openLineBelow = useCallback(() => {
|
|
289
280
|
if (!multilineRef.current) {
|
|
@@ -292,99 +283,13 @@ export const useAskEditor = function useAskEditor(
|
|
|
292
283
|
vimMotionStateRef.current.pendingG = false;
|
|
293
284
|
openLineAtCursor(textareaRef.current, "below");
|
|
294
285
|
setMode("insert");
|
|
295
|
-
}, [setMode]);
|
|
286
|
+
}, [multilineRef, setMode]);
|
|
296
287
|
|
|
297
288
|
const leaveInsertMode = useCallback(() => {
|
|
298
289
|
vimMotionStateRef.current.pendingG = false;
|
|
299
290
|
setMode("cursor");
|
|
300
291
|
}, [setMode]);
|
|
301
292
|
|
|
302
|
-
useCommand({
|
|
303
|
-
handler: leaveInsertMode,
|
|
304
|
-
hidden: true,
|
|
305
|
-
hotkey: "Escape",
|
|
306
|
-
id: `${commandScope}:leave-insert-mode`,
|
|
307
|
-
modes: ["insert"],
|
|
308
|
-
title: "Command mode",
|
|
309
|
-
when: () => enabled("escape"),
|
|
310
|
-
});
|
|
311
|
-
useCommand({
|
|
312
|
-
handler: () => optionsRef.current.onCancel?.(),
|
|
313
|
-
hidden: true,
|
|
314
|
-
hotkey: "q",
|
|
315
|
-
id: `${commandScope}:cancel`,
|
|
316
|
-
modes: ["cursor"],
|
|
317
|
-
title: "Cancel",
|
|
318
|
-
when: () => enabled("cancel") && optionsRef.current.onCancel !== undefined,
|
|
319
|
-
});
|
|
320
|
-
useCommand({
|
|
321
|
-
handler: enterInsertMode,
|
|
322
|
-
hidden: true,
|
|
323
|
-
hotkey: "i",
|
|
324
|
-
id: `${commandScope}:insert-mode-i`,
|
|
325
|
-
modes: ["cursor"],
|
|
326
|
-
title: "Insert mode",
|
|
327
|
-
when: () => enabled("insert-commands"),
|
|
328
|
-
});
|
|
329
|
-
useCommand({
|
|
330
|
-
handler: appendAndEnterInsertMode,
|
|
331
|
-
hidden: true,
|
|
332
|
-
hotkey: "a",
|
|
333
|
-
id: `${commandScope}:insert-mode-a`,
|
|
334
|
-
modes: ["cursor"],
|
|
335
|
-
title: "Append",
|
|
336
|
-
when: () => enabled("insert-commands"),
|
|
337
|
-
});
|
|
338
|
-
useCommand({
|
|
339
|
-
handler: openLineAbove,
|
|
340
|
-
hidden: true,
|
|
341
|
-
hotkey: "shift+o",
|
|
342
|
-
id: `${commandScope}:open-line-above`,
|
|
343
|
-
modes: ["cursor"],
|
|
344
|
-
title: "Open line above",
|
|
345
|
-
when: () => enabled("insert-commands") && multilineRef.current,
|
|
346
|
-
});
|
|
347
|
-
useCommand({
|
|
348
|
-
handler: openLineBelow,
|
|
349
|
-
hidden: true,
|
|
350
|
-
hotkey: "o",
|
|
351
|
-
id: `${commandScope}:open-line-below`,
|
|
352
|
-
modes: ["cursor"],
|
|
353
|
-
title: "Open line below",
|
|
354
|
-
when: () => enabled("insert-commands") && multilineRef.current,
|
|
355
|
-
});
|
|
356
|
-
useCommand({
|
|
357
|
-
handler: submit,
|
|
358
|
-
hidden: true,
|
|
359
|
-
hotkey: "Enter",
|
|
360
|
-
id: `${commandScope}:submit-insert`,
|
|
361
|
-
modes: ["insert"],
|
|
362
|
-
title: "Submit",
|
|
363
|
-
when: () => enabled("submit") && resolveSubmitKey() === "enter",
|
|
364
|
-
});
|
|
365
|
-
useCommand({
|
|
366
|
-
handler: submit,
|
|
367
|
-
hidden: true,
|
|
368
|
-
hotkey: "Enter",
|
|
369
|
-
id: `${commandScope}:submit-cursor`,
|
|
370
|
-
modes: ["cursor"],
|
|
371
|
-
title: "Submit",
|
|
372
|
-
// Command mode has no newline entry, so plain Enter always submits unless
|
|
373
|
-
// the consumer disabled the built-in submit command group.
|
|
374
|
-
when: () => enabled("submit") && resolveSubmitKey() !== "none",
|
|
375
|
-
});
|
|
376
|
-
useCommand({
|
|
377
|
-
handler: submit,
|
|
378
|
-
hidden: true,
|
|
379
|
-
hotkey: "shift+Enter",
|
|
380
|
-
id: `${commandScope}:submit-multiline`,
|
|
381
|
-
modes: ["insert", "cursor"],
|
|
382
|
-
title: "Submit",
|
|
383
|
-
// Shift+Enter remains available for multiline insert mode and for
|
|
384
|
-
// compatibility in cursor mode.
|
|
385
|
-
when: () => enabled("submit") && resolveSubmitKey() !== "none",
|
|
386
|
-
});
|
|
387
|
-
|
|
388
293
|
const motion = useCallback(
|
|
389
294
|
(run: (target: TextareaRenderable | InputRenderable) => void) => {
|
|
390
295
|
const target = getTarget();
|
|
@@ -397,214 +302,209 @@ export const useAskEditor = function useAskEditor(
|
|
|
397
302
|
[getTarget, bumpScroll],
|
|
398
303
|
);
|
|
399
304
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
305
|
+
const builtInActions = useMemo<ActionDefinition[]>(() => {
|
|
306
|
+
const motionAction = (
|
|
307
|
+
id: string,
|
|
308
|
+
hotkey: string,
|
|
309
|
+
title: string,
|
|
310
|
+
run: (target: TextareaRenderable | InputRenderable) => void,
|
|
311
|
+
): AskEditorKeymapDefinition => ({
|
|
312
|
+
group: "motions",
|
|
313
|
+
handler: () => {
|
|
314
|
+
motion(run);
|
|
315
|
+
},
|
|
316
|
+
hidden: true,
|
|
317
|
+
hotkey,
|
|
318
|
+
id: `${commandScope}:${id}`,
|
|
319
|
+
modes: ["cursor"],
|
|
320
|
+
title,
|
|
321
|
+
});
|
|
322
|
+
const definitions: AskEditorKeymapDefinition[] = [
|
|
323
|
+
{
|
|
324
|
+
group: "copy",
|
|
325
|
+
handler: copyLine,
|
|
326
|
+
hidden: true,
|
|
327
|
+
hotkey: "y y",
|
|
328
|
+
id: `${commandScope}:copy-line`,
|
|
329
|
+
modes: ["cursor"],
|
|
330
|
+
title: "Copy current line",
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
group: "copy",
|
|
334
|
+
handler: copyDocument,
|
|
335
|
+
hidden: true,
|
|
336
|
+
hotkey: "y g",
|
|
337
|
+
id: `${commandScope}:copy-document`,
|
|
338
|
+
modes: ["cursor"],
|
|
339
|
+
title: "Copy document",
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
group: "copy",
|
|
343
|
+
handler: copySelection,
|
|
344
|
+
hidden: true,
|
|
345
|
+
hotkey: "y v",
|
|
346
|
+
id: `${commandScope}:copy-selection`,
|
|
347
|
+
modes: ["cursor"],
|
|
348
|
+
title: "Copy selection",
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
group: "escape",
|
|
352
|
+
handler: leaveInsertMode,
|
|
353
|
+
hidden: true,
|
|
354
|
+
hotkey: "Escape",
|
|
355
|
+
id: `${commandScope}:leave-insert-mode`,
|
|
356
|
+
modes: ["insert"],
|
|
357
|
+
title: "Command mode",
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
group: "cancel",
|
|
361
|
+
handler: () => optionsRef.current.onCancel?.(),
|
|
362
|
+
hidden: true,
|
|
363
|
+
hotkey: "q",
|
|
364
|
+
id: `${commandScope}:cancel`,
|
|
365
|
+
modes: ["cursor"],
|
|
366
|
+
title: "Cancel",
|
|
367
|
+
when: () => optionsRef.current.onCancel !== undefined,
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
group: "insert-commands",
|
|
371
|
+
handler: enterInsertMode,
|
|
372
|
+
hidden: true,
|
|
373
|
+
hotkey: "i",
|
|
374
|
+
id: `${commandScope}:insert-mode-i`,
|
|
375
|
+
modes: ["cursor"],
|
|
376
|
+
title: "Insert mode",
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
group: "insert-commands",
|
|
380
|
+
handler: appendAndEnterInsertMode,
|
|
381
|
+
hidden: true,
|
|
382
|
+
hotkey: "a",
|
|
383
|
+
id: `${commandScope}:insert-mode-a`,
|
|
384
|
+
modes: ["cursor"],
|
|
385
|
+
title: "Append",
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
group: "insert-commands",
|
|
389
|
+
handler: openLineAbove,
|
|
390
|
+
hidden: true,
|
|
391
|
+
hotkey: "shift+o",
|
|
392
|
+
id: `${commandScope}:open-line-above`,
|
|
393
|
+
modes: ["cursor"],
|
|
394
|
+
title: "Open line above",
|
|
395
|
+
when: () => multilineRef.current,
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
group: "insert-commands",
|
|
399
|
+
handler: openLineBelow,
|
|
400
|
+
hidden: true,
|
|
401
|
+
hotkey: "o",
|
|
402
|
+
id: `${commandScope}:open-line-below`,
|
|
403
|
+
modes: ["cursor"],
|
|
404
|
+
title: "Open line below",
|
|
405
|
+
when: () => multilineRef.current,
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
group: "submit",
|
|
409
|
+
handler: submit,
|
|
410
|
+
hidden: true,
|
|
411
|
+
hotkey: "Enter",
|
|
412
|
+
id: `${commandScope}:submit-insert`,
|
|
413
|
+
modes: ["insert"],
|
|
414
|
+
title: "Submit",
|
|
415
|
+
when: () => resolveSubmitKey() === "enter",
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
group: "submit",
|
|
419
|
+
handler: submit,
|
|
420
|
+
hidden: true,
|
|
421
|
+
hotkey: "Enter",
|
|
422
|
+
id: `${commandScope}:submit-cursor`,
|
|
423
|
+
modes: ["cursor"],
|
|
424
|
+
title: "Submit",
|
|
425
|
+
when: () => resolveSubmitKey() !== "none",
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
group: "submit",
|
|
429
|
+
handler: submit,
|
|
430
|
+
hidden: true,
|
|
431
|
+
hotkey: "shift+Enter",
|
|
432
|
+
id: `${commandScope}:submit-multiline`,
|
|
433
|
+
modes: ["insert", "cursor"],
|
|
434
|
+
title: "Submit",
|
|
435
|
+
when: () => resolveSubmitKey() !== "none",
|
|
436
|
+
},
|
|
437
|
+
motionAction("move-left", "h", "Move left", (target) => {
|
|
403
438
|
target.moveCursorLeft();
|
|
404
|
-
})
|
|
405
|
-
|
|
406
|
-
hidden: true,
|
|
407
|
-
hotkey: "h",
|
|
408
|
-
id: `${commandScope}:move-left`,
|
|
409
|
-
modes: ["cursor"],
|
|
410
|
-
title: "Move left",
|
|
411
|
-
when: () => enabled("motions"),
|
|
412
|
-
});
|
|
413
|
-
useCommand({
|
|
414
|
-
handler: () => {
|
|
415
|
-
motion((target) => {
|
|
439
|
+
}),
|
|
440
|
+
motionAction("move-left-arrow", "left", "Move left", (target) => {
|
|
416
441
|
target.moveCursorLeft();
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
hidden: true,
|
|
420
|
-
hotkey: "left",
|
|
421
|
-
id: `${commandScope}:move-left-arrow`,
|
|
422
|
-
modes: ["cursor"],
|
|
423
|
-
title: "Move left",
|
|
424
|
-
when: () => enabled("motions"),
|
|
425
|
-
});
|
|
426
|
-
useCommand({
|
|
427
|
-
handler: () => {
|
|
428
|
-
motion((target) => {
|
|
442
|
+
}),
|
|
443
|
+
motionAction("move-right", "l", "Move right", (target) => {
|
|
429
444
|
target.moveCursorRight();
|
|
430
|
-
})
|
|
431
|
-
|
|
432
|
-
hidden: true,
|
|
433
|
-
hotkey: "l",
|
|
434
|
-
id: `${commandScope}:move-right`,
|
|
435
|
-
modes: ["cursor"],
|
|
436
|
-
title: "Move right",
|
|
437
|
-
when: () => enabled("motions"),
|
|
438
|
-
});
|
|
439
|
-
useCommand({
|
|
440
|
-
handler: () => {
|
|
441
|
-
motion((target) => {
|
|
445
|
+
}),
|
|
446
|
+
motionAction("move-right-arrow", "right", "Move right", (target) => {
|
|
442
447
|
target.moveCursorRight();
|
|
443
|
-
})
|
|
444
|
-
|
|
445
|
-
hidden: true,
|
|
446
|
-
hotkey: "right",
|
|
447
|
-
id: `${commandScope}:move-right-arrow`,
|
|
448
|
-
modes: ["cursor"],
|
|
449
|
-
title: "Move right",
|
|
450
|
-
when: () => enabled("motions"),
|
|
451
|
-
});
|
|
452
|
-
useCommand({
|
|
453
|
-
handler: () => {
|
|
454
|
-
motion((target) => {
|
|
448
|
+
}),
|
|
449
|
+
motionAction("move-down", "j", "Move down", (target) => {
|
|
455
450
|
target.moveCursorDown();
|
|
456
|
-
})
|
|
457
|
-
|
|
458
|
-
hidden: true,
|
|
459
|
-
hotkey: "j",
|
|
460
|
-
id: `${commandScope}:move-down`,
|
|
461
|
-
modes: ["cursor"],
|
|
462
|
-
title: "Move down",
|
|
463
|
-
when: () => enabled("motions"),
|
|
464
|
-
});
|
|
465
|
-
useCommand({
|
|
466
|
-
handler: () => {
|
|
467
|
-
motion((target) => {
|
|
451
|
+
}),
|
|
452
|
+
motionAction("move-down-arrow", "down", "Move down", (target) => {
|
|
468
453
|
target.moveCursorDown();
|
|
469
|
-
})
|
|
470
|
-
|
|
471
|
-
hidden: true,
|
|
472
|
-
hotkey: "down",
|
|
473
|
-
id: `${commandScope}:move-down-arrow`,
|
|
474
|
-
modes: ["cursor"],
|
|
475
|
-
title: "Move down",
|
|
476
|
-
when: () => enabled("motions"),
|
|
477
|
-
});
|
|
478
|
-
useCommand({
|
|
479
|
-
handler: () => {
|
|
480
|
-
motion((target) => {
|
|
454
|
+
}),
|
|
455
|
+
motionAction("move-up", "k", "Move up", (target) => {
|
|
481
456
|
target.moveCursorUp();
|
|
482
|
-
})
|
|
483
|
-
|
|
484
|
-
hidden: true,
|
|
485
|
-
hotkey: "k",
|
|
486
|
-
id: `${commandScope}:move-up`,
|
|
487
|
-
modes: ["cursor"],
|
|
488
|
-
title: "Move up",
|
|
489
|
-
when: () => enabled("motions"),
|
|
490
|
-
});
|
|
491
|
-
useCommand({
|
|
492
|
-
handler: () => {
|
|
493
|
-
motion((target) => {
|
|
457
|
+
}),
|
|
458
|
+
motionAction("move-up-arrow", "up", "Move up", (target) => {
|
|
494
459
|
target.moveCursorUp();
|
|
495
|
-
})
|
|
496
|
-
|
|
497
|
-
hidden: true,
|
|
498
|
-
hotkey: "up",
|
|
499
|
-
id: `${commandScope}:move-up-arrow`,
|
|
500
|
-
modes: ["cursor"],
|
|
501
|
-
title: "Move up",
|
|
502
|
-
when: () => enabled("motions"),
|
|
503
|
-
});
|
|
504
|
-
useCommand({
|
|
505
|
-
handler: () => {
|
|
506
|
-
motion((target) => {
|
|
460
|
+
}),
|
|
461
|
+
motionAction("line-home", "0", "Line home", (target) => {
|
|
507
462
|
target.gotoLineHome();
|
|
508
|
-
})
|
|
509
|
-
|
|
510
|
-
hidden: true,
|
|
511
|
-
hotkey: "0",
|
|
512
|
-
id: `${commandScope}:line-home`,
|
|
513
|
-
modes: ["cursor"],
|
|
514
|
-
title: "Line home",
|
|
515
|
-
when: () => enabled("motions"),
|
|
516
|
-
});
|
|
517
|
-
useCommand({
|
|
518
|
-
handler: () => {
|
|
519
|
-
motion((target) => {
|
|
463
|
+
}),
|
|
464
|
+
motionAction("line-home-key", "home", "Line home", (target) => {
|
|
520
465
|
target.gotoLineHome();
|
|
521
|
-
})
|
|
522
|
-
|
|
523
|
-
hidden: true,
|
|
524
|
-
hotkey: "home",
|
|
525
|
-
id: `${commandScope}:line-home-key`,
|
|
526
|
-
modes: ["cursor"],
|
|
527
|
-
title: "Line home",
|
|
528
|
-
when: () => enabled("motions"),
|
|
529
|
-
});
|
|
530
|
-
useCommand({
|
|
531
|
-
handler: () => {
|
|
532
|
-
motion((target) => {
|
|
466
|
+
}),
|
|
467
|
+
motionAction("line-end", "shift+4", "Line end", (target) => {
|
|
533
468
|
target.gotoLineEnd();
|
|
534
|
-
})
|
|
535
|
-
|
|
536
|
-
hidden: true,
|
|
537
|
-
hotkey: "shift+4",
|
|
538
|
-
id: `${commandScope}:line-end`,
|
|
539
|
-
modes: ["cursor"],
|
|
540
|
-
title: "Line end",
|
|
541
|
-
when: () => enabled("motions"),
|
|
542
|
-
});
|
|
543
|
-
useCommand({
|
|
544
|
-
handler: () => {
|
|
545
|
-
motion((target) => {
|
|
469
|
+
}),
|
|
470
|
+
motionAction("line-end-key", "end", "Line end", (target) => {
|
|
546
471
|
target.gotoLineEnd();
|
|
547
|
-
})
|
|
548
|
-
|
|
549
|
-
hidden: true,
|
|
550
|
-
hotkey: "end",
|
|
551
|
-
id: `${commandScope}:line-end-key`,
|
|
552
|
-
modes: ["cursor"],
|
|
553
|
-
title: "Line end",
|
|
554
|
-
when: () => enabled("motions"),
|
|
555
|
-
});
|
|
556
|
-
useCommand({
|
|
557
|
-
handler: () => {
|
|
558
|
-
motion((target) => {
|
|
472
|
+
}),
|
|
473
|
+
motionAction("word-forward", "w", "Word forward", (target) => {
|
|
559
474
|
target.moveWordForward();
|
|
560
|
-
})
|
|
561
|
-
|
|
562
|
-
hidden: true,
|
|
563
|
-
hotkey: "w",
|
|
564
|
-
id: `${commandScope}:word-forward`,
|
|
565
|
-
modes: ["cursor"],
|
|
566
|
-
title: "Word forward",
|
|
567
|
-
when: () => enabled("motions"),
|
|
568
|
-
});
|
|
569
|
-
useCommand({
|
|
570
|
-
handler: () => {
|
|
571
|
-
motion((target) => {
|
|
475
|
+
}),
|
|
476
|
+
motionAction("word-backward", "b", "Word backward", (target) => {
|
|
572
477
|
target.moveWordBackward();
|
|
573
|
-
})
|
|
574
|
-
|
|
575
|
-
hidden: true,
|
|
576
|
-
hotkey: "b",
|
|
577
|
-
id: `${commandScope}:word-backward`,
|
|
578
|
-
modes: ["cursor"],
|
|
579
|
-
title: "Word backward",
|
|
580
|
-
when: () => enabled("motions"),
|
|
581
|
-
});
|
|
582
|
-
useCommand({
|
|
583
|
-
handler: () => {
|
|
584
|
-
motion((target) => {
|
|
478
|
+
}),
|
|
479
|
+
motionAction("buffer-home", "g g", "Buffer home", (target) => {
|
|
585
480
|
target.gotoBufferHome();
|
|
586
|
-
})
|
|
587
|
-
|
|
588
|
-
hidden: true,
|
|
589
|
-
hotkey: "g g",
|
|
590
|
-
id: `${commandScope}:buffer-home`,
|
|
591
|
-
modes: ["cursor"],
|
|
592
|
-
title: "Buffer home",
|
|
593
|
-
when: () => enabled("motions"),
|
|
594
|
-
});
|
|
595
|
-
useCommand({
|
|
596
|
-
handler: () => {
|
|
597
|
-
motion((target) => {
|
|
481
|
+
}),
|
|
482
|
+
motionAction("buffer-end", "shift+g", "Buffer end", (target) => {
|
|
598
483
|
target.gotoBufferEnd();
|
|
599
|
-
})
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
484
|
+
}),
|
|
485
|
+
];
|
|
486
|
+
return definitions.map(({ group, when, ...definition }) => ({
|
|
487
|
+
...definition,
|
|
488
|
+
when: () => enabled(group) && (when?.() ?? true),
|
|
489
|
+
}));
|
|
490
|
+
}, [
|
|
491
|
+
appendAndEnterInsertMode,
|
|
492
|
+
commandScope,
|
|
493
|
+
copyDocument,
|
|
494
|
+
copyLine,
|
|
495
|
+
copySelection,
|
|
496
|
+
enabled,
|
|
497
|
+
enterInsertMode,
|
|
498
|
+
leaveInsertMode,
|
|
499
|
+
motion,
|
|
500
|
+
multilineRef,
|
|
501
|
+
openLineAbove,
|
|
502
|
+
openLineBelow,
|
|
503
|
+
optionsRef,
|
|
504
|
+
resolveSubmitKey,
|
|
505
|
+
submit,
|
|
506
|
+
]);
|
|
507
|
+
useActions(builtInActions);
|
|
608
508
|
|
|
609
509
|
// Middle-click paste from primary selection
|
|
610
510
|
const handleMouseDown = useCallback(
|
|
@@ -651,7 +551,7 @@ export const useAskEditor = function useAskEditor(
|
|
|
651
551
|
}
|
|
652
552
|
bumpScroll();
|
|
653
553
|
},
|
|
654
|
-
[bumpScroll],
|
|
554
|
+
[bumpScroll, multilineRef],
|
|
655
555
|
);
|
|
656
556
|
|
|
657
557
|
const insertText = useCallback(
|
|
@@ -681,8 +581,7 @@ export const useAskEditor = function useAskEditor(
|
|
|
681
581
|
|
|
682
582
|
// Stable identity so composites can capture it in refs/effects; `mode` reads
|
|
683
583
|
// live through the getter.
|
|
684
|
-
const
|
|
685
|
-
controllerRef.current ??= {
|
|
584
|
+
const controller = useLazyRef<AskEditorController>(() => ({
|
|
686
585
|
getText,
|
|
687
586
|
insertText,
|
|
688
587
|
get mode() {
|
|
@@ -692,10 +591,10 @@ export const useAskEditor = function useAskEditor(
|
|
|
692
591
|
setMode: setModeExternal,
|
|
693
592
|
setText,
|
|
694
593
|
submit,
|
|
695
|
-
};
|
|
594
|
+
})).current;
|
|
696
595
|
|
|
697
596
|
return {
|
|
698
|
-
controller
|
|
597
|
+
controller,
|
|
699
598
|
editor: {
|
|
700
599
|
bumpScroll,
|
|
701
600
|
defaultValue,
|