This question is likely to make me sound rather ignorant. This is because I am.
I just think, if I were hypothetically interested in developing my own GUI text editor, widget, or whatever you want to name (which I don't like), how would I do it?
The temptation for a novice like me was to store the contents of a text editor as a string, which seems pretty expensive (not that I am too familiar with how string implementations differ between one language / platform and the next, but I I know that in .NET, for example, they are immutable, so frequent manipulations, such as what you will need to support in a text editor, will be wonderfully wasteful, building one copy of a line after another very quickly Sequence).
Presumably, some mutable data structure containing text is used instead; but figuring out what this structure looks like strikes me as something complicated. Random access would be good (I would think, anyway, don't you want the user to be able to jump anywhere in the text?), But then I wonder about the cost, say, of navigating somewhere in the middle of a huge document and immediately starts typing. Again, the newcomers approach (let's say you save the text as a resizable character array size) will lead to very low performance, I think, like every character typed by the user, there would be a lot of data for the "shift", more.
So, if I were to guess, I would suggest that text editors use some kind of structure that breaks the text into smaller parts (lines, maybe?), Which individually contain arrays of characters with random access and which themselves are randomly available in discrete pieces. It even looks like it should be a pretty monstrous simplification, though, if even remotely close to the start.
Of course, I also understand that there cannot be a “standard” way to implement text editors; perhaps this varies greatly from one editor to another. But I thought that since this is clearly a problem that has been resolved many, many times, perhaps a relatively common approach has surfaced over the years.
In any case, I’m just curious to find out if anyone has knowledge on this topic. As I said, I definitely do not want to write my own text editor; I'm just curious.