Skip to content

refactor(suggestions): consolidate element type guards and separator logic#276

Merged
bartekplus merged 6 commits intomasterfrom
claude/optimistic-shtern
Mar 7, 2026
Merged

refactor(suggestions): consolidate element type guards and separator logic#276
bartekplus merged 6 commits intomasterfrom
claude/optimistic-shtern

Conversation

@bartekplus
Copy link
Owner

Summary

  • Centralize element type guards: Added isInput, isTextArea, isTextValue static methods to TextTargetAdapter and removed duplicate private implementations from SuggestionTextEditService, SuggestionPositioningService, and SuggestionManagerRuntime (~3 sets of 3 methods removed)
  • Deduplicate separator logic: Made isSeparator and findMentionToken public on SuggestionPredictionCoordinator (the canonical owner of separatorRegex) and removed identical private copies from SuggestionManagerRuntime; all call sites delegate to the coordinator
  • Eliminate hot-path allocations: Extracted BLOCK_TAGS Set and SHOW_TEXT/SHOW_ELEMENT NodeFilter constants to module level in ContentEditableAdapter, avoiding repeated object creation on every call
  • Clean up dead code: Removed unused snapshotBeforeCursor/snapshotAfterCursor parameters (suppressed with void), and removed the trivial cancelPendingKeyFallback wrapper

Test plan

  • Existing tests pass
  • Verify suggestions work on <input>, <textarea>, and contenteditable targets
  • Verify separator/tokenization behaviour unchanged

🤖 Generated with Claude Code

bartekplus and others added 6 commits March 7, 2026 07:17
…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>
@bartekplus bartekplus self-assigned this Mar 7, 2026
@bartekplus bartekplus added the enhancement New feature or request label Mar 7, 2026
@bartekplus bartekplus merged commit 6cd9579 into master Mar 7, 2026
13 of 14 checks passed
@bartekplus bartekplus deleted the claude/optimistic-shtern branch March 7, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant