[brailleblaster] StyledText default content model

  • From: "Susan Jolly" <easjolly@xxxxxxxxxxxxx>
  • To: <brailleblaster@xxxxxxxxxxxxx>
  • Date: Sat, 11 Jun 2011 20:03:18 -0600

StyledText by default represents the entire text of a document as a single character array. So the only information it can know when it does a modification is the index into the character array of where the modification started and what characters were inserted or deleted. In the case of an insertion, the size of the character array is increased, the characters past the insertion point are shifted to the right, and the new characters are inserted directly into the correct place in the array. In the case of a delete, the size of the character array is decreased with the relevant characters removed and the ones past the deletion point shifted to the left.


FYI, in practice, with an efficient implementation, there doesn't have to be a shift every time a character is inserted since the character array used for storage typically has a movable gap or empty section. (This approach was apparently invented by the emacs developers.) If a character is inserted or deleted, the gap is moved to the location after the insertion or deletion position since usually someone using an editor makes a number of consecutive insertions. However, the gap model is basically hidden and when StyledText sends event information, the character positions are the correct physical positions they would have if the storage array didn't have a gap.

Susan

Other related posts: