@@ -261,7 +261,16 @@ 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+ // .min is important, because set_style does a
265+ // for i in area.left()..area.right() and
266+ // area.right = x + width !!! which shouldn't be > then surface.area.right()
267+ // This is checked by a debug_assert! in Buffer::index_of
264− ((end.col - start.col) as u16 + 1).min(viewport.width),
268+ ((end.col - start.col) as u16 + 1).min(
272+ .saturating_sub(viewport.x + start.col as u16),
267 selection_style,
276 selection_style,
@@ -290,7 +299,12 @@ impl EditorView {
292 surface.set_style(
301 surface.set_style(
293− Rect::new(viewport.x, viewport.y + end.row as u16, end.col as u16, 1),
304+ viewport.y + end.row as u16,
305+ (end.col as u16).min(viewport.width),
294 selection_style,
308 selection_style,