on master help sign in
Make Transaction::change only rely on the rope.
commit8eaf9a432d14b6c2dd084dabbea606e4b1e3baa0 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 18 Mar 2021, 13:28 (6 years ago) parent51c15da
7 files changed+16−15
helix-core/src/comment.rs+1−1 helix-core/src/history.rs+2−2 helix-core/src/syntax.rs+3−2 helix-core/src/transaction.rs+4−4 helix-lsp/src/lib.rs+1−1 helix-term/src/commands.rs+4−4 helix-view/src/document.rs+1−1
helix-core/src/comment.rs+1−1
@@ -67,7 +67,7 @@ pub fn toggle_line_comments(state: &State) -> Transaction {
6767 }
6868 }
6969 }
70− Transaction::change(state, changes.into_iter())
70+ Transaction::change(&state.doc, changes.into_iter())
7171}
7272
7373#[cfg(test)]
helix-core/src/history.rs+2−2
@@ -96,7 +96,7 @@ mod test {
9696 let mut state = State::new(doc);
9797
9898 let transaction1 =
99− Transaction::change(&state, vec![(5, 5, Some(" world!".into()))].into_iter());
99+ Transaction::change(&state.doc, vec![(5, 5, Some(" world!".into()))].into_iter());
100100
101101 // Need to commit before applying!
102102 history.commit_revision(&transaction1, &state);
@@ -106,7 +106,7 @@ mod test {
106106 // ---
107107
108108 let transaction2 =
109− Transaction::change(&state, vec![(6, 11, Some("世界".into()))].into_iter());
109+ Transaction::change(&state.doc, vec![(6, 11, Some("世界".into()))].into_iter());
110110
111111 // Need to commit before applying!
112112 history.commit_revision(&transaction2, &state);
helix-core/src/syntax.rs+3−2
@@ -1591,7 +1591,7 @@ fn test_input_edits() {
15911591
15921592 let mut state = State::new("hello world!\ntest 123".into());
15931593 let transaction = Transaction::change(
1594− &state,
1594+ &state.doc,
15951595 vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
15961596 );
15971597 let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
@@ -1621,7 +1621,8 @@ fn test_input_edits() {
16211621
16221622 // Testing with the official example from tree-sitter
16231623 let mut state = State::new("fn test() {}".into());
1624− let transaction = Transaction::change(&state, vec![(8, 8, Some("a: u32".into()))].into_iter());
1624+ let transaction =
1625+ Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
16251626 let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
16261627 transaction.apply(&mut state);
16271628
helix-core/src/transaction.rs+4−4
@@ -459,11 +459,11 @@ impl Transaction {
459459 }
460460
461461 /// Generate a transaction from a set of changes.
462− pub fn change<I>(state: &State, changes: I) -> Self
462+ pub fn change<I>(doc: &Rope, changes: I) -> Self
463463 where
464464 I: IntoIterator<Item = Change> + ExactSizeIterator,
465465 {
466− let len = state.doc.len_chars();
466+ let len = doc.len_chars();
467467 let acc = Vec::with_capacity(2 * changes.len() + 1);
468468 let mut changeset = ChangeSet { changes: acc, len };
469469
@@ -494,7 +494,7 @@ impl Transaction {
494494 where
495495 F: FnMut(&Range) -> Change,
496496 {
497− Self::change(state, state.selection.ranges().iter().map(f))
497+ Self::change(&state.doc, state.selection.ranges().iter().map(f))
498498 }
499499
500500 /// Insert text at each selection head.
@@ -617,7 +617,7 @@ mod test {
617617 fn transaction_change() {
618618 let mut state = State::new("hello world!\ntest 123".into());
619619 let transaction = Transaction::change(
620− &state,
620+ &state.doc,
621621 // (1, 1, None) is a useless 0-width delete
622622 vec![(1, 1, None), (6, 11, Some("void".into())), (12, 17, None)].into_iter(),
623623 );
helix-lsp/src/lib.rs+1−1
@@ -58,7 +58,7 @@ pub mod util {
5858 ) -> Transaction {
5959 let doc = state.doc.slice(..);
6060 Transaction::change(
61− state,
61+ &state.doc,
6262 edits.into_iter().map(|edit| {
6363 // simplify "" into None for cleaner changesets
6464 let replacement = if !edit.new_text.is_empty() {
helix-term/src/commands.rs+4−4
@@ -807,7 +807,7 @@ pub fn open_below(cx: &mut Context) {
807807 );
808808
809809 let transaction =
810− Transaction::change(&doc.state, changes.into_iter()).with_selection(selection);
810+ Transaction::change(doc.text(), changes.into_iter()).with_selection(selection);
811811
812812 doc.apply(&transaction);
813813}
@@ -1116,7 +1116,7 @@ pub fn indent(cx: &mut Context) {
11161116 let indent = Tendril::from(" ".repeat(TAB_WIDTH));
11171117
11181118 let transaction = Transaction::change(
1119− &doc.state,
1119+ doc.text(),
11201120 lines.into_iter().map(|line| {
11211121 let pos = doc.text().line_to_char(line);
11221122 (pos, pos, Some(indent.clone()))
@@ -1153,7 +1153,7 @@ pub fn unindent(cx: &mut Context) {
11531153 }
11541154 }
11551155
1156− let transaction = Transaction::change(&doc.state, changes.into_iter());
1156+ let transaction = Transaction::change(doc.text(), changes.into_iter());
11571157
11581158 doc.apply(&transaction);
11591159 doc.append_changes_to_history();
@@ -1234,7 +1234,7 @@ pub fn join_selections(cx: &mut Context) {
12341234 // TODO: joining multiple empty lines should be replaced by a single space.
12351235 // need to merge change ranges that touch
12361236
1237− let transaction = Transaction::change(&doc.state, changes.into_iter());
1237+ let transaction = Transaction::change(doc.text(), changes.into_iter());
12381238 // TODO: select inserted spaces
12391239 // .with_selection(selection);
12401240
helix-view/src/document.rs+1−1
@@ -394,7 +394,7 @@ mod test {
394394
395395 doc.state.selection = Selection::single(0, 5);
396396 let transaction = Transaction::change(
397− &doc.state,
397+ &doc.state.doc,
398398 vec![(0, 2, Some("aei".into())), (3, 5, Some("ou".into()))].into_iter(),
399399 );
400400 // aeilou