refactor(suggestions): consolidate element type guards and separator logic#276
Merged
bartekplus merged 6 commits intomasterfrom Mar 7, 2026
Merged
refactor(suggestions): consolidate element type guards and separator logic#276bartekplus merged 6 commits intomasterfrom
bartekplus merged 6 commits intomasterfrom
Conversation
…ggestionManager tests Replace brittle `await wait(Xms)` calls with `waitForNextCall()` and `waitFor()` helpers that poll for observable state changes instead of sleeping a fixed duration. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add curly braces to single-line if statements (eslint curly rule) and auto-format with prettier. Also exclude .claude/ from prettier checks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…logic - Add isInput/isTextArea/isTextValue static type guards to TextTargetAdapter and replace duplicated private implementations in SuggestionTextEditService, SuggestionPositioningService, and SuggestionManagerRuntime - Expose isSeparator/findMentionToken on SuggestionPredictionCoordinator (the canonical owner of separatorRegex) and remove the duplicate copies from SuggestionManagerRuntime; all call sites now delegate to the coordinator - Extract BLOCK_TAGS Set and SHOW_TEXT/SHOW_ELEMENT NodeFilter constants to module level in ContentEditableAdapter to avoid repeated allocation on hot paths - Remove unused snapshotBeforeCursor/snapshotAfterCursor parameters from resolveBeforeCursorForPrediction/resolveAfterCursorForPrediction - Remove trivial cancelPendingKeyFallback wrapper; callers use clearPendingKeyFallback directly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ocations - resolveBeforeCursorForPrediction now accepts an optional snapshot so callers that already hold one can skip a second DOM read - triggerActiveSuggestion: replaced two independent snapshot calls with a single resolveEditableCursorContext call; removed resolveAfterCursorForPrediction - resolveCurrentPredictionContext, scheduleKeyFallbackReconcile, shouldDeferContentEditableInputToFallback: each was taking two snapshots of the same element; now all derive both values from one snapshot - SuggestionPredictionCoordinator: cache separatorRegexNeedsReset flag at construction/updateLang time so isSeparator avoids a .global/.sticky property read on every character in the per-keystroke scan loop - SuggestionPositioningService: replace nodeName string checks with TextTargetAdapter.isInput for consistency Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…c and token parsing - TextTargetAdapter: add tests for isInput, isTextArea, isTextValue type guards; snapshot for textarea; hasCollapsedSelection for collapsed, expanded, and null-selection cases - SuggestionPredictionCoordinator: add describe blocks for isSeparator (including global/sticky lastIndex-reset regression), findMentionToken (token boundary, empty input, multi-separator), and updateLang (regex swap, separatorRegexNeedsReset recalculation, effect on token parsing) 42 new tests added across 2 files (102 total vs 62 before). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
isInput,isTextArea,isTextValuestatic methods toTextTargetAdapterand removed duplicate private implementations fromSuggestionTextEditService,SuggestionPositioningService, andSuggestionManagerRuntime(~3 sets of 3 methods removed)isSeparatorandfindMentionTokenpublic onSuggestionPredictionCoordinator(the canonical owner ofseparatorRegex) and removed identical private copies fromSuggestionManagerRuntime; all call sites delegate to the coordinatorBLOCK_TAGSSet andSHOW_TEXT/SHOW_ELEMENTNodeFilter constants to module level inContentEditableAdapter, avoiding repeated object creation on every callsnapshotBeforeCursor/snapshotAfterCursorparameters (suppressed withvoid), and removed the trivialcancelPendingKeyFallbackwrapperTest plan
<input>,<textarea>, andcontenteditabletargets🤖 Generated with Claude Code