fix: prevent escape character from being inserted into input
Strip escape characters in PasteAwareTextInput handleChange to prevent them from being inserted by ink-text-input. This was causing the 'Press Esc again to clear' hint to flicker and disappear immediately because the value change triggered the useEffect that resets escapePressed. Also extracted the double-escape window duration to a constant (2.5s). 🤖 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta <noreply@letta.com>
This commit is contained in:
@@ -333,6 +333,22 @@ export function PasteAwareTextInput({
|
||||
}, [internal_eventEmitter]);
|
||||
|
||||
const handleChange = (newValue: string) => {
|
||||
// Drop lone escape characters that Ink's text input would otherwise insert;
|
||||
// they are used as control keys for double-escape handling and should not
|
||||
// mutate the input value.
|
||||
const sanitizedValue = newValue.replaceAll("\u001b", "");
|
||||
if (sanitizedValue !== newValue) {
|
||||
// Keep caret in bounds after stripping control chars
|
||||
const nextCaret = Math.min(caretOffsetRef.current, sanitizedValue.length);
|
||||
setNudgeCursorOffset(nextCaret);
|
||||
caretOffsetRef.current = nextCaret;
|
||||
newValue = sanitizedValue;
|
||||
// If nothing actually changed after stripping, bail out early
|
||||
if (sanitizedValue === displayValue) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Heuristic: detect large additions that look like pastes
|
||||
const addedLen = newValue.length - displayValue.length;
|
||||
const lineDelta = countLines(newValue) - countLines(displayValue);
|
||||
|
||||
Reference in New Issue
Block a user