summaryrefslogtreecommitdiff
path: root/helix-core/src/comment.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-18 04:45:57 +0000
committerBlaž Hrastnik2021-03-18 05:17:32 +0000
commit59e60241864dcf711325109423d74cf6e8b6463d (patch)
treed89a4036a46d2533321c1dd62b1d3c3b60fda693 /helix-core/src/comment.rs
parentdbcc099f484ad186782370ed0cf61b3e8d27282b (diff)
Remove State from a few more signatures.
Diffstat (limited to 'helix-core/src/comment.rs')
-rw-r--r--helix-core/src/comment.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/helix-core/src/comment.rs b/helix-core/src/comment.rs
index 969d4d92..35aabda9 100644
--- a/helix-core/src/comment.rs
+++ b/helix-core/src/comment.rs
@@ -1,4 +1,6 @@
-use crate::{find_first_non_whitespace_char2, Change, RopeSlice, State, Tendril, Transaction};
+use crate::{
+ find_first_non_whitespace_char2, Change, Rope, RopeSlice, Selection, Tendril, Transaction,
+};
use core::ops::Range;
use std::borrow::Cow;
@@ -35,14 +37,14 @@ fn find_line_comment(
(commented, skipped, min)
}
-pub fn toggle_line_comments(state: &State) -> Transaction {
- let text = state.doc.slice(..);
+pub fn toggle_line_comments(doc: &Rope, selection: &Selection) -> Transaction {
+ let text = doc.slice(..);
let mut changes: Vec<Change> = Vec::new();
let token = "//";
let comment = Tendril::from(format!("{} ", token));
- for selection in state.selection.ranges() {
+ for selection in selection.ranges() {
let start = text.char_to_line(selection.from());
let end = text.char_to_line(selection.to());
let lines = start..end + 1;
@@ -67,7 +69,7 @@ pub fn toggle_line_comments(state: &State) -> Transaction {
}
}
}
- Transaction::change(&state.doc, changes.into_iter())
+ Transaction::change(doc, changes.into_iter())
}
#[cfg(test)]
@@ -76,7 +78,7 @@ mod test {
#[test]
fn test_find_line_comment() {
- use crate::{Rope, Selection};
+ use crate::State;
// four lines, two space indented, except for line 1 which is blank.
let doc = Rope::from(" 1\n\n 2\n 3");
@@ -92,13 +94,13 @@ mod test {
assert_eq!(res, (false, vec![1], 2));
// comment
- let transaction = toggle_line_comments(&state);
+ let transaction = toggle_line_comments(&state.doc, &state.selection);
transaction.apply(&mut state);
assert_eq!(state.doc, " // 1\n\n // 2\n // 3");
// uncomment
- let transaction = toggle_line_comments(&state);
+ let transaction = toggle_line_comments(&state.doc, &state.selection);
transaction.apply(&mut state);
assert_eq!(state.doc, " 1\n\n 2\n 3");