PackageDescription: TextHighlighting


Text Highlighting

Last published: January 18, 2017 by 'heeg'

Defines 3 Classes
Extends 11 Classes


The highlighting controller supports multiple highlighters, each will get a chance to do its highlighting on the editor text. The highlighters should be written so that they do their best to not trash any other highlighting that's already present in the text. The order in which the highlighters will be invoked is determined by highlighter ordering (see Highlighter>>order).

There is a dedicated Highlighter class to simplify global highlighter management when loading and unloading highlighting packages. It provides class side #install and #uninstall methods that can be invoked from package postLoad/preUnload actions for example.

A highlighter can be attached to a TextEditorController as follows:

SpellingHighlighter on: aTextEditorController.

This is usually done in the #postBuildWith: method of the associated application model. However this not sufficient to resolve code conflicts between multiple independent highlighters, they would still have to fight over the postBuildWith: method. Therefore this package also adds a pragma based mechanism to avoid these kinds of code conflicts. This mechanism is invoked through ApplicationModel>>addHighlighters which will collect all methods with pragma in the application model class and execute them all, expecting they each add their own respective highlighter. So for example to add spell checking to the BrowserCommentTool, we make sure that its postBuildWith: calls 'self addHighlighters'. Then we add an extension method to the tool class along these lines:

addSpellingHighlighter

SpellingHighlighter on: self textController

This way another highlighting package can also add similar kind of extension method and it will be picked up automatically (as long as #addHighlighters is invoked once somehow).

In general new highlighting capability is added by creating a new Highlighter subclass. See HyperlinkHighlighting or SpellcheckerHighlighting for examples. There's also a DelegatingHighlighter which can be used when the actual highlighting logic needs to be done by some other object. The RBCodeHighlighting package uses a DelegatingHighlighter.