Skip to content

refactor(paste): Remove dead prepend-mode smart spacing path - #1824

Merged
Chadpiha merged 2 commits into
mainfrom
refactor/remove-prepend-smart-spacing
Aug 26, 2026
Merged

refactor(paste): Remove dead prepend-mode smart spacing path#1824
Chadpiha merged 2 commits into
mainfrom
refactor/remove-prepend-smart-spacing

Conversation

@Chadpiha

Copy link
Copy Markdown
Collaborator

What

Removes the never-used "prepend" mode of the paste-time smart-spacing helper and everything that existed only to serve it:

  • applyPrepend, OPENING_CHARS, LEADING_PUNCTUATION in src/helpers/smartSpacing.js; with only append mode left, the mode dispatch was dead indirection, so applySmartSpacing(text) is now a single-purpose function
  • TextEditMonitor.getPrecedingChar and MACOS_AX_PRECEDING_CHAR_SCRIPT in src/helpers/textEditMonitor.js (its only consumer)
  • The prepend/mode-dispatch tests in test/helpers/smartSpacing.test.js
  • The sole call site (ipcHandlers.js) passes text directly; its comment still records why spacing is append-only (the AX read costs hundreds of ms — too slow for the paste hot path)

Why

Prepend mode has never been invoked in production since the module's introduction (#868): the only call site always used append mode, precisely because the macOS Accessibility preceding-char read is too slow for the paste hot path. Dead code per repo standards — git history preserves it if a fast native read ever makes prepend viable. The path already attracted a spurious external bug report (#1787 / #1788).

Reviewer notes

  • textEditMonitorPrecedingChar.test.js was renamed to textEditMonitorSelection.test.js, not deleted: beyond the two getPrecedingChar tests (removed), it holds 12 live tests for activateTargetPid, getSelectedText, and the -25212 native-failure cache, which are unchanged
  • No behavior change: pasted output is identical, since only append mode ever ran

Verification

  • Zero remaining references to any deleted symbol across src/test
  • Touched test files pass 18/18 under Node 24; full suite matches the pre-change baseline (only the pre-existing, unrelated voicePillStructure environment failures)
  • Prettier clean on all five files

The "prepend" mode of applySmartSpacing was never invoked in production
since its introduction (#868): the only call site always uses append
mode, because the macOS Accessibility read prepend depends on
(getPrecedingChar) costs hundreds of ms — too slow for the paste hot
path. Delete applyPrepend, its char sets, getPrecedingChar, and the AX
preceding-char script, and collapse applySmartSpacing to the single
remaining append behavior. No behavior change.

The tests covering the removed code are dropped;
textEditMonitorPrecedingChar.test.js is renamed to
textEditMonitorSelection.test.js since its remaining tests cover
selection reads, activation, and monitoring.

The dead path already attracted a spurious external bug report
(#1787 / #1788).
@Chadpiha
Chadpiha merged commit 2e7ee17 into main Aug 26, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant