-
Notifications
You must be signed in to change notification settings - Fork 275
Offset Tracker
Offset tracking performs the function of tracking caret position in text across text transformation operations and during text editing.
As such there are some preparatory steps needed to aid the tracker in recovering the caret
position accurately, especially after text transformation is applied immediately following an
edit operation which results in the caret being surrounded by whitespace or format control
characters such as LineSeparator (LS
).
Caret surrounded by whitespace is problematic because most transformations do not preserve whitespace and may result in the text at the caret position to be removed. Additionally, typing spaces will result in them being collapsed after text wrapping, making it impossible to insert a space followed by non-space text after a word. It is more natural to allow one space behind the caret to remain even when there is one space after the caret already present to allow natural typing results.
Achieving this requires pre-processing the text and changing the first space after a word to
before applying text wrapping to prevent it from being collapsed with the next space
and keeping the caret at the
character after wrapping.
The same applies to table formatting except all spaces before the caret, when caret is in the
trailing whitespace region of a table cell and the cell, should be changed to
if a
space was inserted before formatting the table. This has the effect of not collapsing any typed
spaces in anticipation that a non-space will be typed. If on the other hand the caret is in the
whitespace region before the cell text then no action is needed.
Similarly, if text is removed by a backspace operation the caret should be kept in the same
relative position to the end of the previous word so it does not appear to jump around in the
text as it is wrapped after the edit. If after backspace the caret was one or more spaces after
of the previous word, then after wrapping it should be one space after the end of the word, even
if the other spaces were collapsed or removed by having the following text wrap to the next
line. This too is achieved by changing the space after the previous word to
before
wrapping to allow it to survive the wrapping operation, and changing it back to a space after
wrapping.
After backspace preparation of table text for formatting is the same as it is for space insert. Only the caret position relative to cell's text and cell alignment determine the required modification of text before applying table formatting.
Line Separator (LS
) presents a special case because it will always be at the start of the next
line after the text is wrapped. Text inserted right before the LS
character will be wrapped to
the previous line.
If the caret is immediately before the LS
character or separated from it only by spaces, then
typing will result in text appearing at the end of the previous line, instead of at the caret
position. It is therefore desirable that the caret position be kept with the inserted text even
if it is separated from it by a space than to keep it with the LS
character on the next line.