on master help sign in
Fix rendering of lines longer than 2^16

Before things would be cast to u16 earlier than needed, which would cause problems for insanely long lines (longer than 2^16 ~ 65 thousand)

commit3ba665d804c8d88bc3d59a52296f349acdb6d436 authorA-Walrus <ofek.r.guy@gmail.com> dateMon 10 Oct 2022, 11:13 (4 years ago) parent4e691d6
2 files changed+10−11
helix-term/src/ui/editor.rs+9−10 helix-view/src/editor.rs+1−1
helix-term/src/ui/editor.rs+9−10
@@ -428,7 +428,7 @@ impl EditorView {
428428 let characters = &whitespace.characters;
429429
430430 let mut spans = Vec::new();
431− let mut visual_x = 0u16;
431+ let mut visual_x = 0usize;
432432 let mut line = 0u16;
433433 let tab_width = doc.tab_width();
434434 let tab = if whitespace.render.tab() == WhitespaceRenderValue::All {
@@ -465,14 +465,13 @@ impl EditorView {
465465 return;
466466 }
467467
468− let starting_indent =
469− (offset.col / tab_width) as u16 + config.indent_guides.skip_levels;
468+ let starting_indent = (offset.col / tab_width) + config.indent_guides.skip_levels;
470469 // TODO: limit to a max indent level too. It doesn't cause visual artifacts but it would avoid some
471470 // extra loops if the code is deeply nested.
472471
473− for i in starting_indent..(indent_level / tab_width as u16) {
472+ for i in starting_indent..(indent_level / tab_width) {
474473 surface.set_string(
475− viewport.x + (i * tab_width as u16) - offset.col as u16,
474+ (viewport.x as usize + (i * tab_width) - offset.col) as u16,
476475 viewport.y + line,
477476 &indent_guide_char,
478477 indent_guide_style,
@@ -518,14 +517,14 @@ impl EditorView {
518517 use helix_core::graphemes::{grapheme_width, RopeGraphemes};
519518
520519 for grapheme in RopeGraphemes::new(text) {
521− let out_of_bounds = visual_x < offset.col as u16
522− || visual_x >= viewport.width + offset.col as u16;
520+ let out_of_bounds = offset.col > (visual_x as usize)
521+ || (visual_x as usize) >= viewport.width as usize + offset.col;
523522
524523 if LineEnding::from_rope_slice(&grapheme).is_some() {
525524 if !out_of_bounds {
526525 // we still want to render an empty cell with the style
527526 surface.set_string(
528− viewport.x + visual_x - offset.col as u16,
527+ (viewport.x as usize + visual_x - offset.col) as u16,
529528 viewport.y + line,
530529 &newline,
531530 style.patch(whitespace_style),
@@ -573,7 +572,7 @@ impl EditorView {
573572 if !out_of_bounds {
574573 // if we're offscreen just keep going until we hit a new line
575574 surface.set_string(
576− viewport.x + visual_x - offset.col as u16,
575+ (viewport.x as usize + visual_x - offset.col) as u16,
577576 viewport.y + line,
578577 display_grapheme,
579578 if is_whitespace {
@@ -606,7 +605,7 @@ impl EditorView {
606605 last_line_indent_level = visual_x;
607606 }
608607
609− visual_x = visual_x.saturating_add(width as u16);
608+ visual_x = visual_x.saturating_add(width);
610609 }
611610 }
612611 }
helix-view/src/editor.rs+1−1
@@ -558,7 +558,7 @@ impl Default for WhitespaceCharacters {
558558pub struct IndentGuidesConfig {
559559 pub render: bool,
560560 pub character: char,
561− pub skip_levels: u16,
561+ pub skip_levels: usize,
562562}
563563
564564impl Default for IndentGuidesConfig {