diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 64df487..663afc1 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -320,7 +320,7 @@ impl Buffer { let l_start = self.text.line_to_char(pos.0); let l_end = self.text.line_to_char(pos.0 + 1); return (l_start + pos.1) - .min(l_start.max(l_end - 1)) + .min(l_start.max(l_end - 1.min(l_end))) .min(self.text.len_chars()); } else { return self.text.len_chars(); diff --git a/src/formatter.rs b/src/formatter.rs index 636aed3..7b4fecd 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -7,7 +7,7 @@ use buffer::Buffer; // This is necessary to prevent pathological formatting cases which // could slow down the editor arbitrarily for arbitrarily long // lines. -pub const LINE_BLOCK_LENGTH: usize = 4096; +pub const LINE_BLOCK_LENGTH: usize = 1 << 12; #[derive(Copy, Clone, PartialEq)] pub enum RoundingBehavior { diff --git a/src/term_ui/screen.rs b/src/term_ui/screen.rs index 0929f81..d647f8e 100644 --- a/src/term_ui/screen.rs +++ b/src/term_ui/screen.rs @@ -89,16 +89,22 @@ impl Screen { } pub(crate) fn draw(&self, x: usize, y: usize, text: &str, style: Style) { - let mut buf = self.buf.borrow_mut(); - let mut x = x; - for g in UnicodeSegmentation::graphemes(text, true) { - let width = UnicodeWidthStr::width(g); - if width > 0 { - buf[y * self.w + x] = Some((style, g.into())); - x += 1; - for _ in 0..(width - 1) { - buf[y * self.w + x] = None; + if y < self.h { + let mut buf = self.buf.borrow_mut(); + let mut x = x; + for g in UnicodeSegmentation::graphemes(text, true) { + let width = UnicodeWidthStr::width(g); + if width > 0 { + if x < self.w { + buf[y * self.w + x] = Some((style, g.into())); + } x += 1; + for _ in 0..(width - 1) { + if x < self.w { + buf[y * self.w + x] = None; + } + x += 1; + } } } }