@@ -1,4 +1,4 @@
1−use crate::{find_first_non_whitespace_char2, Change, RopeSlice, State, Transaction};
1+use crate::{find_first_non_whitespace_char2, Change, RopeSlice, State, Tendril, Transaction};
22use core::ops::Range;
33use std::borrow::Cow;
44
@@ -7,7 +7,6 @@ fn find_line_comment(
77 text: RopeSlice,
88 lines: Range<usize>,
99) -> (bool, Vec<usize>, usize) {
10− // selection ranges map char_to_line from() .. to()
1110 let mut commented = true;
1211 let mut skipped = Vec::new();
1312 let mut min = usize::MAX; // minimum col for find_first_non_whitespace_char
@@ -36,11 +35,12 @@ fn find_line_comment(
3635 (commented, skipped, min)
3736}
3837
39−fn toggle_line_comments(state: &State) -> Transaction {
38+pub fn toggle_line_comments(state: &State) -> Transaction {
4039 let text = state.doc.slice(..);
4140 let mut changes: Vec<Change> = Vec::new();
4241
4342 let token = "//";
43+ let comment = Tendril::from(format!("{} ", token));
4444
4545 for selection in state.selection.ranges() {
4646 let start = text.char_to_line(selection.from());
@@ -59,7 +59,7 @@ fn toggle_line_comments(state: &State) -> Transaction {
5959
6060 if !commented {
6161 // comment line
62− changes.push((pos, pos, Some(format!("{} ", token).into())))
62+ changes.push((pos, pos, Some(comment.clone())))
6363 } else {
6464 // uncomment line
6565 let margin = 1; // TODO: margin is hardcoded 1 but could easily be 0
@@ -101,5 +101,8 @@ mod test {
101101 let transaction = toggle_line_comments(&state);
102102 transaction.apply(&mut state);
103103 assert_eq!(state.doc, " 1\n\n 2\n 3");
104+
105+ // TODO: account for no margin after comment
106+ // TODO: account for uncommenting with uneven comment indentation
104107 }
105108}