Text editor basics

The simplest way to instantiate an editor looks like this:

editor := BrEditor new
	aptitude: BrGlamorousRegularEditorAptitude;
	text: 'something'
  

This hides quite a bit of details.

First, we pass a string as the initial value but behind the scene, the editor works with a text model which looks more like this:

'something' asRopedText
  

Beside strings, a text model holds also attributes. For example, the text from the snippets from this page have different colors and weights. These are provided by text attributes. Also modelled as text attributes are the adornments that appear inside the text, such as the expanders from the code. Learn more about them in Enhancing a text with text attributes.

Second, the editor itself has a model, too. A more elaborate way to create the same editor looks like this:

editor := BrEditorElement new.
editor constraintsDo: [:c | c vertical matchParent. c horizontal matchParent ].
editorModel := BrTextEditorModel new.
editorModel text: 'something' asRopedText.
editor editor: editorModel.
editor
  

The editor model handles things like selection, styling or completion. Learn about styling in Constructing a text editor with contextual styling for urls, and about completion in Working with completion in a text editor.