Line wrapping width is now determined by terminal width.
This commit is contained in:
parent
8701ebbba7
commit
7b87db4e41
|
@ -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
|
// Undo/redo functionality
|
||||||
|
|
|
@ -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 {
|
pub fn get_grapheme_recursive<'a>(&'a self, index: usize) -> &'a str {
|
||||||
match self.data {
|
match self.data {
|
||||||
BufferNodeData::Leaf(ref line) => {
|
BufferNodeData::Leaf(ref line) => {
|
||||||
|
|
|
@ -83,6 +83,8 @@ impl TermUI {
|
||||||
let mut quit = false;
|
let mut quit = false;
|
||||||
|
|
||||||
self.editor.update_dim(self.height-1, self.width);
|
self.editor.update_dim(self.height-1, self.width);
|
||||||
|
self.editor.buffer.formatter.wrap_width = self.width as usize;
|
||||||
|
self.editor.buffer.reformat();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Draw the editor to screen
|
// Draw the editor to screen
|
||||||
|
@ -182,6 +184,8 @@ impl TermUI {
|
||||||
self.width = w as usize;
|
self.width = w as usize;
|
||||||
self.height = h as usize;
|
self.height = h as usize;
|
||||||
self.editor.update_dim(self.height-1, self.width);
|
self.editor.update_dim(self.height-1, self.width);
|
||||||
|
self.editor.buffer.formatter.wrap_width = w as usize;
|
||||||
|
self.editor.buffer.reformat();
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
|
4
todo.md
4
todo.md
|
@ -15,8 +15,8 @@
|
||||||
The freetype formatter should not reference SDL at all, and should
|
The freetype formatter should not reference SDL at all, and should
|
||||||
have only the freetype library itself as a dependency.
|
have only the freetype library itself as a dependency.
|
||||||
//- Handle tab settings properly after the refactor
|
//- Handle tab settings properly after the refactor
|
||||||
- Buffer needs a "reformat" method, which can be run after the formatter
|
//- Buffer needs a "reformat" method, which can be run after the formatter
|
||||||
is changed in some way (e.g. toggling line wrapping).
|
// is changed in some way (e.g. toggling line wrapping).
|
||||||
- Possibly split the text buffer out into its own library...? Would
|
- Possibly split the text buffer out into its own library...? Would
|
||||||
likely be useful to other people as well, and would encourage me to
|
likely be useful to other people as well, and would encourage me to
|
||||||
keep the API clean.
|
keep the API clean.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user