on master help sign in
Fix overflow
2d629a8wojciechkepka
helix-term/src/ui/editor.rs+3−3
@@ -129,7 +129,7 @@ impl EditorView {
129 })],
129 })],
130 };
130 };
131 let mut spans = Vec::new();
131 let mut spans = Vec::new();
132− let mut visual_x = 0;
132+ let mut visual_x = 0u16;
133 let mut line = 0u16;
133 let mut line = 0u16;
134 let tab_width = doc.tab_width();
134 let tab_width = doc.tab_width();
135
135
@@ -185,7 +185,7 @@ impl EditorView {
185 break 'outer;
185 break 'outer;
186 }
186 }
187 } else if grapheme == "\t" {
187 } else if grapheme == "\t" {
188− visual_x += (tab_width as u16);
188+ visual_x = visual_x.saturating_add(tab_width as u16);
189 } else {
189 } else {
190 let out_of_bounds = visual_x < view.first_col as u16
190 let out_of_bounds = visual_x < view.first_col as u16
191 || visual_x >= viewport.width + view.first_col as u16;
191 || visual_x >= viewport.width + view.first_col as u16;
@@ -197,7 +197,7 @@ impl EditorView {
197
197
198 if out_of_bounds {
198 if out_of_bounds {
199 // if we're offscreen just keep going until we hit a new line
199 // 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);
201 continue;
201 continue;
202 }
202 }
203
203