Fix block-wise autoindent when editing adjacent ranges (#19521)
This fixes problems where auto-indent wasn't working correctly for assistant edits. Release Notes: - Fixed a bug where auto-indent didn't work correctly when pasting with multiple cursors on adjacent lines Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
parent
bae85d858e
commit
cb3eb75712
5 changed files with 161 additions and 31 deletions
|
@ -442,7 +442,7 @@ struct AutoindentRequest {
|
|||
is_block_mode: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Debug, Clone)]
|
||||
struct AutoindentRequestEntry {
|
||||
/// A range of the buffer whose indentation should be adjusted.
|
||||
range: Range<Anchor>,
|
||||
|
@ -1420,24 +1420,17 @@ impl Buffer {
|
|||
yield_now().await;
|
||||
}
|
||||
|
||||
// In block mode, only compute indentation suggestions for the first line
|
||||
// of each insertion. Otherwise, compute suggestions for every inserted line.
|
||||
let new_edited_row_ranges = contiguous_ranges(
|
||||
row_ranges.iter().flat_map(|(range, _)| {
|
||||
if request.is_block_mode {
|
||||
range.start..range.start + 1
|
||||
} else {
|
||||
range.clone()
|
||||
}
|
||||
}),
|
||||
max_rows_between_yields,
|
||||
);
|
||||
|
||||
// Compute new suggestions for each line, but only include them in the result
|
||||
// if they differ from the old suggestion for that line.
|
||||
let mut language_indent_sizes = language_indent_sizes_by_new_row.iter().peekable();
|
||||
let mut language_indent_size = IndentSize::default();
|
||||
for new_edited_row_range in new_edited_row_ranges {
|
||||
for (row_range, original_indent_column) in row_ranges {
|
||||
let new_edited_row_range = if request.is_block_mode {
|
||||
row_range.start..row_range.start + 1
|
||||
} else {
|
||||
row_range.clone()
|
||||
};
|
||||
|
||||
let suggestions = snapshot
|
||||
.suggest_autoindents(new_edited_row_range.clone())
|
||||
.into_iter()
|
||||
|
@ -1471,22 +1464,9 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
}
|
||||
yield_now().await;
|
||||
}
|
||||
|
||||
// For each block of inserted text, adjust the indentation of the remaining
|
||||
// lines of the block by the same amount as the first line was adjusted.
|
||||
if request.is_block_mode {
|
||||
for (row_range, original_indent_column) in
|
||||
row_ranges
|
||||
.into_iter()
|
||||
.filter_map(|(range, original_indent_column)| {
|
||||
if range.len() > 1 {
|
||||
Some((range, original_indent_column?))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
if let (true, Some(original_indent_column)) =
|
||||
(request.is_block_mode, original_indent_column)
|
||||
{
|
||||
let new_indent = indent_sizes
|
||||
.get(&row_range.start)
|
||||
|
@ -1511,6 +1491,8 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
yield_now().await;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue