| 207 | * Clamps to [0, value.length] and snaps to the previous boundary. |
| 208 | */ |
| 209 | export function normalizeInputCursor(value: string, cursor: number): number { |
| 210 | const c = clampInputCursor(value, cursor); |
| 211 | if (c === 0 || c === value.length) return c; |
| 212 | |
| 213 | let off = 0; |
| 214 | let last = 0; |
| 215 | while (off < value.length) { |
| 216 | const end = nextClusterEnd(value, off); |
| 217 | if (end === c) return c; |
| 218 | if (end > c) return last; |
| 219 | last = end; |
| 220 | off = end; |
| 221 | } |
| 222 | return value.length; |
| 223 | } |
| 224 | |
| 225 | function normalizeInputCursorForward(value: string, cursor: number): number { |
| 226 | const c = clampInputCursor(value, cursor); |