summaryrefslogtreecommitdiff
path: root/helix-core/src/comment.rs
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-19 05:02:12 +0000
committerNathan Vegdahl2021-07-19 05:02:12 +0000
commite462f32723bb61899a390f438d7d856d87fb7614 (patch)
treee97a9afbf07e2735ba96d62dd5e8f71e1a241fe1 /helix-core/src/comment.rs
parent6c038bb0151c6aeb43fc94bd2dc3d516a71d346c (diff)
parent5292fe0f7df9f1a420744007aa9dd67e7a5a6610 (diff)
Merge branch 'master' into great_line_ending_and_cursor_range_cleanup
Diffstat (limited to 'helix-core/src/comment.rs')
-rw-r--r--helix-core/src/comment.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/helix-core/src/comment.rs b/helix-core/src/comment.rs
index 07f685d8..5d564055 100644
--- a/helix-core/src/comment.rs
+++ b/helix-core/src/comment.rs
@@ -38,18 +38,18 @@ fn find_line_comment(
}
#[must_use]
-pub fn toggle_line_comments(doc: &Rope, selection: &Selection) -> Transaction {
+pub fn toggle_line_comments(doc: &Rope, selection: &Selection, token: Option<&str>) -> Transaction {
let text = doc.slice(..);
let mut changes: Vec<Change> = Vec::new();
- let token = "//";
+ let token = token.unwrap_or("//");
let comment = Tendril::from(format!("{} ", token));
for selection in selection {
let start = text.char_to_line(selection.from());
let end = text.char_to_line(selection.to());
let lines = start..end + 1;
- let (commented, skipped, min) = find_line_comment(token, text, lines.clone());
+ let (commented, skipped, min) = find_line_comment(&token, text, lines.clone());
changes.reserve((end - start).saturating_sub(skipped.len()));
@@ -95,14 +95,14 @@ mod test {
assert_eq!(res, (false, vec![1], 2));
// comment
- let transaction = toggle_line_comments(&state.doc, &state.selection);
+ let transaction = toggle_line_comments(&state.doc, &state.selection, None);
transaction.apply(&mut state.doc);
state.selection = state.selection.clone().map(transaction.changes());
assert_eq!(state.doc, " // 1\n\n // 2\n // 3");
// uncomment
- let transaction = toggle_line_comments(&state.doc, &state.selection);
+ let transaction = toggle_line_comments(&state.doc, &state.selection, None);
transaction.apply(&mut state.doc);
state.selection = state.selection.clone().map(transaction.changes());
assert_eq!(state.doc, " 1\n\n 2\n 3");