editor: Fix regression causing incorrect delimiter on newline in case of multiple comment prefixes (#31129)
Closes #31115 This fixes regression caused by https://github.com/zed-industries/zed/pull/30824 while keeping that fix. - [x] Test Release Notes: - Fixed the issue where adding a newline after the `///` comment would extend it with `//` instead of `///` in Rust and other similar languages.
This commit is contained in:
parent
b829f72c17
commit
8742d4ab90
2 changed files with 45 additions and 6 deletions
|
@ -3964,15 +3964,18 @@ impl Editor {
|
|||
.skip(num_of_whitespaces)
|
||||
.take(max_len_of_delimiter)
|
||||
.collect::<String>();
|
||||
let (delimiter, trimmed_len) =
|
||||
delimiters.iter().find_map(|delimiter| {
|
||||
let trimmed = delimiter.trim_end();
|
||||
if comment_candidate.starts_with(trimmed) {
|
||||
Some((delimiter, trimmed.len()))
|
||||
let (delimiter, trimmed_len) = delimiters
|
||||
.iter()
|
||||
.filter_map(|delimiter| {
|
||||
let prefix = delimiter.trim_end();
|
||||
if comment_candidate.starts_with(prefix) {
|
||||
Some((delimiter, prefix.len()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})?;
|
||||
})
|
||||
.max_by_key(|(_, len)| *len)?;
|
||||
|
||||
let cursor_is_placed_after_comment_marker =
|
||||
num_of_whitespaces + trimmed_len <= start_point.column as usize;
|
||||
if cursor_is_placed_after_comment_marker {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue