Skip to content

feat(core): add opt-in smartPunctuation (double-space period) to Textarea#1178

Open
helgeu wants to merge 1 commit into
anomalyco:mainfrom
helgeu:feat/textarea-smart-punctuation
Open

feat(core): add opt-in smartPunctuation (double-space period) to Textarea#1178
helgeu wants to merge 1 commit into
anomalyco:mainfrom
helgeu:feat/textarea-smart-punctuation

Conversation

@helgeu

@helgeu helgeu commented Jun 15, 2026

Copy link
Copy Markdown

Summary

Adds an opt-in smartPunctuation option to TextareaRenderable that mirrors the native macOS/iOS "Add period with double-space" behavior: when enabled, typing two spaces after a word inserts ". " instead of " ". Pressing Backspace immediately after reverts it back to two spaces.

Implements the design discussed in #1177.

Why this belongs in the widget

Downstream consumers (e.g. opencode's prompt) can't implement this cleanly, because individual space keystrokes are handled inside Textarea.handleKeyPress and never surface to the host app — the conversion has to live here.

Behavior

  • Opt-in: smartPunctuation defaults to false; existing behavior is unchanged. Also exposed as a runtime getter/setter.
  • Context-gated (no timing): converts only when the char before the cursor is a space preceded by a letter/digit, with no active selection. It does not fire at line start, after punctuation, or stack into ".. " on a third space.
  • Revert-on-backspace: pressing Backspace immediately after an auto-insert restores the two literal spaces; any other keypress (or paste) consumes the revert opportunity.

Why no keystroke timing

Per the research in #1177: Apple's implementation and every editor input-rule system (ProseMirror, CodeMirror, VS Code, etc.) gate this purely on preceding-character context, never on keystroke timing. Timing-based gating is non-deterministic, breaks paste/fast typists, and has no precedent for content transforms. (Android/AOSP is the lone exception with a loose 1100ms window, but it still relies on the same context gates + backspace-revert.)

Tests

New Textarea.smart-punctuation.test.ts (8 cases): default-off, convert after letter, convert after digit, no-op at line start, no-op after punctuation, no triple-space stacking, backspace-revert, and runtime toggle.

  • New tests: 8/8 pass
  • Full Textarea suite: 576/576 pass (no regressions)
  • oxfmt + oxlint: clean

Closes #1177

Add a `smartPunctuation` option (default false) to TextareaRenderable that
mirrors the native macOS/iOS "Add period with double-space" behavior: typing
two spaces after a letter or digit inserts ". " instead of "  ". Pressing
backspace immediately after reverts to two spaces.

The conversion is context-gated (no keystroke timing), matching how editor
input-rule systems and Apple's implementation work; timing-based gating is
non-deterministic and unsupported elsewhere.

Refs anomalyco#1177
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.

Add opt-in double-space → period (smart punctuation) to Textarea

1 participant