Fixed bug with gutter size not updating as line numbers get wider.
This commit is contained in:
parent
db5f6c7e64
commit
75742c7aa4
|
@ -248,22 +248,26 @@ impl<T: LineFormatter> Editor<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update_dim(&mut self, h: usize, w: usize) {
|
||||
self.editor_dim = (h, w);
|
||||
self.update_view_dim();
|
||||
}
|
||||
|
||||
pub fn update_view_dim(&mut self) {
|
||||
// TODO: generalize for non-terminal UI. Maybe this isn't where it
|
||||
// belongs, in fact. But for now, this is the easiest place to put
|
||||
// it.
|
||||
/// Updates the view dimensions, and returns whether that
|
||||
/// actually changed anything.
|
||||
pub fn update_dim(&mut self, h: usize, w: usize) -> bool {
|
||||
let line_count_digits = digit_count(self.buffer.line_count() as u32, 10) as usize;
|
||||
// Minus 1 vertically for the header, minus one more than the digits in
|
||||
// the line count for the gutter.
|
||||
self.view_dim = (
|
||||
self.editor_dim.0 - 1,
|
||||
self.editor_dim.1 - line_count_digits - 1,
|
||||
);
|
||||
if self.editor_dim.0 != h || self.editor_dim.1 != w {
|
||||
self.editor_dim = (h, w);
|
||||
|
||||
// Minus 1 vertically for the header, minus one more than the digits in
|
||||
// the line count for the gutter.
|
||||
self.view_dim = (
|
||||
self.editor_dim.0 - 1,
|
||||
self.editor_dim.1 - line_count_digits - 1,
|
||||
);
|
||||
return true;
|
||||
} else if self.view_dim.1 != (self.editor_dim.1 - line_count_digits - 1) {
|
||||
self.view_dim.1 = self.editor_dim.1 - line_count_digits - 1;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn undo(&mut self) {
|
||||
|
|
|
@ -59,18 +59,17 @@ macro_rules! ui_loop {
|
|||
|
||||
// Check for screen resize
|
||||
let (w, h) = termion::terminal_size().unwrap();
|
||||
if $term_ui.width != w as usize || $term_ui.height != h as usize {
|
||||
let needs_update = $term_ui
|
||||
.editor
|
||||
.update_dim(h as usize - 1, w as usize);
|
||||
if needs_update {
|
||||
$term_ui.width = w as usize;
|
||||
$term_ui.height = h as usize;
|
||||
$term_ui
|
||||
.editor
|
||||
.update_dim($term_ui.height - 1, $term_ui.width);
|
||||
$term_ui.editor.update_view_dim();
|
||||
$term_ui.screen.resize(w as usize, h as usize);
|
||||
$term_ui
|
||||
.editor
|
||||
.formatter
|
||||
.set_wrap_width($term_ui.editor.view_dim.1);
|
||||
$term_ui.screen.resize(w as usize, h as usize);
|
||||
should_redraw = true;
|
||||
}
|
||||
|
||||
|
@ -132,7 +131,6 @@ impl TermUI {
|
|||
self.width = w as usize;
|
||||
self.height = h as usize;
|
||||
self.editor.update_dim(self.height - 1, self.width);
|
||||
self.editor.update_view_dim();
|
||||
self.editor.formatter.set_wrap_width(self.editor.view_dim.1);
|
||||
self.screen.resize(w as usize, h as usize);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user