Yet more bug fixes. Getting pretty close to fully functional again.
This commit is contained in:
parent
d7d7b7cd2b
commit
6e239a3c92
|
@ -299,27 +299,27 @@ impl Editor {
|
||||||
|
|
||||||
/// 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) {
|
||||||
// // Find the first and last char index visible within the editor.
|
// Find the first and last char index visible within the editor.
|
||||||
// let c_first = self
|
let c_first = self
|
||||||
// .formatter
|
.formatter
|
||||||
// .set_horizontal(&self.buffer, self.view_pos.0, 0);
|
.set_horizontal(&self.buffer, self.view_pos.0, 0);
|
||||||
// let mut c_last =
|
let mut c_last =
|
||||||
// self.formatter
|
self.formatter
|
||||||
// .offset_vertical(&self.buffer, c_first, self.view_dim.0 as isize);
|
.offset_vertical(&self.buffer, c_first, self.view_dim.0 as isize);
|
||||||
// c_last = self
|
c_last = self
|
||||||
// .formatter
|
.formatter
|
||||||
// .set_horizontal(&self.buffer, c_last, self.view_dim.1);
|
.set_horizontal(&self.buffer, c_last, self.view_dim.1);
|
||||||
|
|
||||||
// // Adjust the view depending on where the cursor is
|
// Adjust the view depending on where the cursor is
|
||||||
// if self.cursors[0].range.0 < c_first {
|
if self.cursors[0].range.0 < c_first {
|
||||||
// self.view_pos.0 = self.cursors[0].range.0;
|
self.view_pos.0 = self.cursors[0].range.0;
|
||||||
// } else if self.cursors[0].range.0 > c_last {
|
} else if self.cursors[0].range.0 > c_last {
|
||||||
// self.view_pos.0 = self.formatter.offset_vertical(
|
self.view_pos.0 = self.formatter.offset_vertical(
|
||||||
// &self.buffer,
|
&self.buffer,
|
||||||
// self.cursors[0].range.0,
|
self.cursors[0].range.0,
|
||||||
// -(self.view_dim.0 as isize),
|
-(self.view_dim.0 as isize),
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_text_at_cursor(&mut self, text: &str) {
|
pub fn insert_text_at_cursor(&mut self, text: &str) {
|
||||||
|
@ -545,9 +545,9 @@ impl Editor {
|
||||||
let mut temp_index = self
|
let mut temp_index = self
|
||||||
.formatter
|
.formatter
|
||||||
.offset_vertical(&self.buffer, c.range.0, vmove);
|
.offset_vertical(&self.buffer, c.range.0, vmove);
|
||||||
// temp_index = self
|
temp_index = self
|
||||||
// .formatter
|
.formatter
|
||||||
// .set_horizontal(&self.buffer, temp_index, c.vis_start);
|
.set_horizontal(&self.buffer, temp_index, c.vis_start);
|
||||||
|
|
||||||
if !self.buffer.is_grapheme(temp_index) {
|
if !self.buffer.is_grapheme(temp_index) {
|
||||||
temp_index = self.buffer.nth_prev_grapheme(temp_index, 1);
|
temp_index = self.buffer.nth_prev_grapheme(temp_index, 1);
|
||||||
|
@ -575,9 +575,9 @@ impl Editor {
|
||||||
let mut temp_index = self
|
let mut temp_index = self
|
||||||
.formatter
|
.formatter
|
||||||
.offset_vertical(&self.buffer, c.range.0, vmove);
|
.offset_vertical(&self.buffer, c.range.0, vmove);
|
||||||
// temp_index = self
|
temp_index = self
|
||||||
// .formatter
|
.formatter
|
||||||
// .set_horizontal(&self.buffer, temp_index, c.vis_start);
|
.set_horizontal(&self.buffer, temp_index, c.vis_start);
|
||||||
|
|
||||||
if !self.buffer.is_grapheme(temp_index) {
|
if !self.buffer.is_grapheme(temp_index) {
|
||||||
temp_index = self.buffer.nth_prev_grapheme(temp_index, 1);
|
temp_index = self.buffer.nth_prev_grapheme(temp_index, 1);
|
||||||
|
|
|
@ -107,7 +107,7 @@ impl LineFormatter {
|
||||||
// wasn't long enough, so return the index of the last grapheme
|
// wasn't long enough, so return the index of the last grapheme
|
||||||
// of the previous line.
|
// of the previous line.
|
||||||
if i > char_offset {
|
if i > char_offset {
|
||||||
return last_i;
|
return char_idx - char_offset + last_i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise reset and keep going.
|
// Otherwise reset and keep going.
|
||||||
|
@ -123,7 +123,7 @@ impl LineFormatter {
|
||||||
// Check if we've found the horizontal position _and_ the passed
|
// Check if we've found the horizontal position _and_ the passed
|
||||||
// char_idx on the same line, and return if so.
|
// char_idx on the same line, and return if so.
|
||||||
if i >= char_offset && hpos_char_idx != None {
|
if i >= char_offset && hpos_char_idx != None {
|
||||||
return hpos_char_idx.unwrap();
|
return char_idx - char_offset + hpos_char_idx.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
last_pos = pos;
|
last_pos = pos;
|
||||||
|
@ -132,7 +132,13 @@ impl LineFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reached the end of the text, return the last char index.
|
// If we reached the end of the text, return the last char index.
|
||||||
return i;
|
let end_i = char_idx - char_offset + i;
|
||||||
|
let end_last_i = char_idx - char_offset + last_i;
|
||||||
|
if buf.text.len_chars() == end_i {
|
||||||
|
return end_i;
|
||||||
|
} else {
|
||||||
|
return end_last_i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Takes a char index and a visual vertical offset, and returns the char
|
/// Takes a char index and a visual vertical offset, and returns the char
|
||||||
|
|
Loading…
Reference in New Issue
Block a user