on master help sign in
Work around rendering errors for positions offscreen.
commitc70080dd686738ab6272dd0b3c421c6621e86e34 authorBlaž Hrastnik <blaz@mxxn.io> dateFri 5 Feb 2021, 14:42 (6 years ago) parent8f0ddf9
2 files changed+33−12
helix-term/src/ui/editor.rs+18−8 helix-view/src/tree.rs+15−4
helix-term/src/ui/editor.rs+18−8
@@ -198,12 +198,16 @@ impl EditorView {
198198
199199 // TODO: paint cursor heads except primary
200200
201− surface.set_string(
202− viewport.x + visual_x,
203− viewport.y + line,
204− grapheme,
205− style,
206− );
201+ // HAXX: we don't render the char if it's offscreen. This should be
202+ // skipped in a better way much earlier
203+ if visual_x < viewport.width {
204+ surface.set_string(
205+ viewport.x + visual_x,
206+ viewport.y + line,
207+ grapheme,
208+ style,
209+ );
210+ }
207211
208212 visual_x += width;
209213 }
@@ -268,12 +272,18 @@ impl EditorView {
268272
269273 if let Some(path) = doc.relative_path() {
270274 let path = path.to_string_lossy();
271− surface.set_string(viewport.x + 6, viewport.y, path, text_color);
275+ surface.set_stringn(
276+ viewport.x + 6,
277+ viewport.y,
278+ path,
279+ viewport.width.saturating_sub(6) as usize,
280+ text_color,
281+ );
272282 // TODO: append [+] if modified
273283 }
274284
275285 surface.set_string(
276− viewport.x + viewport.width - 10,
286+ viewport.x + viewport.width.saturating_sub(10),
277287 viewport.y,
278288 format!("{}", doc.diagnostics.len()),
279289 text_color,
helix-view/src/tree.rs+15−4
@@ -152,16 +152,27 @@ impl Tree {
152152 match container.layout {
153153 Layout::Vertical => unimplemented!(),
154154 Layout::Horizontal => {
155− let len = container.children.len() as u16;
155+ let len = container.children.len();
156156
157− let width = area.width / len;
157+ let width = area.width / len as u16;
158158
159159 let mut child_x = area.x;
160160
161− for (_i, child) in container.children.iter().enumerate() {
162− let area = Rect::new(child_x, area.y, width, area.height);
161+ for (i, child) in container.children.iter().enumerate() {
162+ let mut area = Rect::new(
163+ child_x,
164+ container.area.y,
165+ width,
166+ container.area.height,
167+ );
163168 child_x += width;
164169
170+ // last child takes the remaining width because we can get uneven
171+ // space from rounding
172+ if i == len - 1 {
173+ area.width = container.area.x + container.area.width - area.x;
174+ }
175+
165176 self.stack.push((*child, area));
166177 }
167178 }