How are text editors generally implemented?

One technique that’s common (especially in older editors) is called a split buffer. Basically, you “break” the text into everything before the cursor and everything after the cursor. Everything before goes at the beginning of the buffer. Everything after goes at the end of the buffer.

When the user types in text, it goes into the empty space in between without moving any data. When the user moves the cursor, you move the appropriate amount of text from one side of the “break” to the other. Typically there’s a lot of moving around a single area, so you’re usually only moving small amounts of text at a time. The biggest exception is if you have a “go to line xxx” kind of capability.

Charles Crowley has written a much more complete discussion of the topic. You might also want to look at The Craft of Text Editing, which covers split buffers (and other possibilities) in much greater depth.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)