wormclaude 1.0.96 → 1.0.97
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/lineeditor.js +22 -13
- package/dist/theme.js +1 -1
- package/package.json +1 -1
package/dist/lineeditor.js
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
|
-
import React, { useState, useEffect } from 'react';
|
|
1
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
2
2
|
import { Text, useInput } from 'ink';
|
|
3
3
|
// Tam imleç-kontrollü satır editörü (ink-text-input yerine).
|
|
4
|
-
//
|
|
4
|
+
// ÖNEMLİ: Ink'in useInput'u handler'ı bayat closure ile çağırabilir → value/cursor'u REF'ten okuruz
|
|
5
|
+
// (her render güncellenir) ki sağ-ok/yazma doğru konumu kullansın.
|
|
6
|
+
// Destekler: yazma (imleç konumuna), Backspace/Delete, ← →, Home/End (Ctrl+A/Ctrl+E).
|
|
5
7
|
// ↑↓/PageUp/PageDown/Esc/Tab'a DOKUNMAZ → menü/scroll/dialog handler'larına geçer.
|
|
6
8
|
export default function LineEditor({ value, onChange, onSubmit, placeholder, isActive = true, color }) {
|
|
7
9
|
const [cursor, setCursor] = useState(value.length);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
const valueRef = useRef(value);
|
|
11
|
+
const cursorRef = useRef(cursor);
|
|
12
|
+
valueRef.current = value; // her render'da güncel değer
|
|
13
|
+
cursorRef.current = cursor;
|
|
14
|
+
// value dışarıdan kısalırsa imleci sınırla (örn. submit'te temizlenince).
|
|
15
|
+
useEffect(() => { if (cursor > value.length)
|
|
16
|
+
setCursor(value.length); }, [value]); // eslint-disable-line
|
|
10
17
|
useInput((input, key) => {
|
|
18
|
+
const val = valueRef.current;
|
|
19
|
+
const cur = cursorRef.current;
|
|
11
20
|
if (key.leftArrow) {
|
|
12
|
-
setCursor(
|
|
21
|
+
setCursor(Math.max(0, cur - 1));
|
|
13
22
|
return;
|
|
14
23
|
}
|
|
15
24
|
if (key.rightArrow) {
|
|
16
|
-
setCursor(
|
|
25
|
+
setCursor(Math.min(val.length, cur + 1));
|
|
17
26
|
return;
|
|
18
27
|
}
|
|
19
28
|
if (key.return) {
|
|
20
|
-
onSubmit?.(
|
|
29
|
+
onSubmit?.(val);
|
|
21
30
|
return;
|
|
22
31
|
}
|
|
23
32
|
if (key.backspace || key.delete) {
|
|
24
|
-
if (
|
|
25
|
-
onChange(
|
|
26
|
-
setCursor(
|
|
33
|
+
if (cur > 0) {
|
|
34
|
+
onChange(val.slice(0, cur - 1) + val.slice(cur));
|
|
35
|
+
setCursor(cur - 1);
|
|
27
36
|
}
|
|
28
37
|
return;
|
|
29
38
|
}
|
|
@@ -32,15 +41,15 @@ export default function LineEditor({ value, onChange, onSubmit, placeholder, isA
|
|
|
32
41
|
return;
|
|
33
42
|
}
|
|
34
43
|
if (key.ctrl && input === 'e') {
|
|
35
|
-
setCursor(
|
|
44
|
+
setCursor(val.length);
|
|
36
45
|
return;
|
|
37
46
|
}
|
|
38
47
|
// Gezinme/özel tuşlar bize ait değil → metne yazma, başka handler'lara bırak.
|
|
39
48
|
if (key.ctrl || key.meta || key.tab || key.escape || key.upArrow || key.downArrow || key.pageUp || key.pageDown)
|
|
40
49
|
return;
|
|
41
50
|
if (input) {
|
|
42
|
-
onChange(
|
|
43
|
-
setCursor(
|
|
51
|
+
onChange(val.slice(0, cur) + input + val.slice(cur));
|
|
52
|
+
setCursor(cur + input.length);
|
|
44
53
|
}
|
|
45
54
|
}, { isActive });
|
|
46
55
|
// Placeholder (boş input)
|
package/dist/theme.js
CHANGED