Improved window resizing responsiveness.

The reformat code was being run on every resize event,
which chokes on most resizes which end up emitting a lot
of resize events.  Now it waits and processes a bunch of
resize events until there aren't any left, and only does
the actual reformat on the last one.
This commit is contained in:
Nathan Vegdahl 2015-02-01 13:50:47 -08:00
parent c9d09f6f98
commit 4d114162ee

View File

@ -81,6 +81,7 @@ impl TermUI {
pub fn main_ui_loop(&mut self) {
// Quitting flag
let mut quit = false;
let mut resize: Option<(usize, usize)> = None;
self.editor.update_dim(self.height-1, self.width);
self.editor.buffer.formatter.wrap_width = self.width as usize;
@ -181,11 +182,7 @@ impl TermUI {
},
Ok(rustbox::Event::ResizeEvent(w, h)) => {
self.width = w as usize;
self.height = h as usize;
self.editor.update_dim(self.height-1, self.width);
self.editor.buffer.formatter.wrap_width = self.width;
self.editor.buffer.reformat();
resize = Some((h as usize, w as usize));
},
_ => {
@ -196,6 +193,15 @@ impl TermUI {
e = self.rb.peek_event(Duration::milliseconds(0)); // Get next event (if any)
}
if let Some((h, w)) = resize {
self.width = w as usize;
self.height = h as usize;
self.editor.update_dim(self.height-1, self.width);
self.editor.buffer.formatter.wrap_width = self.width;
self.editor.buffer.reformat();
println!("Resized window!");
}
resize = None;
// Quit if quit flag is set
if quit {