If you are interested in this kind of stuff, Craig Finseth's The Craft of Text Editing is a great read: https://www.finseth.com/craft/

That will make a good weekend read thanks! Others may be interested in Data Structures for Text Sequences by Charles Crowley[0] which describes Piece Tables. This is the basis for the Vis editor[1].

[0]https://www.cs.unm.edu/~crowley/papers/sds.pdf

[1]https://github.com/martanne/vis