Page 7 of 7

Re: Text Editor Shifting Mechanics

Posted: Mon Jan 26, 2026 9:11 pm
by GARTHWILSON
It looks like a really good resource, except that none of the diagrams show up for me, only text.

Re: Text Editor Shifting Mechanics

Posted: Mon Jan 26, 2026 9:12 pm
by BigDumbDinosaur
GARTHWILSON wrote:
...none of the diagrams show up for me, only text.
Same here.

Re: Text Editor Shifting Mechanics

Posted: Mon Jan 26, 2026 9:19 pm
by BigEd

Re: Text Editor Shifting Mechanics

Posted: Tue Jan 27, 2026 9:17 am
by rwiker
No True Scotsman wrote:
BigDumbDinosaur wrote:
gfoot wrote:
I don't remember what it is called but it's a method where characters before the cursor are stored at the start of the block and characters after the cursor are at the end of the block, with a big gap in between to allow fast editing.  When the cursor moves (or at least when an edit starts) you move a chunk of data to create this situation before inserting the new text.
That was brought up a number of posts ago...the phrase “sliding window” comes to mind.
Is this what they call a piece table data structure?
https://en.wikipedia.org/wiki/Gap_buffer, perhaps?

Re: Text Editor Shifting Mechanics

Posted: Tue Jan 27, 2026 9:19 am
by BigEd
Edit: agree, gfoot is describing a gap buffer.

It looks to me like the piece table is more fine-grained than the gap buffer (so, thanks for the pointer to that!) Also it keeps the original file in one buffer, and additions in a second (growing) buffer. It might be that it's quicker but uses more memory - depending on how big the gap might have been.

Edit to add
Quote:
Undo is just a matter of keeping the right piece descriptors
around. Unlimited undoes can be easily supported.

Re: Text Editor Shifting Mechanics

Posted: Tue Jan 27, 2026 4:49 pm
by No True Scotsman
I found an object-oriented implementation of the piece table in JavaScript, if anybody wants to examine it.
PieceTable.js.zip
Source code for a PieceTable written in JavaScript
(2.22 KiB) Downloaded 23 times
The syntax is close enough to Java and C++ to serve as pseudocode for instructional purposes. I haven't delved into this yet myself, but I'll definitely be wanting a rudimentary text editor as a core component of my 6502 system. My preliminary research into writing a text editor herded me in the direction of the piece table. It may have even been the above referenced text that sent me down that road.

It's important to me that the application be completely decoupled from the on-screen visual presentation, as the latter will be farmed out to a serial terminal running on an ESP32 microcontroller board.