Have view scrolling nearly working again.

Just doesn't *quite* work with wrapped lines.  Need to investigate.
This commit is contained in:
Nathan Vegdahl 2015-02-07 22:57:25 -08:00
parent 870818fec8
commit 8f94b32953
2 changed files with 19 additions and 7 deletions

View File

@ -296,17 +296,24 @@ impl<T: LineFormatter> Editor<T> {
/// Moves the editor's view the minimum amount to show the cursor /// Moves the editor's view the minimum amount to show the cursor
pub fn move_view_to_cursor(&mut self) { pub fn move_view_to_cursor(&mut self) {
// TODO: account for the horizontal offset of the editor view.
// TODO: handle multiple cursors properly. Should only move if // TODO: handle multiple cursors properly. Should only move if
// there are no cursors currently in view, and should jump to // there are no cursors currently in view, and should jump to
// the closest cursor. // the closest cursor.
//let gi = self.cursors[0].range.0; // Find the first and last grapheme index visible within the editor.
//let vho = self.cursors[0].vis_start; let g_first = self.formatter.index_set_horizontal_v2d(&self.buffer, self.view_pos.0, 0, Floor);
let mut g_last = self.formatter.index_offset_vertical_v2d(&self.buffer, g_first, (self.view_dim.0 - 1) as isize, (Floor, Floor));
//self.view_pos.0 = gi; g_last = self.formatter.index_set_horizontal_v2d(&self.buffer, g_last, self.view_dim.1, Floor);
// TODO: horizontal offset // Adjust the view depending on where the cursor is
//self.view_pos.1 = vho; if self.cursors[0].range.0 < g_first {
self.view_pos.0 = self.cursors[0].range.0;
}
else if self.cursors[0].range.0 > g_last {
self.view_pos.0 = self.formatter.index_offset_vertical_v2d(&self.buffer, self.cursors[0].range.0, -((self.view_dim.0 - 1) as isize), (Floor, Floor));
}
} }

View File

@ -94,7 +94,12 @@ pub trait LineFormatter {
let (v, _) = self.index_to_v2d(line, col_i); let (v, _) = self.index_to_v2d(line, col_i);
let mut new_col_i = self.v2d_to_index(line, (v, horizontal), (RoundingBehavior::Floor, rounding)); let mut new_col_i = self.v2d_to_index(line, (v, horizontal), (RoundingBehavior::Floor, rounding));
if new_col_i >= line.grapheme_count() && line.grapheme_count() > 0 {
// Make sure we're not pushing the index off the end of the line
if (line_i + 1) < buf.line_count()
&& new_col_i >= line.grapheme_count()
&& line.grapheme_count() > 0
{
new_col_i = line.grapheme_count() - 1; new_col_i = line.grapheme_count() - 1;
} }