Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The key data structure in a text editor is the one that holds the text. <a href="http://www.cs.unm.edu/~crowley/papers/sds/sds.html" rel="noreferrer">This article</a> has a good round-up of the types of structures people choose from for a text editor. The article is old, but is still very relevant today.</p> <p>Very simple data structures (like an array of characters) tend to be too slow for certain types of operations, like inserting a character at the beginning of a document that is already very long, as you would end up moving or copying lots of data around. Most of the data structures reduce or limit the amount of data being moved by cleverly dividing the document up into chunks. The article I linked has details.</p> <p>Another reason to use some of the more advanced data structures are to make it simpler to implement features like undo and redo. Some of the data structures make it easy to keep deleted text around so that it's easy to put the document back into a previous state by changing a few pointers or offsets.</p> <p>Additional data structures can help with formatting the text, but those are usually more for document editors (like Word) than text editors.</p> <p>JTextArea (and comparable features in other platforms) essentially are text editors, and they probably use one of the data structures from the article I linked to.</p> <p>If you wanted to write a text editor at that level rather than using an existing one, you'd need to implement several types of functionality:</p> <ol> <li>Loading the text from a file to the data strcture and saving it back out again.</li> <li>Responding to key presses that modify the text. For example, if the user types a letter key, you need to insert that letter into the text data structure at the current location. If they press the backspace key, you need to remove a character. Etc.</li> <li>Displaying the document on the screen. You'll constantly have to map window coordinates to a point in the text sequence and vice versa. For example, if the user clicks the mouse, you need to turn the (x,y) coordinate of the click into a position within your text sequence. Depending how sophisticated your layout is, you might be able to calculate this on the fly, but it often helps to have an additional data structure that acts as a mapping between the text sequence and the window coordinates. Of course, you have to update that data structure if the text changes or if the window resizes.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload