Fixed a couple of bugs that crashed at tiny terminal sizes.
This commit is contained in:
parent
86ca5f9edf
commit
dbb640b330
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -89,20 +89,26 @@ impl Screen {
|
|||
}
|
||||
|
||||
pub(crate) fn draw(&self, x: usize, y: usize, text: &str, style: Style) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn hide_cursor(&self) {
|
||||
write!(self.out.borrow_mut(), "{}", termion::cursor::Hide).unwrap();
|
||||
|
|
Loading…
Reference in New Issue
Block a user