WIP fixing cursor movement code.

This commit is contained in:
Nathan Vegdahl 2015-02-07 21:38:16 -08:00
parent 6fc2f34053
commit 27959dadf8

View File

@ -39,7 +39,7 @@ pub trait LineFormatter {
fn index_offset_vertical_v2d(&self, buf: &Buffer, index: usize, offset: isize, rounding: (RoundingBehavior, RoundingBehavior)) -> usize { fn index_offset_vertical_v2d(&self, buf: &Buffer, index: usize, offset: isize, rounding: (RoundingBehavior, RoundingBehavior)) -> usize {
// TODO: handle rounding modes // TODO: handle rounding modes
// TODO: do this with bidirectional line iterator // TODO: do this with bidirectional line iterator
let (mut line_i, col_i) = buf.index_to_line_col(index); let (mut line_i, mut col_i) = buf.index_to_line_col(index);
let (mut y, x) = self.index_to_v2d(buf.get_line(line_i), col_i); let (mut y, x) = self.index_to_v2d(buf.get_line(line_i), col_i);
let mut new_y = y as isize + offset; let mut new_y = y as isize + offset;
@ -54,7 +54,7 @@ pub trait LineFormatter {
break; break;
} }
else { else {
if new_y < 0 { if new_y > 0 {
// Check for off-the-end // Check for off-the-end
if (line_i + 1) >= buf.line_count() { if (line_i + 1) >= buf.line_count() {
return buf.grapheme_count(); return buf.grapheme_count();
@ -63,14 +63,16 @@ pub trait LineFormatter {
line_i += 1; line_i += 1;
new_y -= h as isize; new_y -= h as isize;
} }
else if new_y > 0 { else if new_y < 0 {
// Check for off-the-end // Check for off-the-end
if line_i == 0 { if line_i == 0 {
return 0; return 0;
} }
line_i -= 1; line_i -= 1;
new_y -= h as isize; line = buf.get_line(line_i);
let (h, _) = self.dimensions(line);
new_y += h as isize;
} }
else { else {
unreachable!(); unreachable!();
@ -80,7 +82,10 @@ pub trait LineFormatter {
// Next, convert the resulting coordinates back into buffer-wide // Next, convert the resulting coordinates back into buffer-wide
// coordinates. // coordinates.
let col_i = self.v2d_to_index(line, (y, x), rounding); col_i = self.v2d_to_index(line, (y, x), rounding);
//if col_i >= line.grapheme_count() && line.grapheme_count() > 0 {
// col_i = line.grapheme_count() - 1;
//}
return buf.line_col_to_index((line_i, col_i)); return buf.line_col_to_index((line_i, col_i));
} }