Fix panic folding in multi-buffers (#21511)
Closes #19054 Rename `max_buffer_row()` to `widest_line_number()` to (hopefully) prevent people assuming it means the same as `max_point().row`. Release Notes: - Fixed a panic when folding in a multibuffer
This commit is contained in:
parent
e231321655
commit
196fd65601
10 changed files with 46 additions and 40 deletions
|
@ -136,7 +136,7 @@ pub fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
|
|||
vim.update_editor(cx, |vim, editor, cx| {
|
||||
let snapshot = editor.snapshot(cx);
|
||||
if let Ok(range) = action.range.buffer_range(vim, editor, cx) {
|
||||
let end = if range.end < snapshot.max_buffer_row() {
|
||||
let end = if range.end < snapshot.buffer_snapshot.max_row() {
|
||||
Point::new(range.end.0 + 1, 0)
|
||||
} else {
|
||||
snapshot.buffer_snapshot.max_point()
|
||||
|
@ -436,9 +436,11 @@ impl Position {
|
|||
.row
|
||||
.saturating_add_signed(*offset)
|
||||
}
|
||||
Position::LastLine { offset } => {
|
||||
snapshot.max_buffer_row().0.saturating_add_signed(*offset)
|
||||
}
|
||||
Position::LastLine { offset } => snapshot
|
||||
.buffer_snapshot
|
||||
.max_row()
|
||||
.0
|
||||
.saturating_add_signed(*offset),
|
||||
Position::CurrentLine { offset } => editor
|
||||
.selections
|
||||
.newest_anchor()
|
||||
|
@ -448,7 +450,7 @@ impl Position {
|
|||
.saturating_add_signed(*offset),
|
||||
};
|
||||
|
||||
Ok(MultiBufferRow(target).min(snapshot.max_buffer_row()))
|
||||
Ok(MultiBufferRow(target).min(snapshot.buffer_snapshot.max_row()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1866,7 +1866,7 @@ fn end_of_document(
|
|||
let new_row = if let Some(line) = line {
|
||||
(line - 1) as u32
|
||||
} else {
|
||||
map.max_buffer_row().0
|
||||
map.buffer_snapshot.max_row().0
|
||||
};
|
||||
|
||||
let new_point = Point::new(new_row, point.column());
|
||||
|
|
|
@ -154,9 +154,9 @@ impl Vim {
|
|||
// contains a newline (so that delete works as expected). We undo that change
|
||||
// here.
|
||||
let is_last_line = linewise
|
||||
&& end.row == buffer.max_buffer_row().0
|
||||
&& end.row == buffer.max_row().0
|
||||
&& buffer.max_point().column > 0
|
||||
&& start.row < buffer.max_buffer_row().0
|
||||
&& start.row < buffer.max_row().0
|
||||
&& start == Point::new(start.row, buffer.line_len(MultiBufferRow(start.row)));
|
||||
|
||||
if is_last_line {
|
||||
|
|
|
@ -724,7 +724,7 @@ fn indent(
|
|||
|
||||
// Loop forwards until we find a non-blank line with less indent
|
||||
let mut end_row = row;
|
||||
let max_rows = map.max_buffer_row().0;
|
||||
let max_rows = map.buffer_snapshot.max_row().0;
|
||||
for next_row in (row + 1)..=max_rows {
|
||||
let indent = map.line_indent_for_buffer_row(MultiBufferRow(next_row));
|
||||
if indent.is_line_empty() {
|
||||
|
@ -958,13 +958,13 @@ pub fn start_of_paragraph(map: &DisplaySnapshot, display_point: DisplayPoint) ->
|
|||
/// The trailing newline is excluded from the paragraph.
|
||||
pub fn end_of_paragraph(map: &DisplaySnapshot, display_point: DisplayPoint) -> DisplayPoint {
|
||||
let point = display_point.to_point(map);
|
||||
if point.row == map.max_buffer_row().0 {
|
||||
if point.row == map.buffer_snapshot.max_row().0 {
|
||||
return map.max_point();
|
||||
}
|
||||
|
||||
let is_current_line_blank = map.buffer_snapshot.is_line_blank(MultiBufferRow(point.row));
|
||||
|
||||
for row in point.row + 1..map.max_buffer_row().0 + 1 {
|
||||
for row in point.row + 1..map.buffer_snapshot.max_row().0 + 1 {
|
||||
let blank = map.buffer_snapshot.is_line_blank(MultiBufferRow(row));
|
||||
if blank != is_current_line_blank {
|
||||
let previous_row = row - 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue