Line wrapping width is now determined by terminal width.

This commit is contained in:
Nathan Vegdahl 2015-01-31 13:19:14 -08:00
parent 8701ebbba7
commit 7b87db4e41
4 changed files with 25 additions and 2 deletions

View File

@ -208,6 +208,15 @@ impl<T: LineFormatter> Buffer<T> {
}
/// Runs the formatter on all of the text. Should be run whenever the
/// formatter has been changed.
pub fn reformat<'a>(&'a mut self) {
self.text.reformat_recursive(&self.formatter);
}
//------------------------------------------------------------------------
// Undo/redo functionality

View File

@ -195,6 +195,16 @@ impl BufferNode {
}
pub fn reformat_recursive<T: LineFormatter>(&mut self, f: &T) {
if let BufferNodeData::Branch(ref mut left, ref mut right) = self.data {
left.update_stats(f);
right.update_stats(f);
}
self.update_stats(f);
}
pub fn get_grapheme_recursive<'a>(&'a self, index: usize) -> &'a str {
match self.data {
BufferNodeData::Leaf(ref line) => {

View File

@ -83,6 +83,8 @@ impl TermUI {
let mut quit = false;
self.editor.update_dim(self.height-1, self.width);
self.editor.buffer.formatter.wrap_width = self.width as usize;
self.editor.buffer.reformat();
loop {
// Draw the editor to screen
@ -182,6 +184,8 @@ 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.reformat();
},
_ => {

View File

@ -15,8 +15,8 @@
The freetype formatter should not reference SDL at all, and should
have only the freetype library itself as a dependency.
//- Handle tab settings properly after the refactor
- Buffer needs a "reformat" method, which can be run after the formatter
is changed in some way (e.g. toggling line wrapping).
//- Buffer needs a "reformat" method, which can be run after the formatter
// is changed in some way (e.g. toggling line wrapping).
- Possibly split the text buffer out into its own library...? Would
likely be useful to other people as well, and would encourage me to
keep the API clean.