@tooee/ask 0.2.4 → 0.3.1
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/README.md +2 -2
- package/dist/{AskEditor.d.ts → ask-editor.d.ts} +2 -2
- package/dist/ask-editor.d.ts.map +1 -0
- package/dist/ask-editor.js +26 -0
- package/dist/ask-editor.js.map +1 -0
- package/dist/{AskOverlay.d.ts → ask-overlay.d.ts} +6 -6
- package/dist/ask-overlay.d.ts.map +1 -0
- package/dist/{AskOverlay.js → ask-overlay.js} +11 -10
- package/dist/ask-overlay.js.map +1 -0
- package/dist/{AskPanel.d.ts → ask-panel.d.ts} +5 -5
- package/dist/ask-panel.d.ts.map +1 -0
- package/dist/ask-panel.js +33 -0
- package/dist/ask-panel.js.map +1 -0
- package/dist/{Ask.d.ts → ask.d.ts} +2 -2
- package/dist/ask.d.ts.map +1 -0
- package/dist/{Ask.js → ask.js} +15 -12
- package/dist/ask.js.map +1 -0
- package/dist/{EditorScrollbar.d.ts → editor-scrollbar.d.ts} +2 -2
- package/dist/editor-scrollbar.d.ts.map +1 -0
- package/dist/{EditorScrollbar.js → editor-scrollbar.js} +15 -10
- package/dist/editor-scrollbar.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/launch.d.ts +1 -1
- package/dist/launch.d.ts.map +1 -1
- package/dist/launch.js +5 -4
- package/dist/launch.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/use-ask-dialog.d.ts +4 -4
- package/dist/use-ask-dialog.d.ts.map +1 -1
- package/dist/use-ask-dialog.js +45 -38
- package/dist/use-ask-dialog.js.map +1 -1
- package/dist/use-ask-editor.d.ts +9 -9
- package/dist/use-ask-editor.d.ts.map +1 -1
- package/dist/use-ask-editor.js +211 -138
- package/dist/use-ask-editor.js.map +1 -1
- package/dist/vim-motions.d.ts +3 -3
- package/dist/vim-motions.d.ts.map +1 -1
- package/dist/vim-motions.js +73 -44
- package/dist/vim-motions.js.map +1 -1
- package/package.json +8 -8
- package/src/{AskEditor.tsx → ask-editor.tsx} +30 -23
- package/src/ask-overlay.tsx +80 -0
- package/src/{AskPanel.tsx → ask-panel.tsx} +49 -41
- package/src/{Ask.tsx → ask.tsx} +48 -45
- package/src/{EditorScrollbar.tsx → editor-scrollbar.tsx} +40 -28
- package/src/index.ts +17 -17
- package/src/launch.tsx +11 -10
- package/src/types.ts +5 -5
- package/src/use-ask-dialog.tsx +102 -90
- package/src/use-ask-editor.ts +377 -292
- package/src/vim-motions.ts +110 -71
- package/dist/Ask.d.ts.map +0 -1
- package/dist/Ask.js.map +0 -1
- package/dist/AskEditor.d.ts.map +0 -1
- package/dist/AskEditor.js +0 -19
- package/dist/AskEditor.js.map +0 -1
- package/dist/AskOverlay.d.ts.map +0 -1
- package/dist/AskOverlay.js.map +0 -1
- package/dist/AskPanel.d.ts.map +0 -1
- package/dist/AskPanel.js +0 -25
- package/dist/AskPanel.js.map +0 -1
- package/dist/EditorScrollbar.d.ts.map +0 -1
- package/dist/EditorScrollbar.js.map +0 -1
- package/src/AskOverlay.tsx +0 -75
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-ask-dialog.js","sourceRoot":"","sources":["../src/use-ask-dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"use-ask-dialog.js","sourceRoot":"","sources":["../src/use-ask-dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG1C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9C;;;;;GAKG;AACH,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAiC1B;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC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O;gBACb,WAAW,EAAE,QAAQ;aACtB,CACF,CAAC;YACF,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YACvC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;YAC7B,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;IAEF,OAAO,SAAS,CAAC,OAAO,CAAC;AAC3B,CAAC,CAAC"}
|
package/dist/use-ask-editor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { InputRenderable, KeyEvent, MouseEvent, PasteEvent, TextareaRenderable } from "@opentui/core";
|
|
2
|
-
import {
|
|
2
|
+
import type { Mode } from "@tooee/commands";
|
|
3
3
|
declare module "@tooee/commands" {
|
|
4
4
|
interface CommandContext {
|
|
5
5
|
/** Contributed by ask editors: the current input value. */
|
|
@@ -35,19 +35,19 @@ export interface UseAskEditorOptions {
|
|
|
35
35
|
/** Programmatic text control for composites (dictation, prefill, transforms). */
|
|
36
36
|
export interface AskEditorController {
|
|
37
37
|
/** Current text (works for input and textarea). */
|
|
38
|
-
getText()
|
|
38
|
+
getText: () => string;
|
|
39
39
|
/** Replace the buffer; optionally move cursor to end (default true). */
|
|
40
|
-
setText(text: string, opts?: {
|
|
40
|
+
setText: (text: string, opts?: {
|
|
41
41
|
cursorToEnd?: boolean;
|
|
42
|
-
})
|
|
42
|
+
}) => void;
|
|
43
43
|
/** Insert at the cursor position. */
|
|
44
|
-
insertText(text: string)
|
|
45
|
-
setCursorToEnd()
|
|
46
|
-
submit()
|
|
44
|
+
insertText: (text: string) => void;
|
|
45
|
+
setCursorToEnd: () => void;
|
|
46
|
+
submit: () => void;
|
|
47
47
|
/** Current local mode (live read). */
|
|
48
48
|
readonly mode: Mode;
|
|
49
49
|
/** Switch insert/cursor mode; resets any pending vim motion state. */
|
|
50
|
-
setMode(mode: Mode)
|
|
50
|
+
setMode: (mode: Mode) => void;
|
|
51
51
|
}
|
|
52
52
|
/** Everything `<AskEditor/>` needs: refs, focus, mode, handlers. */
|
|
53
53
|
export interface AskEditorViewModel {
|
|
@@ -89,5 +89,5 @@ export interface UseAskEditorResult {
|
|
|
89
89
|
* command surface, so it works identically at the app root, inside an
|
|
90
90
|
* `ownCommands` overlay, or under any `CommandSurfaceProvider`.
|
|
91
91
|
*/
|
|
92
|
-
export declare
|
|
92
|
+
export declare const useAskEditor: (options?: UseAskEditorOptions) => UseAskEditorResult;
|
|
93
93
|
//# sourceMappingURL=use-ask-editor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-ask-editor.d.ts","sourceRoot":"","sources":["../src/use-ask-editor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,UAAU,EACV,UAAU,EACV,kBAAkB,EACnB,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"use-ask-editor.d.ts","sourceRoot":"","sources":["../src/use-ask-editor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,UAAU,EACV,UAAU,EACV,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAUvB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,QAAQ,iBAAiB,CAAC;IAC/B,UAAU,cAAc;QACtB,2DAA2D;QAC3D,GAAG,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;KACxB;CACF;AAED,2EAA2E;AAC3E,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,iBAAiB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnG,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,aAAa,GAAG,MAAM,CAAC;AAE5D,MAAM,WAAW,mBAAmB;IAClC,uFAAuF;IACvF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,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EAAE;QAAE,OAAO,EAAE,eAAe,GAAG,IAAI,CAAA;KAAE,CAAC;IAC9C,iDAAiD;IACjD,IAAI,EAAE,IAAI,CAAC;IACX,6EAA6E;IAC7E,SAAS,EAAE,OAAO,CAAC;IACnB,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,kFAAkF;IAClF,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,4EAA4E;IAC5E,eAAe,EAAE,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,KAAK,IAAI,CAAC;IACxD,aAAa,EAAE,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,KAAK,IAAI,CAAC;IACtD,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,uFAAuF;IACvF,WAAW,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,mBAAmB,CAAC;IAChC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GACvB,UAAS,mBAAwB,KAChC,kBAmhBF,CAAC"}
|
package/dist/use-ask-editor.js
CHANGED
|
@@ -8,7 +8,7 @@ import { appendAtCursor, openLineAtCursor } from "./vim-motions.js";
|
|
|
8
8
|
* command surface, so it works identically at the app root, inside an
|
|
9
9
|
* `ownCommands` overlay, or under any `CommandSurfaceProvider`.
|
|
10
10
|
*/
|
|
11
|
-
export function useAskEditor(options = {}) {
|
|
11
|
+
export const useAskEditor = function useAskEditor(options = {}) {
|
|
12
12
|
const { multiline = false, defaultValue, placeholder, commandScope = "ask" } = options;
|
|
13
13
|
const mode = useMode();
|
|
14
14
|
const setMode = useSetMode();
|
|
@@ -20,7 +20,9 @@ export function useAskEditor(options = {}) {
|
|
|
20
20
|
// Bumped whenever the editor viewport may have moved (cursor, content, wheel)
|
|
21
21
|
// so the scrollbar thumb re-computes from the editor's internal scroll state.
|
|
22
22
|
const [scrollRevision, setScrollRevision] = useState(0);
|
|
23
|
-
const bumpScroll = useCallback(() =>
|
|
23
|
+
const bumpScroll = useCallback(() => {
|
|
24
|
+
setScrollRevision((r) => r + 1);
|
|
25
|
+
}, []);
|
|
24
26
|
const optionsRef = useRef(options);
|
|
25
27
|
optionsRef.current = options;
|
|
26
28
|
const modeRef = useRef(mode);
|
|
@@ -37,15 +39,18 @@ export function useAskEditor(options = {}) {
|
|
|
37
39
|
const suspended = (options.suspended ?? false) || (activeSurface !== null && activeSurface.id !== surfaceId);
|
|
38
40
|
const focused = (mode === "insert" || mode === "cursor") && !suspended;
|
|
39
41
|
const preventCursorModeEditorInput = useCallback((event) => {
|
|
40
|
-
if (modeRef.current === "cursor")
|
|
42
|
+
if (modeRef.current === "cursor") {
|
|
41
43
|
event.preventDefault();
|
|
44
|
+
}
|
|
42
45
|
}, []);
|
|
43
46
|
useEffect(() => {
|
|
44
|
-
if (didPositionInitialCursorRef.current ||
|
|
47
|
+
if (didPositionInitialCursorRef.current || (defaultValue?.length ?? 0) === 0) {
|
|
45
48
|
return;
|
|
49
|
+
}
|
|
46
50
|
const target = multiline ? textareaRef.current : inputRef.current;
|
|
47
|
-
if (!target)
|
|
51
|
+
if (!target) {
|
|
48
52
|
return;
|
|
53
|
+
}
|
|
49
54
|
target.cursorOffset = target.plainText.length;
|
|
50
55
|
didPositionInitialCursorRef.current = true;
|
|
51
56
|
}, [defaultValue, multiline]);
|
|
@@ -54,19 +59,18 @@ export function useAskEditor(options = {}) {
|
|
|
54
59
|
bumpScroll();
|
|
55
60
|
}, [bumpScroll]);
|
|
56
61
|
const getTarget = useCallback(() => (multilineRef.current ? textareaRef.current : inputRef.current), []);
|
|
62
|
+
// Controller mutations must be observable before React state synchronizes.
|
|
57
63
|
const getText = useCallback(() => multilineRef.current
|
|
58
64
|
? (textareaRef.current?.plainText ?? "")
|
|
59
|
-
:
|
|
60
|
-
// must be visible before React state re-syncs on the next render.
|
|
61
|
-
(inputRef.current?.plainText ?? valueRef.current), []);
|
|
65
|
+
: (inputRef.current?.plainText ?? valueRef.current), []);
|
|
62
66
|
const submit = useCallback(() => {
|
|
63
67
|
void optionsRef.current.onSubmit?.(getText());
|
|
64
68
|
}, [getText]);
|
|
65
69
|
useProvideCommandContext(() => ({ ask: { value: getText() } }));
|
|
66
70
|
const enabled = useCallback((group) => !(optionsRef.current.disable?.includes(group) ?? false), []);
|
|
67
71
|
const resolveSubmitKey = useCallback(() => {
|
|
68
|
-
const current = optionsRef
|
|
69
|
-
return current.submitKey ?? (current.multiline ? "shift+enter" : "enter");
|
|
72
|
+
const { current } = optionsRef;
|
|
73
|
+
return current.submitKey ?? (current.multiline === true ? "shift+enter" : "enter");
|
|
70
74
|
}, []);
|
|
71
75
|
const enterInsertMode = useCallback(() => {
|
|
72
76
|
vimMotionStateRef.current.pendingG = false;
|
|
@@ -78,15 +82,17 @@ export function useAskEditor(options = {}) {
|
|
|
78
82
|
setMode("insert");
|
|
79
83
|
}, [getTarget, setMode]);
|
|
80
84
|
const openLineAbove = useCallback(() => {
|
|
81
|
-
if (!multilineRef.current)
|
|
85
|
+
if (!multilineRef.current) {
|
|
82
86
|
return;
|
|
87
|
+
}
|
|
83
88
|
vimMotionStateRef.current.pendingG = false;
|
|
84
89
|
openLineAtCursor(textareaRef.current, "above");
|
|
85
90
|
setMode("insert");
|
|
86
91
|
}, [setMode]);
|
|
87
92
|
const openLineBelow = useCallback(() => {
|
|
88
|
-
if (!multilineRef.current)
|
|
93
|
+
if (!multilineRef.current) {
|
|
89
94
|
return;
|
|
95
|
+
}
|
|
90
96
|
vimMotionStateRef.current.pendingG = false;
|
|
91
97
|
openLineAtCursor(textareaRef.current, "below");
|
|
92
98
|
setMode("insert");
|
|
@@ -96,247 +102,315 @@ export function useAskEditor(options = {}) {
|
|
|
96
102
|
setMode("cursor");
|
|
97
103
|
}, [setMode]);
|
|
98
104
|
useCommand({
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
handler: leaveInsertMode,
|
|
106
|
+
hidden: true,
|
|
101
107
|
hotkey: "Escape",
|
|
108
|
+
id: `${commandScope}:leave-insert-mode`,
|
|
102
109
|
modes: ["insert"],
|
|
103
|
-
|
|
110
|
+
title: "Command mode",
|
|
104
111
|
when: () => enabled("escape"),
|
|
105
|
-
handler: leaveInsertMode,
|
|
106
112
|
});
|
|
107
113
|
useCommand({
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
handler: () => optionsRef.current.onCancel?.(),
|
|
115
|
+
hidden: true,
|
|
110
116
|
hotkey: "q",
|
|
117
|
+
id: `${commandScope}:cancel`,
|
|
111
118
|
modes: ["cursor"],
|
|
112
|
-
|
|
119
|
+
title: "Cancel",
|
|
113
120
|
when: () => enabled("cancel") && optionsRef.current.onCancel !== undefined,
|
|
114
|
-
handler: () => optionsRef.current.onCancel?.(),
|
|
115
121
|
});
|
|
116
122
|
useCommand({
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
handler: enterInsertMode,
|
|
124
|
+
hidden: true,
|
|
119
125
|
hotkey: "i",
|
|
126
|
+
id: `${commandScope}:insert-mode-i`,
|
|
120
127
|
modes: ["cursor"],
|
|
121
|
-
|
|
128
|
+
title: "Insert mode",
|
|
122
129
|
when: () => enabled("insert-commands"),
|
|
123
|
-
handler: enterInsertMode,
|
|
124
130
|
});
|
|
125
131
|
useCommand({
|
|
126
|
-
|
|
127
|
-
|
|
132
|
+
handler: appendAndEnterInsertMode,
|
|
133
|
+
hidden: true,
|
|
128
134
|
hotkey: "a",
|
|
135
|
+
id: `${commandScope}:insert-mode-a`,
|
|
129
136
|
modes: ["cursor"],
|
|
130
|
-
|
|
137
|
+
title: "Append",
|
|
131
138
|
when: () => enabled("insert-commands"),
|
|
132
|
-
handler: appendAndEnterInsertMode,
|
|
133
139
|
});
|
|
134
140
|
useCommand({
|
|
135
|
-
|
|
136
|
-
|
|
141
|
+
handler: openLineAbove,
|
|
142
|
+
hidden: true,
|
|
137
143
|
hotkey: "shift+o",
|
|
144
|
+
id: `${commandScope}:open-line-above`,
|
|
138
145
|
modes: ["cursor"],
|
|
139
|
-
|
|
146
|
+
title: "Open line above",
|
|
140
147
|
when: () => enabled("insert-commands") && multilineRef.current,
|
|
141
|
-
handler: openLineAbove,
|
|
142
148
|
});
|
|
143
149
|
useCommand({
|
|
144
|
-
|
|
145
|
-
|
|
150
|
+
handler: openLineBelow,
|
|
151
|
+
hidden: true,
|
|
146
152
|
hotkey: "o",
|
|
153
|
+
id: `${commandScope}:open-line-below`,
|
|
147
154
|
modes: ["cursor"],
|
|
148
|
-
|
|
155
|
+
title: "Open line below",
|
|
149
156
|
when: () => enabled("insert-commands") && multilineRef.current,
|
|
150
|
-
handler: openLineBelow,
|
|
151
157
|
});
|
|
152
158
|
useCommand({
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
handler: submit,
|
|
160
|
+
hidden: true,
|
|
155
161
|
hotkey: "Enter",
|
|
162
|
+
id: `${commandScope}:submit-single-line`,
|
|
156
163
|
modes: ["insert", "cursor"],
|
|
157
|
-
|
|
164
|
+
title: "Submit",
|
|
158
165
|
when: () => enabled("submit") && resolveSubmitKey() === "enter",
|
|
159
|
-
handler: submit,
|
|
160
166
|
});
|
|
161
167
|
useCommand({
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
handler: submit,
|
|
169
|
+
hidden: true,
|
|
164
170
|
hotkey: "shift+Enter",
|
|
171
|
+
id: `${commandScope}:submit-multiline`,
|
|
165
172
|
modes: ["insert", "cursor"],
|
|
166
|
-
|
|
173
|
+
title: "Submit",
|
|
167
174
|
// Shift+Enter always submits (single-line editors have no newline for it
|
|
168
175
|
// to mean); plain Enter only when it is the configured submit key.
|
|
169
176
|
when: () => enabled("submit") && resolveSubmitKey() !== "none",
|
|
170
|
-
handler: submit,
|
|
171
177
|
});
|
|
172
178
|
const motion = useCallback((run) => {
|
|
173
179
|
const target = getTarget();
|
|
174
|
-
if (target)
|
|
180
|
+
if (target) {
|
|
175
181
|
run(target);
|
|
182
|
+
}
|
|
176
183
|
vimMotionStateRef.current.pendingG = false;
|
|
177
184
|
bumpScroll();
|
|
178
185
|
}, [getTarget, bumpScroll]);
|
|
179
186
|
useCommand({
|
|
180
|
-
|
|
181
|
-
|
|
187
|
+
handler: () => {
|
|
188
|
+
motion((target) => {
|
|
189
|
+
target.moveCursorLeft();
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
hidden: true,
|
|
182
193
|
hotkey: "h",
|
|
194
|
+
id: `${commandScope}:move-left`,
|
|
183
195
|
modes: ["cursor"],
|
|
184
|
-
|
|
196
|
+
title: "Move left",
|
|
185
197
|
when: () => enabled("motions"),
|
|
186
|
-
handler: () => motion((target) => target.moveCursorLeft()),
|
|
187
198
|
});
|
|
188
199
|
useCommand({
|
|
189
|
-
|
|
190
|
-
|
|
200
|
+
handler: () => {
|
|
201
|
+
motion((target) => {
|
|
202
|
+
target.moveCursorLeft();
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
hidden: true,
|
|
191
206
|
hotkey: "left",
|
|
207
|
+
id: `${commandScope}:move-left-arrow`,
|
|
192
208
|
modes: ["cursor"],
|
|
193
|
-
|
|
209
|
+
title: "Move left",
|
|
194
210
|
when: () => enabled("motions"),
|
|
195
|
-
handler: () => motion((target) => target.moveCursorLeft()),
|
|
196
211
|
});
|
|
197
212
|
useCommand({
|
|
198
|
-
|
|
199
|
-
|
|
213
|
+
handler: () => {
|
|
214
|
+
motion((target) => {
|
|
215
|
+
target.moveCursorRight();
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
hidden: true,
|
|
200
219
|
hotkey: "l",
|
|
220
|
+
id: `${commandScope}:move-right`,
|
|
201
221
|
modes: ["cursor"],
|
|
202
|
-
|
|
222
|
+
title: "Move right",
|
|
203
223
|
when: () => enabled("motions"),
|
|
204
|
-
handler: () => motion((target) => target.moveCursorRight()),
|
|
205
224
|
});
|
|
206
225
|
useCommand({
|
|
207
|
-
|
|
208
|
-
|
|
226
|
+
handler: () => {
|
|
227
|
+
motion((target) => {
|
|
228
|
+
target.moveCursorRight();
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
hidden: true,
|
|
209
232
|
hotkey: "right",
|
|
233
|
+
id: `${commandScope}:move-right-arrow`,
|
|
210
234
|
modes: ["cursor"],
|
|
211
|
-
|
|
235
|
+
title: "Move right",
|
|
212
236
|
when: () => enabled("motions"),
|
|
213
|
-
handler: () => motion((target) => target.moveCursorRight()),
|
|
214
237
|
});
|
|
215
238
|
useCommand({
|
|
216
|
-
|
|
217
|
-
|
|
239
|
+
handler: () => {
|
|
240
|
+
motion((target) => {
|
|
241
|
+
target.moveCursorDown();
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
hidden: true,
|
|
218
245
|
hotkey: "j",
|
|
246
|
+
id: `${commandScope}:move-down`,
|
|
219
247
|
modes: ["cursor"],
|
|
220
|
-
|
|
248
|
+
title: "Move down",
|
|
221
249
|
when: () => enabled("motions"),
|
|
222
|
-
handler: () => motion((target) => target.moveCursorDown()),
|
|
223
250
|
});
|
|
224
251
|
useCommand({
|
|
225
|
-
|
|
226
|
-
|
|
252
|
+
handler: () => {
|
|
253
|
+
motion((target) => {
|
|
254
|
+
target.moveCursorDown();
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
hidden: true,
|
|
227
258
|
hotkey: "down",
|
|
259
|
+
id: `${commandScope}:move-down-arrow`,
|
|
228
260
|
modes: ["cursor"],
|
|
229
|
-
|
|
261
|
+
title: "Move down",
|
|
230
262
|
when: () => enabled("motions"),
|
|
231
|
-
handler: () => motion((target) => target.moveCursorDown()),
|
|
232
263
|
});
|
|
233
264
|
useCommand({
|
|
234
|
-
|
|
235
|
-
|
|
265
|
+
handler: () => {
|
|
266
|
+
motion((target) => {
|
|
267
|
+
target.moveCursorUp();
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
hidden: true,
|
|
236
271
|
hotkey: "k",
|
|
272
|
+
id: `${commandScope}:move-up`,
|
|
237
273
|
modes: ["cursor"],
|
|
238
|
-
|
|
274
|
+
title: "Move up",
|
|
239
275
|
when: () => enabled("motions"),
|
|
240
|
-
handler: () => motion((target) => target.moveCursorUp()),
|
|
241
276
|
});
|
|
242
277
|
useCommand({
|
|
243
|
-
|
|
244
|
-
|
|
278
|
+
handler: () => {
|
|
279
|
+
motion((target) => {
|
|
280
|
+
target.moveCursorUp();
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
hidden: true,
|
|
245
284
|
hotkey: "up",
|
|
285
|
+
id: `${commandScope}:move-up-arrow`,
|
|
246
286
|
modes: ["cursor"],
|
|
247
|
-
|
|
287
|
+
title: "Move up",
|
|
248
288
|
when: () => enabled("motions"),
|
|
249
|
-
handler: () => motion((target) => target.moveCursorUp()),
|
|
250
289
|
});
|
|
251
290
|
useCommand({
|
|
252
|
-
|
|
253
|
-
|
|
291
|
+
handler: () => {
|
|
292
|
+
motion((target) => {
|
|
293
|
+
target.gotoLineHome();
|
|
294
|
+
});
|
|
295
|
+
},
|
|
296
|
+
hidden: true,
|
|
254
297
|
hotkey: "0",
|
|
298
|
+
id: `${commandScope}:line-home`,
|
|
255
299
|
modes: ["cursor"],
|
|
256
|
-
|
|
300
|
+
title: "Line home",
|
|
257
301
|
when: () => enabled("motions"),
|
|
258
|
-
handler: () => motion((target) => target.gotoLineHome()),
|
|
259
302
|
});
|
|
260
303
|
useCommand({
|
|
261
|
-
|
|
262
|
-
|
|
304
|
+
handler: () => {
|
|
305
|
+
motion((target) => {
|
|
306
|
+
target.gotoLineHome();
|
|
307
|
+
});
|
|
308
|
+
},
|
|
309
|
+
hidden: true,
|
|
263
310
|
hotkey: "home",
|
|
311
|
+
id: `${commandScope}:line-home-key`,
|
|
264
312
|
modes: ["cursor"],
|
|
265
|
-
|
|
313
|
+
title: "Line home",
|
|
266
314
|
when: () => enabled("motions"),
|
|
267
|
-
handler: () => motion((target) => target.gotoLineHome()),
|
|
268
315
|
});
|
|
269
316
|
useCommand({
|
|
270
|
-
|
|
271
|
-
|
|
317
|
+
handler: () => {
|
|
318
|
+
motion((target) => {
|
|
319
|
+
target.gotoLineEnd();
|
|
320
|
+
});
|
|
321
|
+
},
|
|
322
|
+
hidden: true,
|
|
272
323
|
hotkey: "shift+4",
|
|
324
|
+
id: `${commandScope}:line-end`,
|
|
273
325
|
modes: ["cursor"],
|
|
274
|
-
|
|
326
|
+
title: "Line end",
|
|
275
327
|
when: () => enabled("motions"),
|
|
276
|
-
handler: () => motion((target) => target.gotoLineEnd()),
|
|
277
328
|
});
|
|
278
329
|
useCommand({
|
|
279
|
-
|
|
280
|
-
|
|
330
|
+
handler: () => {
|
|
331
|
+
motion((target) => {
|
|
332
|
+
target.gotoLineEnd();
|
|
333
|
+
});
|
|
334
|
+
},
|
|
335
|
+
hidden: true,
|
|
281
336
|
hotkey: "end",
|
|
337
|
+
id: `${commandScope}:line-end-key`,
|
|
282
338
|
modes: ["cursor"],
|
|
283
|
-
|
|
339
|
+
title: "Line end",
|
|
284
340
|
when: () => enabled("motions"),
|
|
285
|
-
handler: () => motion((target) => target.gotoLineEnd()),
|
|
286
341
|
});
|
|
287
342
|
useCommand({
|
|
288
|
-
|
|
289
|
-
|
|
343
|
+
handler: () => {
|
|
344
|
+
motion((target) => {
|
|
345
|
+
target.moveWordForward();
|
|
346
|
+
});
|
|
347
|
+
},
|
|
348
|
+
hidden: true,
|
|
290
349
|
hotkey: "w",
|
|
350
|
+
id: `${commandScope}:word-forward`,
|
|
291
351
|
modes: ["cursor"],
|
|
292
|
-
|
|
352
|
+
title: "Word forward",
|
|
293
353
|
when: () => enabled("motions"),
|
|
294
|
-
handler: () => motion((target) => target.moveWordForward()),
|
|
295
354
|
});
|
|
296
355
|
useCommand({
|
|
297
|
-
|
|
298
|
-
|
|
356
|
+
handler: () => {
|
|
357
|
+
motion((target) => {
|
|
358
|
+
target.moveWordBackward();
|
|
359
|
+
});
|
|
360
|
+
},
|
|
361
|
+
hidden: true,
|
|
299
362
|
hotkey: "b",
|
|
363
|
+
id: `${commandScope}:word-backward`,
|
|
300
364
|
modes: ["cursor"],
|
|
301
|
-
|
|
365
|
+
title: "Word backward",
|
|
302
366
|
when: () => enabled("motions"),
|
|
303
|
-
handler: () => motion((target) => target.moveWordBackward()),
|
|
304
367
|
});
|
|
305
368
|
useCommand({
|
|
306
|
-
|
|
307
|
-
|
|
369
|
+
handler: () => {
|
|
370
|
+
motion((target) => {
|
|
371
|
+
target.gotoBufferHome();
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
hidden: true,
|
|
308
375
|
hotkey: "g g",
|
|
376
|
+
id: `${commandScope}:buffer-home`,
|
|
309
377
|
modes: ["cursor"],
|
|
310
|
-
|
|
378
|
+
title: "Buffer home",
|
|
311
379
|
when: () => enabled("motions"),
|
|
312
|
-
handler: () => motion((target) => target.gotoBufferHome()),
|
|
313
380
|
});
|
|
314
381
|
useCommand({
|
|
315
|
-
|
|
316
|
-
|
|
382
|
+
handler: () => {
|
|
383
|
+
motion((target) => {
|
|
384
|
+
target.gotoBufferEnd();
|
|
385
|
+
});
|
|
386
|
+
},
|
|
387
|
+
hidden: true,
|
|
317
388
|
hotkey: "shift+g",
|
|
389
|
+
id: `${commandScope}:buffer-end`,
|
|
318
390
|
modes: ["cursor"],
|
|
319
|
-
|
|
391
|
+
title: "Buffer end",
|
|
320
392
|
when: () => enabled("motions"),
|
|
321
|
-
handler: () => motion((target) => target.gotoBufferEnd()),
|
|
322
393
|
});
|
|
323
394
|
// Middle-click paste from primary selection
|
|
324
395
|
const handleMouseDown = useCallback((event) => {
|
|
325
396
|
if (event.button === 1) {
|
|
326
397
|
event.preventDefault();
|
|
327
|
-
void
|
|
328
|
-
|
|
398
|
+
void (async () => {
|
|
399
|
+
const text = await readPrimaryText();
|
|
400
|
+
if (text === undefined || text === "") {
|
|
329
401
|
return;
|
|
402
|
+
}
|
|
330
403
|
getTarget()?.insertText(text);
|
|
331
|
-
});
|
|
404
|
+
})();
|
|
332
405
|
}
|
|
333
406
|
}, [getTarget]);
|
|
334
407
|
const setText = useCallback((text, opts) => {
|
|
335
408
|
const cursorToEnd = opts?.cursorToEnd ?? true;
|
|
336
409
|
if (multilineRef.current) {
|
|
337
410
|
const target = textareaRef.current;
|
|
338
|
-
if (!target)
|
|
411
|
+
if (!target) {
|
|
339
412
|
return;
|
|
413
|
+
}
|
|
340
414
|
const prevOffset = target.cursorOffset;
|
|
341
415
|
target.replaceText(text);
|
|
342
416
|
target.cursorOffset = cursorToEnd
|
|
@@ -364,8 +438,9 @@ export function useAskEditor(options = {}) {
|
|
|
364
438
|
}, [getTarget, bumpScroll]);
|
|
365
439
|
const setCursorToEnd = useCallback(() => {
|
|
366
440
|
const target = getTarget();
|
|
367
|
-
if (!target)
|
|
441
|
+
if (!target) {
|
|
368
442
|
return;
|
|
443
|
+
}
|
|
369
444
|
target.cursorOffset = target.plainText.length;
|
|
370
445
|
bumpScroll();
|
|
371
446
|
}, [getTarget, bumpScroll]);
|
|
@@ -376,39 +451,37 @@ export function useAskEditor(options = {}) {
|
|
|
376
451
|
// Stable identity so composites can capture it in refs/effects; `mode` reads
|
|
377
452
|
// live through the getter.
|
|
378
453
|
const controllerRef = useRef(null);
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
};
|
|
391
|
-
}
|
|
454
|
+
controllerRef.current ??= {
|
|
455
|
+
getText,
|
|
456
|
+
insertText,
|
|
457
|
+
get mode() {
|
|
458
|
+
return modeRef.current;
|
|
459
|
+
},
|
|
460
|
+
setCursorToEnd,
|
|
461
|
+
setMode: setModeExternal,
|
|
462
|
+
setText,
|
|
463
|
+
submit,
|
|
464
|
+
};
|
|
392
465
|
return {
|
|
393
466
|
controller: controllerRef.current,
|
|
394
467
|
editor: {
|
|
395
|
-
|
|
468
|
+
bumpScroll,
|
|
396
469
|
defaultValue,
|
|
397
|
-
|
|
398
|
-
value,
|
|
399
|
-
onInput: setValue,
|
|
400
|
-
textareaRef,
|
|
470
|
+
focused,
|
|
401
471
|
inputRef,
|
|
402
472
|
mode,
|
|
403
|
-
|
|
404
|
-
focused,
|
|
405
|
-
scrollRevision,
|
|
406
|
-
bumpScroll,
|
|
473
|
+
multiline,
|
|
407
474
|
onEditorKeyDown: preventCursorModeEditorInput,
|
|
408
475
|
onEditorPaste: preventCursorModeEditorInput,
|
|
409
|
-
|
|
476
|
+
onInput: setValue,
|
|
410
477
|
onMouseDown: handleMouseDown,
|
|
478
|
+
placeholder,
|
|
479
|
+
scrollRevision,
|
|
480
|
+
submit,
|
|
481
|
+
suspended,
|
|
482
|
+
textareaRef,
|
|
483
|
+
value,
|
|
411
484
|
},
|
|
412
485
|
};
|
|
413
|
-
}
|
|
486
|
+
};
|
|
414
487
|
//# sourceMappingURL=use-ask-editor.js.map
|