More fixing.

This commit is contained in:
Nathan Vegdahl 2017-12-30 23:47:05 -08:00
parent 9c302620e9
commit 47ed45aae6
4 changed files with 35 additions and 22 deletions

View File

@ -270,10 +270,17 @@ impl Buffer {
/// If the index is off the end of the text, returns the line and column
/// number of the last valid text position.
pub fn index_to_line_col(&self, pos: usize) -> (usize, usize) {
if pos < self.text.len_chars() {
let line = self.text.char_to_line(pos);
let line_pos = self.text.line_to_char(line);
return (line, pos - line_pos);
} else {
let line = self.text.len_lines() - 1;
let line_pos = self.text.line_to_char(line);
return (line, pos - line_pos);
}
}
/// Converts a line number and char-column number into a char

View File

@ -99,7 +99,10 @@ impl<T: LineFormatter> Editor<T> {
for line in self.buffer.line_iter() {
// Get the line ending
let ending = if line.len_chars() > 0 {
let g = line.slice(line.len_chars() - 1, line.len_chars()).graphemes().nth(0).unwrap();
let g = line.slice(line.len_chars() - 1, line.len_chars())
.graphemes()
.nth(0)
.unwrap();
str_to_line_ending(g)
} else {
LineEnding::None

View File

@ -40,8 +40,7 @@ pub fn is_whitespace(text: &str) -> bool {
| "\u{3000}" // IDEOGRAPHIC SPACE
| "\u{FEFF}" // ZERO WIDTH NO-BREAK SPACE
=> true,
_ => false
_ => false,
}
}

View File

@ -44,7 +44,7 @@ pub struct TermUI {
impl TermUI {
pub fn new() -> TermUI {
let rb = match rustbox::RustBox::init(rustbox::InitOptions {
buffer_stderr: false,
buffer_stderr: true,
..Default::default()
}) {
Ok(rbox) => rbox,
@ -65,7 +65,7 @@ impl TermUI {
pub fn new_from_editor(ed: Editor<ConsoleLineFormatter>) -> TermUI {
let rb = match rustbox::RustBox::init(rustbox::InitOptions {
buffer_stderr: false,
buffer_stderr: true,
..Default::default()
}) {
Ok(rbox) => rbox,
@ -406,13 +406,15 @@ impl TermUI {
.line_col_to_index((line_index, line_block_index * LINE_BLOCK_LENGTH));
let temp_line = editor.buffer.get_line(line_index);
let (vis_line_offset, _) = editor.formatter.index_to_v2d(
temp_line.slice(
temp_line
.slice(
line_block_index * LINE_BLOCK_LENGTH,
min(
temp_line.len_chars(),
(line_block_index + 1) * LINE_BLOCK_LENGTH,
),
).graphemes(),
)
.graphemes(),
editor.view_pos.0 - grapheme_index,
);
@ -451,9 +453,10 @@ impl TermUI {
let mut last_pos_y = 0;
let mut lines_traversed: usize = 0;
let line_len = line.len_chars();
let mut g_iter = editor
.formatter
.iter(line.slice(line_block_index * LINE_BLOCK_LENGTH, line_len).graphemes());
let mut g_iter = editor.formatter.iter(line.slice(
line_block_index * LINE_BLOCK_LENGTH,
line_len,
).graphemes());
loop {
if let Some((g, (pos_y, pos_x), width)) = g_iter.next() {
@ -552,9 +555,10 @@ impl TermUI {
line_block_index += 1;
line_g_index = 0;
let line_len = line.len_chars();
g_iter = editor
.formatter
.iter(line.slice(line_block_index * LINE_BLOCK_LENGTH, line_len).graphemes());
g_iter = editor.formatter.iter(line.slice(
line_block_index * LINE_BLOCK_LENGTH,
line_len,
).graphemes());
lines_traversed += 1;
}
}