on master help sign in
Fix split sizes getting out of sync with the terminal size, refs #69
c0332bdBlaž Hrastnik
helix-term/src/compositor.rs+8−2
@@ -122,11 +122,17 @@ impl Compositor {
122 }
122 }
123
123
124 pub fn render(&mut self, cx: &mut Context) {
124 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
127
131
128 let surface = self.terminal.current_buffer_mut();
132 let surface = self.terminal.current_buffer_mut();
129
133
134+ let area = surface.area().clone();
135+
130 for layer in &self.layers {
136 for layer in &self.layers {
131 layer.render(area, surface, cx)
137 layer.render(area, surface, cx)
132 }
138 }
helix-term/src/ui/editor.rs+6−2
@@ -240,7 +240,7 @@ impl EditorView {
240 for selection in doc
240 for selection in doc
241 .selection(view.id)
241 .selection(view.id)
242 .iter()
242 .iter()
243− .filter(|range| range.overlaps(&screen))
243+ .filter(|range| screen.overlaps(&range))
244 {
244 {
245 // TODO: render also if only one of the ranges is in viewport
245 // TODO: render also if only one of the ranges is in viewport
246 let mut start = view.screen_coords_at_pos(doc, text, selection.anchor);
246 let mut start = view.screen_coords_at_pos(doc, text, selection.anchor);
@@ -261,7 +261,7 @@ impl EditorView {
261 Rect::new(
261 Rect::new(
262 viewport.x + start.col as u16,
262 viewport.x + start.col as u16,
263 viewport.y + start.row as u16,
263 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),
265 1,
265 1,
266 ),
266 ),
267 selection_style,
267 selection_style,
@@ -633,6 +633,10 @@ impl Component for EditorView {
633 // clear with background color
633 // clear with background color
634 surface.set_style(area, cx.editor.theme.get("ui.background"));
634 surface.set_style(area, cx.editor.theme.get("ui.background"));
635
635
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+
636 for (view, is_focused) in cx.editor.tree.views() {
640 for (view, is_focused) in cx.editor.tree.views() {
637 let doc = cx.editor.document(view.doc).unwrap();
641 let doc = cx.editor.document(view.doc).unwrap();
638 self.render_view(doc, view, area, surface, &cx.editor.theme, is_focused);
642 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 {
160 if let Some(doc) = (self.doc_fn)(&self.line) {
160 if let Some(doc) = (self.doc_fn)(&self.line) {
161 let text = ui::Text::new(doc.to_string());
161 let text = ui::Text::new(doc.to_string());
162
162
163+ let viewport = area;
164+ let area = viewport.intersection(Rect::new(
165+ completion_area.x,
163− let area = Rect::new(completion_area.x, completion_area.y - 3, BASE_WIDTH * 3, 3);
166+ completion_area.y - 3,
167+ BASE_WIDTH * 3,
168+ 3,
169+ ));
164
170
165 let background = theme.get("ui.help");
171 let background = theme.get("ui.help");
166 surface.clear_with(area, background);
172 surface.clear_with(area, background);
helix-tui/src/terminal.rs+2−2
@@ -137,12 +137,12 @@ where
137 }
137 }
138
138
139 /// Queries the backend for size and resizes if it doesn't match the previous size.
139 /// 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> {
141 let size = self.size()?;
141 let size = self.size()?;
142 if size != self.viewport.area {
142 if size != self.viewport.area {
143 self.resize(size)?;
143 self.resize(size)?;
144 };
144 };
145− Ok(())
145+ Ok(size)
146 }
146 }
147
147
148 /// Synchronizes terminal size, calls the rendering closure, flushes the current internal state
148 /// 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 {
194 }
194 }
195
195
196 pub fn resize(&mut self, area: Rect) {
196 pub fn resize(&mut self, area: Rect) {
197− self.tree.resize(area);
197+ if self.tree.resize(area) {
198− self._refresh();
198+ self._refresh();
199+ };
199 }
200 }
200
201
201 pub fn focus_next(&mut self) {
202 pub fn focus_next(&mut self) {
helix-view/src/tree.rs+7−3
@@ -293,9 +293,13 @@ impl Tree {
293 }
293 }
294 }
294 }
295
295
296− pub fn resize(&mut self, area: Rect) {
296+ pub fn resize(&mut self, area: Rect) -> bool {
297+ if self.area != area {
297− self.area = area;
298+ self.area = area;
298− self.recalculate();
299+ self.recalculate();
300+ return true;
301+ }
302+ false
299 }
303 }
300
304
301 pub fn recalculate(&mut self) {
305 pub fn recalculate(&mut self) {