Compute word and line boundaries lazily in MultilineInput key handlers - #1225
Compute word and line boundaries lazily in MultilineInput key handlers#1225nordicnode wants to merge 2 commits into
Conversation
|
The core idea is sound: Two things hold this back from being portable as-is:
The benchmark numbers (74ms vs 2ms for 100k keystrokes) are plausible directionally but not verifiable from a synthetic harness that isn't included in the diff - worth adding the benchmark script itself if you want that number to carry weight. Worth iterating: extract the lineInfo lookup into one shared helper, and write tests that actually import and call the component's real boundary-finding logic (or exercise it through key events) rather than duplicating it. |
…al implementations
|
Thanks for the thorough review @codebuff-team! Both points have been addressed in the latest commit:
|
Summary
cli/src/components/multiline-input.tsx, defer word and line boundary calculations (findLineStart,findLineEnd,findPreviousWordBoundary,findNextWordBoundary, and visuallineStarts) to the specific key branches that actually consume them.handleDeletionKeysandhandleNavigationKeyseagerly executed 4 string scans backwards and forwards across the text buffer plus visual buffer queries at the top of their callbacks on every single keystroke.getVisualLineInfohelper: Factored the visual line lookup logic into a singlegetVisualLineInfo()helper insidehandleNavigationKeys, eliminating the 4-fold duplicatedtextRef.currentcast across Home, End, Up, and Down while preserving full lazy execution.findLineStart,findLineEnd,findPreviousWordBoundary, andfindNextWordBoundaryso they can be directly imported and exercised by unit tests without parallel copies.cli/src/components/__tests__/multiline-input.test.tsx, imported and directly tested the real boundary implementations across standard text, consecutive whitespace, empty strings, start/end bounds, clamping, and multiline inputs.Test plan
bun test --config=/dev/null src/components/__tests__/multiline-input.test.tsx(77 passed, 0 failed)bun run --cwd cli typecheck(0 errors)bun freebuff/cli/build.ts 0.0.0-ci(successful binary build)bun cli/scripts/smoke-binary.ts cli/bin/freebuff(OK)bun x prettier --check cli/src/components/multiline-input.tsx cli/src/components/__tests__/multiline-input.test.tsx(All matched files use Prettier code style)