on master help sign in
Fix overflow
commit2d629a880cddec4938750b13bcd9926631c1db94 authorwojciechkepka <wojtek.kepka@protonmail.com> dateSat 19 Jun 2021, 21:33 (5 years ago) parent28d9673
1 file changed+3−3
helix-term/src/ui/editor.rs+3−3
helix-term/src/ui/editor.rs+3−3
@@ -129,7 +129,7 @@ impl EditorView {
129129 })],
130130 };
131131 let mut spans = Vec::new();
132− let mut visual_x = 0;
132+ let mut visual_x = 0u16;
133133 let mut line = 0u16;
134134 let tab_width = doc.tab_width();
135135
@@ -185,7 +185,7 @@ impl EditorView {
185185 break 'outer;
186186 }
187187 } else if grapheme == "\t" {
188− visual_x += (tab_width as u16);
188+ visual_x = visual_x.saturating_add(tab_width as u16);
189189 } else {
190190 let out_of_bounds = visual_x < view.first_col as u16
191191 || visual_x >= viewport.width + view.first_col as u16;
@@ -197,7 +197,7 @@ impl EditorView {
197197
198198 if out_of_bounds {
199199 // if we're offscreen just keep going until we hit a new line
200− visual_x += width;
200+ visual_x = visual_x.saturating_add(width);
201201 continue;
202202 }
203203