on master help sign in
Fix split sizes getting out of sync with the terminal size, refs #69
commitc0332bd935bb7c016278d43a526e588558a0cab1 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 3 Jun 2021, 10:28 (5 years ago) parent3c77299
6 files changed+33−12
helix-term/src/compositor.rs+8−2 helix-term/src/ui/editor.rs+6−2 helix-term/src/ui/prompt.rs+7−1 helix-tui/src/terminal.rs+2−2 helix-view/src/editor.rs+3−2 helix-view/src/tree.rs+7−3
helix-term/src/compositor.rs+8−2
@@ -122,11 +122,17 @@ impl Compositor {
122122 }
123123
124124 pub fn render(&mut self, cx: &mut Context) {
125− self.terminal.autoresize().unwrap();
126− let area = self.size();
125+ let area = self
126+ .terminal
127+ .autoresize()
128+ .expect("Unable to determine terminal size");
129+
130+ // TODO: need to recalculate view tree if necessary
127131
128132 let surface = self.terminal.current_buffer_mut();
129133
134+ let area = surface.area().clone();
135+
130136 for layer in &self.layers {
131137 layer.render(area, surface, cx)
132138 }
helix-term/src/ui/editor.rs+6−2
@@ -240,7 +240,7 @@ impl EditorView {
240240 for selection in doc
241241 .selection(view.id)
242242 .iter()
243− .filter(|range| range.overlaps(&screen))
243+ .filter(|range| screen.overlaps(&range))
244244 {
245245 // TODO: render also if only one of the ranges is in viewport
246246 let mut start = view.screen_coords_at_pos(doc, text, selection.anchor);
@@ -261,7 +261,7 @@ impl EditorView {
261261 Rect::new(
262262 viewport.x + start.col as u16,
263263 viewport.y + start.row as u16,
264− (end.col - start.col) as u16 + 1,
264+ ((end.col - start.col) as u16 + 1).min(viewport.width),
265265 1,
266266 ),
267267 selection_style,
@@ -633,6 +633,10 @@ impl Component for EditorView {
633633 // clear with background color
634634 surface.set_style(area, cx.editor.theme.get("ui.background"));
635635
636+ // if the terminal size suddenly changed, we need to trigger a resize
637+ cx.editor
638+ .resize(Rect::new(area.x, area.y, area.width, area.height - 1)); // - 1 to account for commandline
639+
636640 for (view, is_focused) in cx.editor.tree.views() {
637641 let doc = cx.editor.document(view.doc).unwrap();
638642 self.render_view(doc, view, area, surface, &cx.editor.theme, is_focused);
helix-term/src/ui/prompt.rs+7−1
@@ -160,7 +160,13 @@ impl Prompt {
160160 if let Some(doc) = (self.doc_fn)(&self.line) {
161161 let text = ui::Text::new(doc.to_string());
162162
163− let area = Rect::new(completion_area.x, completion_area.y - 3, BASE_WIDTH * 3, 3);
163+ let viewport = area;
164+ let area = viewport.intersection(Rect::new(
165+ completion_area.x,
166+ completion_area.y - 3,
167+ BASE_WIDTH * 3,
168+ 3,
169+ ));
164170
165171 let background = theme.get("ui.help");
166172 surface.clear_with(area, background);
helix-tui/src/terminal.rs+2−2
@@ -137,12 +137,12 @@ where
137137 }
138138
139139 /// Queries the backend for size and resizes if it doesn't match the previous size.
140− pub fn autoresize(&mut self) -> io::Result<()> {
140+ pub fn autoresize(&mut self) -> io::Result<Rect> {
141141 let size = self.size()?;
142142 if size != self.viewport.area {
143143 self.resize(size)?;
144144 };
145− Ok(())
145+ Ok(size)
146146 }
147147
148148 /// Synchronizes terminal size, calls the rendering closure, flushes the current internal state
helix-view/src/editor.rs+3−2
@@ -194,8 +194,9 @@ impl Editor {
194194 }
195195
196196 pub fn resize(&mut self, area: Rect) {
197− self.tree.resize(area);
198− self._refresh();
197+ if self.tree.resize(area) {
198+ self._refresh();
199+ };
199200 }
200201
201202 pub fn focus_next(&mut self) {
helix-view/src/tree.rs+7−3
@@ -293,9 +293,13 @@ impl Tree {
293293 }
294294 }
295295
296− pub fn resize(&mut self, area: Rect) {
297− self.area = area;
298− self.recalculate();
296+ pub fn resize(&mut self, area: Rect) -> bool {
297+ if self.area != area {
298+ self.area = area;
299+ self.recalculate();
300+ return true;
301+ }
302+ false
299303 }
300304
301305 pub fn recalculate(&mut self) {