Skip to content

TextArea,ContextMenu: Fix and rework Sonnet based spellchecker

ivan tkachenko requested to merge work/ratijas/fix-spellchecker into master

This patch somewhat simplifies data flow and state management of spell checker in TextArea.

Sonnet.Settings becomes a global instance, so default state can be synchronized between text fields for which user did not toggle spell checking explicitly. This is actually interesting, as Sonnet.Settings does not emit signals across all instances, so a force-refresh (READ) might be required to receive updates values.

Both Instantiator of spellchecker highlighter and the highlighter itself are not being toggled from the context menu anymore. Now everything routes through TextArea instance's Kirigami.SpellChecking.enabled state, which also ensures that binding to defaults breaks when user explicitly toggles spellchecker from a context menu item. This also makes it possible to programmatically force spellchecker highlighter to be active on a read-only text area, however a context menu still won't show any spellchecker actions in that case.

Test plan:

  • Open Kirigami Gallery, navigate to "Text Field" page.
  • Open System Settings -> Spell Check KCM -> toggle "Automatic spell checking enabled by default" checkbox, click Apply.
  • Open new instance of Kirigami Gallery app -> go to Text Field page.

If you have any dictionaries installed, in one of the two app instances you should see lots of red words highlighted.

  • Toggle the Spell Check checkbox on the page.
  • Right click on the text area, toggle Spell Check menu item.

Both ways to toggle spellchecker should work.


Conceptually, I am still not quite happy with this API. It feels like highlighter component or instance should be bound to Kirigami.SpellChecking attached property or whatever (and for consistency we should rename it to Kirigami.SpellCheck). Also it's almost painful that TextInput (and by extension TextField subclass) does not expose any QTextDocument or at least QTextLayout which Sonnet/QSyntaxHighlighter could operate on.

Merge request reports