Comment by EdiX

11 years ago

This data structure is called gap buffer, it's rather common in text editors because it's simple to implement and efficient on the most common use cases.

In the usual implementation the gap is only moved when you actually insert text, not when the cursor is moved, which makes it even more efficient.