'use strict'; /** * ink-text-input does not know about SGR mouse reports. If one reaches it, * the report is treated as ordinary printable input and appears in the * prompt. Filter it before the parent sees the new value and remount the * underlying input so its private cursor state cannot retain the length of * the discarded report. */ import { createElement as h, useState } from 'react'; import TextInput from 'ink-text-input'; import { stripMouseSequences } from './mouse.js'; export function SafeTextInput(props) { const [generation, setGeneration] = useState(0); const handleChange = (next) => { const cleaned = stripMouseSequences(next); if (cleaned !== next) { setGeneration((value) => value + 1); } props.onChange?.(cleaned); }; return h(TextInput, { ...props, key: generation, onChange: handleChange, }); }