Skip to content

Add local spelling checks to the composer body - #4

Merged
latentoperator merged 20 commits into
mainfrom
task/S04-spelling-settings
Oct 1, 2026
Merged

latentoperator merged 20 commits into
mainfrom
task/S04-spelling-settings

Conversation

@latentoperator

@latentoperator latentoperator commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Outcome

Add local spelling checks to the composer body. Completed misspelled words receive an underline in the theme's error color. Right-click or Ctrl+. opens up to five suggestions, Ignore for this session, and Add to dictionary.

Corrections support undo and mark the draft as edited. Editing the draft invalidates stale correction choices. Settings has an on/off switch and reports missing spelling support or failed personal-word saves. Personal words are stored in the app's private spelling.json.

Sonnet checks words locally. A missing module or dictionary leaves composing available. The composer follows the saved language setting, including when the dictionary changes while a draft is open. Subject and address fields are outside this change.

Status

Draft until a final hands-on check in a real desktop session: typing through an input method or compose key, and the underline and menu in a live window. Base: 4d5e0f0; head: 811e99a. The earlier verification below was run at 39d4dd5. Since then:

  • Personal words moved unchanged into ui/compose/PersonalWords.qml, because together with Add original-message export for Outlook and IMAP #3 they pushed ui/Service.qml over its 128 KiB size limit.
  • The Settings hint now says to restart after installing a dictionary. Sonnet lists dictionaries once per process: installing one mid-run was not picked up by a new adapter, but a fresh process found it.
  • The composer spelling tests now skip instead of timing out when Sonnet is missing.

Verification

Local checks on Linux with Qt 6.11.2, Sonnet 6.29.0, and en_US/en_GB dictionaries:

  • Actual Sonnet adapter, composer, and menu suites: 9, 15, and 16 passed, with no failures or skips.
  • Independent review found and reproduced three defects. The fixes preserve clean drafts during Ignore/personal-word updates, refresh other composers after session Ignore, and open Ctrl+. without replacement suggestions. All nine independent verification checks passed, including cleanup and Undo/Redo.
  • A runner with Sonnet removed from its import path kept the production composer editable with working Undo. The standalone composition fixture also passed.
  • make validate: QML 1053 passed, 8 failed, no skips. The same eight keyboard-navigation failures reproduce at the pinned baseline. All Rust targets passed; library 555 passed, 11 ignored. JS/shell checks and the separately run app-QML, lint, plugin validation, and diff checks passed.
  • Standalone app rebuilt with the session library embedded; native settings and resource tests passed. Backend API and real backend-process checks passed.

All 14 GitHub checks passed for this candidate.

Combined build with #3

Merged with #3 on top of 4d5e0f0 and run on an Arch/Omarchy laptop (Qt 6.11.2, Quickshell 0.3.1, Rust 1.98.1, Sonnet 6.29.0), with isolated home and config directories:

  • make test-rust: 667 passed, 11 ignored. test-js, test-shell, test-backend-process, test-app-qml, and qml-check passed.
  • make test-qml: 1066 passed, 8 failed. The failures are the same eight KeyboardReaderNavigation cases that fail on untouched main with this Qt.
  • End to end, the real omamail serve with a synthetic IMAP account on a loopback server saved a multipart message with an 8-bit body and a binary attachment. The file was byte-identical, mode 0600, and parsed independently with the subject, body, and attachment intact. A second save got (2) added to the name. The server saw only EXAMINE and UID FETCH … BODY.PEEK[]. Missing messages, unknown accounts, and a missing account were refused.
  • With Sonnet hidden from the QML import path, the spelling suites skip and the export suites pass. With Sonnet present, they all pass.
  • Restart persistence was tested on real Quickshell rather than the test mock. One qs process added a word through Service, and it was written to spelling.json with mode 0600. A fresh process loaded it and treated the word as correct. Session Ignore did not carry over into the fresh process.

Screenshots

Reviewed captures cover body underlines, suggestion menus, Settings, and missing-dictionary guidance in light and dark themes. Images are hosted as GitHub attachments.

The previews use synthetic text and isolated settings. The light composer pairs use identical text. The earlier dark composer examples use different sample text. Settings captures have a small scroll offset. These images show the UI; they do not replace integration tests.

The body comparison shows the new underlines. The menu comparison shows corrections, Ignore for this session, and Add to dictionary.

View Before After
Body, light theme before body light after body light
Menu, light theme before editing menu light after suggestions light
Settings and additional theme captures
View Before After
Settings, light before settings light after settings light
Missing dictionary, light before settings light after missing dictionary light
Settings, dark before settings dark after settings dark
Missing dictionary, dark before settings dark after missing dictionary dark
Body, dark before body dark after body dark
Menu, dark before editing menu dark after suggestions dark

Security

Reviewed and passed for the local spelling, optional loading, and private configuration changes. Independent review and isolated tests found no global dictionary or Sonnet preference writes. Full runtime acceptance remains pending.

Release Notes

  • Check spelling locally in the composer body, with corrections, session ignore, and a personal dictionary.
  • Turn spelling checks on or off in Settings, with guidance when spelling support is missing.

