3 ms·
If you've never interacted with the file saved state of an editor which saves its edit history tree, its a revelation when you try the UNIX strings command on o
by ggm 9y ago
If you've never interacted with the file saved state of an editor which saves its edit history tree, its a revelation when you try the UNIX strings command on one. It took me a few minutes to realise insert and moves were not the same, because the structure followed insert order, to permit infinite-undo. The actual text position was a subsidiary location tagged on the string.
I think everyone should be asked to write their own simple editor, and then for extension try to convert from the obvious simple tropes in arrays to one which begins to do what these editors do.
- greglindahl 9y agoOr you could implement a gap buffer, and then your complicated editor is using a simple trope. Emacs is an example of a full-featured editor based on a gap buffer.
- ggm 9y agoSure. You could leap to the best solution first. Probably, you lucked out in the gene pool and your future fate is not to write bad code. The rest of us, who did not acquire sufficiently complex frontal lobes, struggle with concepts and probably dive into stupider solutions first, like I did at uni in the 1980s allocating a fixed size buffer (big initial mistake)_ and maintaining a huge linked list of edits sequence events into it. I passed the course, but future evidence suggests I didn't learn as much as I hoped!
- greglindahl 9y agoHa ha, well, I'll confess, I got lucky and discovered the existence of gap buffers before I tried to write a simple editor. And these days, there's a Wikipedia article on quite a few of the fundamental editor data structures. It's worth noting that no widely-used editor since emacs uses a gap buffer, so it's not like it's won the hearts and minds of implementers.
- eftychis 9y agoI wouldn't say a gap buffer is the "complicated and crazy" data structure for text editing. Certainly not the best. There's no free lunch, every approach has its downsides :)
- deleted 9y ago[deleted]
- continuational 9y agoGap buffers can’t support multiple cursors efficiently. This is a core feature in eg. Sublime Text.
- dsego 9y agoSublime doesn't use a gap buffer?