fixup: work on rewrapping block comments in selections

This commit is contained in:
Clayton Carter 2025-08-14 09:36:15 -04:00
parent 619a142e3d
commit e246758be4
2 changed files with 174 additions and 1 deletions

View file

@ -12003,7 +12003,7 @@ impl Editor {
let line_trimmed = line_trimmed let line_trimmed = line_trimmed
.strip_prefix(start.as_ref()) .strip_prefix(start.as_ref())
.map(|s| { .map(|s| {
let mut indent_size = indent_size.clone(); let mut indent_size = indent_size;
indent_size.len -= tab_size; indent_size.len -= tab_size;
let indent_prefix: String = indent_size.chars().collect(); let indent_prefix: String = indent_size.chars().collect();
first_line_delimiter = Some((indent_prefix, start)); first_line_delimiter = Some((indent_prefix, start));

View file

@ -5954,6 +5954,164 @@ async fn test_rewrap_block_comments(cx: &mut TestAppContext) {
&mut cx, &mut cx,
); );
// selection w/ single short block comment
assert_rewrap(
indoc! {"
«/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */ˇ»
"},
indoc! {"
«/*
* Lorem ipsum dolor sit amet,
* consectetur adipiscing elit.
*/ˇ»
"},
rust_lang.clone(),
&mut cx,
);
// rewrapping a single comment w/ abutting comments
assert_rewrap(
indoc! {"
/* ˇLorem ipsum dolor sit amet, consectetur adipiscing elit. */
/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */
"},
indoc! {"
/*
* ˇLorem ipsum dolor sit amet,
* consectetur adipiscing elit.
*/
/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */
"},
rust_lang.clone(),
&mut cx,
);
// selection w/ non-abutting short block comments
assert_rewrap(
indoc! {"
«/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */
/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */ˇ»
"},
indoc! {"
«/*
* Lorem ipsum dolor sit amet,
* consectetur adipiscing elit.
*/
/*
* Lorem ipsum dolor sit amet,
* consectetur adipiscing elit.
*/ˇ»
"},
rust_lang.clone(),
&mut cx,
);
// selection of multiline block comments
assert_rewrap(
indoc! {"
«/* Lorem ipsum dolor sit amet,
* consectetur adipiscing elit. */ˇ»
"},
indoc! {"
«/*
* Lorem ipsum dolor sit amet,
* consectetur adipiscing elit.
*/ˇ»
"},
rust_lang.clone(),
&mut cx,
);
// partial selection of multiline block comments
assert_rewrap(
indoc! {"
«/* Lorem ipsum dolor sit amet,ˇ»
* consectetur adipiscing elit. */
/* Lorem ipsum dolor sit amet,
«* consectetur adipiscing elit. */ˇ»
"},
indoc! {"
«/*
* Lorem ipsum dolor sit amet,ˇ»
* consectetur adipiscing elit. */
/* Lorem ipsum dolor sit amet,
«* consectetur adipiscing elit.
*/ˇ»
"},
rust_lang.clone(),
&mut cx,
);
// selection w/ abutting short block comments
// FIXME unhandled edge case; not correct, just documenting known issues
// should not be combined; should rewrap as 2 comments
assert_rewrap(
indoc! {"
«/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */
/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */ˇ»
"},
// desired behavior:
// indoc! {"
// «/*
// * Lorem ipsum dolor sit amet,
// * consectetur adipiscing elit.
// */
// /*
// * Lorem ipsum dolor sit amet,
// * consectetur adipiscing elit.
// */ˇ»
// "},
// actual behaviour:
indoc! {"
«/*
* Lorem ipsum dolor sit amet,
* consectetur adipiscing elit. Lorem
* ipsum dolor sit amet, consectetur
* adipiscing elit.
*/ˇ»
"},
rust_lang.clone(),
&mut cx,
);
// FIXME same as above, but with delimiters on separate line
// assert_rewrap(
// indoc! {"
// «/* Lorem ipsum dolor sit amet, consectetur adipiscing elit.
// */
// /*
// * Lorem ipsum dolor sit amet, consectetur adipiscing elit. */ˇ»
// "},
// // desired:
// // indoc! {"
// // «/*
// // * Lorem ipsum dolor sit amet,
// // * consectetur adipiscing elit.
// // */
// // /*
// // * Lorem ipsum dolor sit amet,
// // * consectetur adipiscing elit.
// // */ˇ»
// // "},
// // actual: (but with trailing w/s on the empty lines)
// indoc! {"
// «/*
// * Lorem ipsum dolor sit amet,
// * consectetur adipiscing elit.
// *
// */
// /*
// *
// * Lorem ipsum dolor sit amet,
// * consectetur adipiscing elit.
// */ˇ»
// "},
// rust_lang.clone(),
// &mut cx,
// );
// TODO these are unhandled edge cases; not correct, just documenting known issues // TODO these are unhandled edge cases; not correct, just documenting known issues
assert_rewrap( assert_rewrap(
indoc! {" indoc! {"
@ -5964,6 +6122,21 @@ async fn test_rewrap_block_comments(cx: &mut TestAppContext) {
//ˇ Lorem ipsum dolor sit amet, consectetur adipiscing elit. */ //ˇ Lorem ipsum dolor sit amet, consectetur adipiscing elit. */
/*ˇ Lorem ipsum dolor sit amet */ /* consectetur adipiscing elit. */ /*ˇ Lorem ipsum dolor sit amet */ /* consectetur adipiscing elit. */
"}, "},
// desired:
// indoc! {"
// /*
// *ˇ Lorem ipsum dolor sit amet,
// * consectetur adipiscing elit.
// */
// /*
// *ˇ Lorem ipsum dolor sit amet,
// * consectetur adipiscing elit.
// */
// /*
// *ˇ Lorem ipsum dolor sit amet
// */ /* consectetur adipiscing elit. */
// "},
// actual:
indoc! {" indoc! {"
/* /*
//ˇ Lorem ipsum dolor sit amet, //ˇ Lorem ipsum dolor sit amet,