Explaining the text editor's selection mechanism
The selection mechanism can look trivial in a text editor, but it's really anything but.
Take a look at this example: we get a selecter serivce for an editor and we tell it to select the word at position 2
. That does not sound too tricky. Only here we talk about cursor position, instead of text position.
select_moveOneRight_at_6 <gtExample> | anEditor | anEditor := self editorOnMultilineText. anEditor editor moveCursorTo: 6. anEditor selecter moveOneToRight; select. self assert: anEditor selection equals: (BlCompositeSelection new select: 6 to: 7). self assert: anEditor editor selectedText asString equals: 'e'. self assert: anEditor cursors equals: (BrTextEditorCursor atAll: #(7)). ^ anEditor
The fact that we can have two kinds of positions (text and cursor) makes things a little more complicated. So, we devised a visualization to help us. Executing the example above shows us a view like this: an editor with the cursor positions highlighted.
This is achieved through a little utility: BlDevCrossover
.
We built this visualization to help us with debugging. And it saved us a large debugging effort, indeed. But more importantly, it made the bug solving fun.