@nick-skriabin/glyph 0.1.3 → 0.1.5
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/index.cjs +12 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1923,6 +1923,7 @@ function Input(props) {
|
|
|
1923
1923
|
value: controlledValue,
|
|
1924
1924
|
defaultValue = "",
|
|
1925
1925
|
onChange,
|
|
1926
|
+
onKeyPress,
|
|
1926
1927
|
placeholder,
|
|
1927
1928
|
style,
|
|
1928
1929
|
focusedStyle,
|
|
@@ -1951,6 +1952,10 @@ function Input(props) {
|
|
|
1951
1952
|
const workingCursorRef = React15.useRef(cursorPos);
|
|
1952
1953
|
React15.useEffect(() => {
|
|
1953
1954
|
workingValueRef.current = value;
|
|
1955
|
+
if (workingCursorRef.current > value.length) {
|
|
1956
|
+
workingCursorRef.current = value.length;
|
|
1957
|
+
setCursorPos(value.length);
|
|
1958
|
+
}
|
|
1954
1959
|
}, [value]);
|
|
1955
1960
|
React15.useEffect(() => {
|
|
1956
1961
|
workingCursorRef.current = cursorPos;
|
|
@@ -1958,12 +1963,14 @@ function Input(props) {
|
|
|
1958
1963
|
const stateRef = React15.useRef({
|
|
1959
1964
|
isControlled,
|
|
1960
1965
|
onChange,
|
|
1966
|
+
onKeyPress,
|
|
1961
1967
|
multiline: multiline ?? false,
|
|
1962
1968
|
innerWidth
|
|
1963
1969
|
});
|
|
1964
1970
|
stateRef.current = {
|
|
1965
1971
|
isControlled,
|
|
1966
1972
|
onChange,
|
|
1973
|
+
onKeyPress,
|
|
1967
1974
|
multiline: multiline ?? false,
|
|
1968
1975
|
innerWidth
|
|
1969
1976
|
};
|
|
@@ -1986,8 +1993,12 @@ function Input(props) {
|
|
|
1986
1993
|
const {
|
|
1987
1994
|
isControlled: ctrl,
|
|
1988
1995
|
onChange: cb,
|
|
1996
|
+
onKeyPress: onKey,
|
|
1989
1997
|
multiline: ml
|
|
1990
1998
|
} = stateRef.current;
|
|
1999
|
+
if (onKey?.(key) === true) {
|
|
2000
|
+
return true;
|
|
2001
|
+
}
|
|
1991
2002
|
const val = workingValueRef.current;
|
|
1992
2003
|
const pos = workingCursorRef.current;
|
|
1993
2004
|
if (key.name === "escape") return false;
|
|
@@ -2040,22 +2051,6 @@ function Input(props) {
|
|
|
2040
2051
|
}
|
|
2041
2052
|
return true;
|
|
2042
2053
|
}
|
|
2043
|
-
if (key.name === "u") {
|
|
2044
|
-
if (ml) {
|
|
2045
|
-
const { line, lines } = cursorToLineCol(val, pos);
|
|
2046
|
-
const lineStart = lineColToCursor(lines, line, 0);
|
|
2047
|
-
if (pos > lineStart) {
|
|
2048
|
-
const newVal = val.slice(0, lineStart) + val.slice(pos);
|
|
2049
|
-
updateValue(newVal, lineStart);
|
|
2050
|
-
}
|
|
2051
|
-
} else {
|
|
2052
|
-
if (pos > 0) {
|
|
2053
|
-
const newVal = val.slice(pos);
|
|
2054
|
-
updateValue(newVal, 0);
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
return true;
|
|
2058
|
-
}
|
|
2059
2054
|
if (key.name === "k") {
|
|
2060
2055
|
if (ml) {
|
|
2061
2056
|
const { line, lines } = cursorToLineCol(val, pos);
|
|
@@ -2456,9 +2451,7 @@ function ScrollView({
|
|
|
2456
2451
|
if (key.name === "d") {
|
|
2457
2452
|
setOffset(offset + halfPage);
|
|
2458
2453
|
} else if (key.name === "u") {
|
|
2459
|
-
|
|
2460
|
-
setOffset(offset - halfPage);
|
|
2461
|
-
}
|
|
2454
|
+
setOffset(offset - halfPage);
|
|
2462
2455
|
} else if (key.name === "f") {
|
|
2463
2456
|
setOffset(offset + fullPage);
|
|
2464
2457
|
} else if (key.name === "b") {
|