Only allocate once when toggling comments

This commit is contained in:
Dániel Buga 2022-05-15 19:35:18 +02:00
parent 90d8dbec30
commit ed3e34c9ee
1 changed files with 3 additions and 5 deletions

View File

@ -713,10 +713,8 @@ pub fn do_edit<T: Clipboard>(
ToggleLineComment => {
let mut lines = HashSet::new();
let selection = cursor.edit_selection(buffer);
let comment_token = syntax
.map(|s| s.language.comment_token())
.unwrap_or("//")
.to_string();
let comment_token =
syntax.map(|s| s.language.comment_token()).unwrap_or("//");
let mut had_comment = true;
let mut smallest_indent = usize::MAX;
for region in selection.regions() {
@ -775,7 +773,7 @@ pub fn do_edit<T: Clipboard>(
selection.add_region(SelRegion::new(start, start, None))
}
buffer.edit(
&[(&selection, &(comment_token + " "))],
&[(&selection, &format!("{comment_token} "))],
EditType::InsertChars,
)
};