(t: string, c: number)
| 57 | }, [value]); |
| 58 | |
| 59 | const apply = (t: string, c: number) => { |
| 60 | onChange(t); |
| 61 | setCursor(Math.max(0, Math.min(c, t.length))); |
| 62 | setAnchor(null); // any edit collapses the selection |
| 63 | histIdx.current = null; // and drops out of history-recall mode |
| 64 | }; |
| 65 | |
| 66 | // Selection = the half-open range [min(anchor,cursor), max(anchor,cursor)). |
| 67 | const hasSelection = anchor !== null && anchor !== cursor; |