From 5f62f69907676e9d52f58a69c0dc38a532ccb15a Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Thu, 10 Mar 2022 20:04:16 -0800 Subject: [PATCH] Add unwrap check if buffer_line not available --- crates/editor/src/editor.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 4d49fb71496864e7e1936f2608ba6557525c86d1..05443553591d9c5eb00d962122ef464c622cfb1c 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -2639,21 +2639,22 @@ impl Editor { for selection in &mut selections { if selection.is_empty() { let old_head = selection.head(); - let (buffer, line_buffer_range) = display_map - .buffer_snapshot - .buffer_line_for_row(old_head.row) - .unwrap(); - let indent_column = buffer.indent_column_for_line(line_buffer_range.start.row); let mut new_head = movement::left(&display_map, old_head.to_display_point(&display_map)) .unwrap() .to_point(&display_map); - if old_head.column <= indent_column && old_head.column > 0 { - let indent = buffer.indent_size(); - new_head = cmp::min( - new_head, - Point::new(old_head.row, ((old_head.column - 1) / indent) * indent), - ); + if let Some((buffer, line_buffer_range)) = display_map + .buffer_snapshot + .buffer_line_for_row(old_head.row) + { + let indent_column = buffer.indent_column_for_line(line_buffer_range.start.row); + if old_head.column <= indent_column && old_head.column > 0 { + let indent = buffer.indent_size(); + new_head = cmp::min( + new_head, + Point::new(old_head.row, ((old_head.column - 1) / indent) * indent), + ); + } } selection.set_head(new_head);