From afa1a8f67cd4b4775ef9b5ba4a5d0132b3cfebe2 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sat, 31 Jan 2015 13:41:41 -0800 Subject: [PATCH] Fixed nasty bug in reformatting code. It was not actually reformatting things... --- src/buffer/mod.rs | 2 +- src/buffer/node.rs | 15 ++++++++++----- src/term_ui/mod.rs | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index ba903ba..ec95782 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -210,7 +210,7 @@ impl Buffer { /// Runs the formatter on all of the text. Should be run whenever the /// formatter has been changed. - pub fn reformat<'a>(&'a mut self) { + pub fn reformat(&mut self) { self.text.reformat_recursive(&self.formatter); } diff --git a/src/buffer/node.rs b/src/buffer/node.rs index 1925e2e..414d649 100644 --- a/src/buffer/node.rs +++ b/src/buffer/node.rs @@ -196,12 +196,17 @@ impl BufferNode { pub fn reformat_recursive(&mut self, f: &T) { - if let BufferNodeData::Branch(ref mut left, ref mut right) = self.data { - left.update_stats(f); - right.update_stats(f); + match self.data { + BufferNodeData::Branch(ref mut left, ref mut right) => { + left.reformat_recursive(f); + right.reformat_recursive(f); + self.vis_dim = ((left.vis_dim.0 + right.vis_dim.0), max(left.vis_dim.1, right.vis_dim.1)); + }, + + BufferNodeData::Leaf(ref line) => { + self.vis_dim = f.dimensions(line); + } } - - self.update_stats(f); } diff --git a/src/term_ui/mod.rs b/src/term_ui/mod.rs index 1d651fa..7b109e1 100644 --- a/src/term_ui/mod.rs +++ b/src/term_ui/mod.rs @@ -184,7 +184,7 @@ impl TermUI { 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 = w as usize; + self.editor.buffer.formatter.wrap_width = self.width; self.editor.buffer.reformat(); },