The prior version worked fine for the typical single insertion/removal
cases. But when larger imbalances happened due to bulk insertion or
removal it wouldn't work correctly.
The new improved version works on any tree whose children are themselves
balanced, even if they are extremely different heights when compared to
each other. It works in O(log N) time.
It doesn't use an intermediate conversion to a string anymore, and should
execute in O(log N) as long as the right-hand rope is equal length or
smaller than the left.
It may also be O(log N) for the left-hand rope being smaller, but that
depends on whether the rebalance code executes in O(log N) time when
the left and right hand side are individually balanced. I haven't
analysed it yet, so dunno.
The rope uses a large leaf-node text length, so in the vast majority of
cases this ends up being the same as directly storing the string data.
But in the case that the line becomes extremely long, this will allow
for reasonable performance
This commit pulls the formatter out of the text buffer and
puts it in the editor instead. However, there is a lot of
commented code utlizing the buffer and formatter that still
needs to be updated.
In short, the editor is pretty non-functional in this commit.
File loading is now the responsibility of the Buffer, which allows
it to do some weird internal stuff to make it faster.
Also, using custom code for scanning the text, so all line endings
are handled now, not just LF and CRLF.
A LineFormatter determines how a line of text is visually displayed in
2d space. This allows both the Console and GUI version of the editor
to share the same buffer code whilst still handling the differing ways
in which both handle visual display.
There is now a CursorSet type that handles multiple cursors, and makes
it convenient to maintain the necessary invariants expected by the rest
of the code for multi-cursor editing.
This should probably be replaced by a more efficient implementation in
the future, as this version will be slow and require large allocations
when moving large pieces of text. But let's wait and see if it's a
problem in practice first.