Fixed a couple of bugs that crashed at tiny terminal sizes.

This commit is contained in:
Nathan Vegdahl 2018-01-01 12:59:47 -08:00
parent 86ca5f9edf
commit dbb640b330
3 changed files with 17 additions and 11 deletions

View File

@ -320,7 +320,7 @@ impl Buffer {
let l_start = self.text.line_to_char(pos.0); let l_start = self.text.line_to_char(pos.0);
let l_end = self.text.line_to_char(pos.0 + 1); let l_end = self.text.line_to_char(pos.0 + 1);
return (l_start + pos.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()); .min(self.text.len_chars());
} else { } else {
return self.text.len_chars(); return self.text.len_chars();

View File

@ -7,7 +7,7 @@ use buffer::Buffer;
// This is necessary to prevent pathological formatting cases which // This is necessary to prevent pathological formatting cases which
// could slow down the editor arbitrarily for arbitrarily long // could slow down the editor arbitrarily for arbitrarily long
// lines. // lines.
pub const LINE_BLOCK_LENGTH: usize = 4096; pub const LINE_BLOCK_LENGTH: usize = 1 << 12;
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
pub enum RoundingBehavior { pub enum RoundingBehavior {

View File

@ -89,16 +89,22 @@ impl Screen {
} }
pub(crate) fn draw(&self, x: usize, y: usize, text: &str, style: Style) { pub(crate) fn draw(&self, x: usize, y: usize, text: &str, style: Style) {
let mut buf = self.buf.borrow_mut(); if y < self.h {
let mut x = x; let mut buf = self.buf.borrow_mut();
for g in UnicodeSegmentation::graphemes(text, true) { let mut x = x;
let width = UnicodeWidthStr::width(g); for g in UnicodeSegmentation::graphemes(text, true) {
if width > 0 { let width = UnicodeWidthStr::width(g);
buf[y * self.w + x] = Some((style, g.into())); if width > 0 {
x += 1; if x < self.w {
for _ in 0..(width - 1) { buf[y * self.w + x] = Some((style, g.into()));
buf[y * self.w + x] = None; }
x += 1; x += 1;
for _ in 0..(width - 1) {
if x < self.w {
buf[y * self.w + x] = None;
}
x += 1;
}
} }
} }
} }