@miphamai/cli 0.79.0 → 0.79.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/package.json +1 -1
- package/src/shared/package-info.ts +1 -1
- package/src/ui/input.tsx +74 -33
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
export const PACKAGE_NAME = '@miphamai/cli' as const
|
|
10
10
|
|
|
11
11
|
/** 当前发布版本 */
|
|
12
|
-
export const PACKAGE_VERSION = '0.79.
|
|
12
|
+
export const PACKAGE_VERSION = '0.79.1' as const
|
|
13
13
|
|
|
14
14
|
/** npm install 全局安装命令 */
|
|
15
15
|
export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` as const
|
package/src/ui/input.tsx
CHANGED
|
@@ -130,6 +130,64 @@ export function applyEdit(state: EditState, action: EditAction): EditState {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Map an Ink key object + raw input to a cursor-editing action (null when the key
|
|
135
|
+
* isn't an edit). Extracted from the MiphamTextInput useInput handler so the macOS
|
|
136
|
+
* Backspace quirk is unit-testable.
|
|
137
|
+
*
|
|
138
|
+
* Ink 5.2.1 parses the macOS Backspace key (terminal sends \x7f) as `key.delete`,
|
|
139
|
+
* NOT `key.backspace` (that's \x08). So both must map to a backward delete; the
|
|
140
|
+
* true forward-Delete key (\x1b[3~) is also parsed as `key.delete` by Ink and is
|
|
141
|
+
* rare, so it deliberately stays backward-delete too.
|
|
142
|
+
*/
|
|
143
|
+
export function keyToEditAction(
|
|
144
|
+
key: { leftArrow?: boolean; rightArrow?: boolean; backspace?: boolean; delete?: boolean },
|
|
145
|
+
input: string,
|
|
146
|
+
): EditAction | null {
|
|
147
|
+
if (key.leftArrow) return { type: 'moveLeft' }
|
|
148
|
+
if (key.rightArrow) return { type: 'moveRight' }
|
|
149
|
+
if (key.backspace || key.delete) return { type: 'backspace' }
|
|
150
|
+
const cleaned = normalizeInput(input)
|
|
151
|
+
if (cleaned) return { type: 'insert', text: cleaned }
|
|
152
|
+
return null
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Browsing state for arrow-key history navigation. */
|
|
156
|
+
export interface HistoryNavState {
|
|
157
|
+
history: string[]
|
|
158
|
+
index: number // -1 = not browsing
|
|
159
|
+
savedDraft: string // draft saved on first up-arrow
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Pure history-navigation transition. Returns the value to display plus the
|
|
164
|
+
* updated browsing state, or null when the key is a no-op (empty history for up,
|
|
165
|
+
* or not browsing for down).
|
|
166
|
+
*/
|
|
167
|
+
export function navigateHistory(
|
|
168
|
+
state: HistoryNavState,
|
|
169
|
+
dir: 'up' | 'down',
|
|
170
|
+
draft: string,
|
|
171
|
+
): { index: number; savedDraft: string; value: string } | null {
|
|
172
|
+
if (dir === 'up') {
|
|
173
|
+
if (state.history.length === 0) return null
|
|
174
|
+
const savedDraft = state.index === -1 ? draft : state.savedDraft
|
|
175
|
+
const index = Math.min(state.index + 1, state.history.length - 1)
|
|
176
|
+
return { index, savedDraft, value: state.history[state.history.length - 1 - index]! }
|
|
177
|
+
}
|
|
178
|
+
// down
|
|
179
|
+
if (state.index === -1) return null
|
|
180
|
+
const index = state.index - 1
|
|
181
|
+
if (index === -1) {
|
|
182
|
+
return { index, savedDraft: '', value: state.savedDraft }
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
index,
|
|
186
|
+
savedDraft: state.savedDraft,
|
|
187
|
+
value: state.history[state.history.length - 1 - index]!,
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
133
191
|
/** True when typing a leading `/` should auto-open the slash-command picker. */
|
|
134
192
|
export function shouldAutoOpenPicker(value: string, prevValue: string, enabled: boolean): boolean {
|
|
135
193
|
return enabled && value.startsWith('/') && !prevValue.startsWith('/')
|
|
@@ -188,16 +246,10 @@ function MiphamTextInput({
|
|
|
188
246
|
}
|
|
189
247
|
|
|
190
248
|
// 把按键归一化为一次光标编辑:左/右移动,退格/删除,或光标处插入(打字/粘贴)。
|
|
249
|
+
// macOS Backspace 发 \x7f,被 Ink 映射成 key.delete(非 key.backspace),
|
|
250
|
+
// 故 keyToEditAction 里两者都按向后删处理。
|
|
191
251
|
const state: EditState = { value: valueRef.current, cursor: cursorRef.current }
|
|
192
|
-
|
|
193
|
-
if (key.leftArrow) action = { type: 'moveLeft' }
|
|
194
|
-
else if (key.rightArrow) action = { type: 'moveRight' }
|
|
195
|
-
else if (key.backspace) action = { type: 'backspace' }
|
|
196
|
-
else if (key.delete) action = { type: 'delete' }
|
|
197
|
-
else {
|
|
198
|
-
const cleaned = normalizeInput(input)
|
|
199
|
-
if (cleaned) action = { type: 'insert', text: cleaned }
|
|
200
|
-
}
|
|
252
|
+
const action = keyToEditAction(key, input)
|
|
201
253
|
if (!action) return
|
|
202
254
|
|
|
203
255
|
const next = applyEdit(state, action)
|
|
@@ -379,30 +431,19 @@ export function InputBar({
|
|
|
379
431
|
// Ignore if picker is active (command picker handles its own arrows)
|
|
380
432
|
if (value.startsWith('/')) return
|
|
381
433
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (historyIndexRef.current === -1) return
|
|
396
|
-
const newIndex = historyIndexRef.current - 1
|
|
397
|
-
historyIndexRef.current = newIndex
|
|
398
|
-
if (newIndex === -1) {
|
|
399
|
-
// Back to the original draft
|
|
400
|
-
setValue(savedDraftRef.current)
|
|
401
|
-
savedDraftRef.current = ''
|
|
402
|
-
} else {
|
|
403
|
-
setValue(submittedHistory[submittedHistory.length - 1 - newIndex]!)
|
|
404
|
-
}
|
|
405
|
-
return
|
|
434
|
+
const result = navigateHistory(
|
|
435
|
+
{
|
|
436
|
+
history: submittedHistory,
|
|
437
|
+
index: historyIndexRef.current,
|
|
438
|
+
savedDraft: savedDraftRef.current,
|
|
439
|
+
},
|
|
440
|
+
key.upArrow ? 'up' : 'down',
|
|
441
|
+
valueRef.current,
|
|
442
|
+
)
|
|
443
|
+
if (result) {
|
|
444
|
+
historyIndexRef.current = result.index
|
|
445
|
+
savedDraftRef.current = result.savedDraft
|
|
446
|
+
setValue(result.value)
|
|
406
447
|
}
|
|
407
448
|
}
|
|
408
449
|
})
|