- probe: ui/tests/qml/tst_spellcheck_probe.qml (+ SpellcheckProbe.qml) attaches
  the real Sonnet highlighter through an optional Loader and checks UTF-16
  offsets, suggestions, ignore scope, disabling, and undo-safe correction
- decision: planning/decisions/S00.md freezes the adapter interface and raises
  two findings that need supervisor sign-off: misspelledColor is inert (the
  underline is always Qt's fixed red), and addWordToDictionary writes the global
  Hunspell dictionary, so personal words must be app-owned and applied via
  ignoreWord
- state: S00 marked READY FOR REVIEW
- S00.md: D1 accept Qt's fixed red underline, D2 app-owned personal words via
  ignoreWord, D3 keep Sonnet replaceWord with the priming rule (all confirmed)
- tests/spellcheck/playground.qml: desktop tool to type, see underlines, and
  click a suggestion to apply a primed correction
- portable suite passes
- ui/compose/SpellcheckAdapter.qml implements the S00 interface (inspect,
  applyCorrection with the required suggestions priming, ignoreForSession,
  personalWords) and is the only production file importing org.kde.sonnet
- ComposeView loads it through a Loader bound to the body textDocument,
  exposes spellingAvailable/spellingStatus/spellingAdapter, and unloads it
  when spelling is disabled; never assigns a null document
- tests: adapter contract (7) and composer integration (5) pass; the preview
  harness shows the real composer for hands-on tuning
- Makefile QML_FILES updated
Sonnet's QML highlighter colours the misspelled word red as well as underlining
it (unlike the QWidget one), and misspelledColor is inert. So the adapter's
highlighter now stays inactive and is used purely as a checker; the composer
draws the line itself from completed-word ranges.

- spellcheck adapter: adds misspelledRanges(text); a word is marked only once a
  delimiter follows it, so a word still being typed is never underlined;
  replaces item icons with the theme error colour
- ComposeView: errorColor property, debounced completion check, underline
  overlay on the body item using positionToRectangle
- App.qml passes the theme's urgent role as errorColor
- preview: thinner suggestion strip coloured from the composer's theme roles
- tests: adapter 9, composer 6, all green
- TextMenu gains a spelling section above Cut/Copy/Paste: up to five
  suggestions, Ignore for this session, and Add to dictionary, all sharing the
  existing theme colours and j/k/o keyboard navigation
- ComposeView captures the clicked word via TextEdit.positionAt and the caret
  word via Ctrl+., and routes corrections to the adapter; the fixed bottom
  strip is retired
- keeps the captured UTF-16 position so a correction targets the clicked word
  even if the caret moved
- tests: menu/caret integration 10 in the composer test, text menu 14; full QML
  suite 1023 passed / 8 pre-existing Qt 6.11 failures; the TextMenu cursor test
  now names its row instead of assuming index 0
positionToRectangle returns the caret at a position (width 1), not the
character's box, so anchoring the width on end-1 stopped the line at the start
of the last letter. Use the caret one past the word instead.

Measured: 'sentance' drew 47 px before, 53 px after (full advance 52.7 px).
Fix the spelling review findings:

- The personal dictionary now reaches both host write boundaries
  (config-store.sh and StandaloneShell.qml), and a refused write is
  surfaced in Settings instead of silently staying memory-only.
- Personal-word writes queue the latest snapshot and merge a late initial
  read, so an add during an in-flight write or before the file loads is
  not lost.
- The native settings allowlist accepts spellingEnabled and
  spellingLanguage, with a SettingsStore round-trip test.
- The composer and service probe follow spellingLanguage continuously and
  report no-dictionary for the requested language rather than falling back
  to English; availability compares the accepted dictionary with the
  request because Sonnet keeps the prior language on a missing one.
- A spelling correction is refused when the body revision moved under the
  menu, so a repeated misspelling cannot redirect the edit to the wrong
  occurrence.
- Underline geometry re-measures on width, wrap and font changes.
- The spelling bindings move from App.qml into ComposeView, keeping
  App.qml under the 128 KB source ceiling.
latentoperator and others added 6 commits September 30, 2026 09:05
Sonnet lists installed dictionaries once per process. A dictionary installed while Omamail runs is not found by reopening Settings or by a new spelling adapter; verified on Qt 6.11.2 and Sonnet 6.29.0 by installing a dictionary under XDG_DATA_HOME mid-run. A fresh process finds it.
Service.qml has a 128 KiB ceiling in tests/test_source.sh. Spelling alone fits under it, but together with message export it does not. The personal-word store (load, merge, queued write, and its FileView) moves unchanged to compose/PersonalWords.qml; Service keeps the same public properties and functions.
Without the Sonnet module the adapter never loads, so waiting for it timed out and failed 27 cases instead of skipping them. The waits now also accept the no-module status and the cases skip. Verified on Qt 6.11.2 both with Sonnet (15 + 16 passed) and with it hidden from the import path (13 + 14 skipped, 0 failed).
The preview's stand-in service had no personal-word store, so Add to
dictionary was a silent no-op there. The real service and the composer
tests already cover it; this only makes the hands-on preview match.
@latentoperator
latentoperator marked this pull request as ready for review October 1, 2026 15:14
@latentoperator
latentoperator merged commit c55a3d4 into main Oct 1, 2026
14 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