editor: Fix rewrap with a non-empty selection (#17980)

This PR fixes an issue where rewrapping would not occur with a non-empty
selection.

It is only the expansion to neighboring lines that needs to be gated by
an empty selection.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2024-09-17 19:20:45 -04:00
committed by GitHub
parent fbb402ef12
commit 4d074fc737
2 changed files with 48 additions and 15 deletions
+15 -15
View File
@@ -6736,22 +6736,22 @@ impl Editor {
let mut line_prefix = indent_size.chars().collect::<String>();
if selection.is_empty() {
if let Some(comment_prefix) =
buffer
.language_scope_at(selection.head())
.and_then(|language| {
language
.line_comment_prefixes()
.iter()
.find(|prefix| buffer.contains_str_at(indent_end, prefix))
.cloned()
})
{
line_prefix.push_str(&comment_prefix);
should_rewrap = true;
}
if let Some(comment_prefix) =
buffer
.language_scope_at(selection.head())
.and_then(|language| {
language
.line_comment_prefixes()
.iter()
.find(|prefix| buffer.contains_str_at(indent_end, prefix))
.cloned()
})
{
line_prefix.push_str(&comment_prefix);
should_rewrap = true;
}
if selection.is_empty() {
'expand_upwards: while start_row > 0 {
let prev_row = start_row - 1;
if buffer.contains_str_at(Point::new(prev_row, 0), &line_prefix)