This pull request adds the ability to scroll the editor horizontally via the mouse wheel, as well as autoscrolling when the cursor moves. This feature took a couple of days to get implemented because we wanted to find a way of efficiently maintaining the longest line in a given range. This will not only be useful for horizontal scrolling, but will be reused when we will introduce a "display map" to handle folds and soft-wraps. A few highlights related to the proposed changes:
Each Insertion maintains a line index that is specifically designed to efficiently answer the following queries:
Given a 1d offset, return its 2d position.
Given a 2d position, return its 1d offset.
Given an offset range, return the longest row in that range
The line index is a binary tree represented as a densely packed array. To achieve this layout we use a linear algorithm that, instead of trying to recursively divide the sequence in two evenly sized subsequences, ensures that all the levels of the tree are full (except the last one) and filled from left to right (i.e., a complete binary tree).
Horizontal scrolling is entirely handled in JS. This is somewhat unfortunate and goes against our principle of pushing as much logic as possible down into the Rust core. However, until we replace our JS text layout engine with a more sophisticated one entirely implemented in native code, this minimizes the coordination that would need to happen between Rust and JS in order to retrieve layout information, measurements, etc.
This pull request adds the ability to scroll the editor horizontally via the mouse wheel, as well as autoscrolling when the cursor moves. This feature took a couple of days to get implemented because we wanted to find a way of efficiently maintaining the longest line in a given range. This will not only be useful for horizontal scrolling, but will be reused when we will introduce a "display map" to handle folds and soft-wraps. A few highlights related to the proposed changes:
Insertion
maintains a line index that is specifically designed to efficiently answer the following queries:/cc: @nathansobo