on master help sign in
Make Transaction::change only rely on the rope.
8eaf9a4Blaž Hrastnik
helix-core/src/comment.rs+1−1
@@ -67,7 +67,7 @@ pub fn toggle_line_comments(state: &State) -> Transaction {
67 }
67 }
68 }
68 }
69 }
69 }
70− Transaction::change(state, changes.into_iter())
70+ Transaction::change(&state.doc, changes.into_iter())
71}
71}
72
72
73#[cfg(test)]
73#[cfg(test)]
helix-core/src/history.rs+2−2
@@ -96,7 +96,7 @@ mod test {
96 let mut state = State::new(doc);
96 let mut state = State::new(doc);
97
97
98 let transaction1 =
98 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());
100
100
101 // Need to commit before applying!
101 // Need to commit before applying!
102 history.commit_revision(&transaction1, &state);
102 history.commit_revision(&transaction1, &state);
@@ -106,7 +106,7 @@ mod test {
106 // ---
106 // ---
107
107
108 let transaction2 =
108 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());
110
110
111 // Need to commit before applying!
111 // Need to commit before applying!
112 history.commit_revision(&transaction2, &state);
112 history.commit_revision(&transaction2, &state);
helix-core/src/syntax.rs+3−2
@@ -1591,7 +1591,7 @@ fn test_input_edits() {
1591
1591
1592 let mut state = State::new("hello world!\ntest 123".into());
1592 let mut state = State::new("hello world!\ntest 123".into());
1593 let transaction = Transaction::change(
1593 let transaction = Transaction::change(
1594− &state,
1594+ &state.doc,
1595 vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
1595 vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
1596 );
1596 );
1597 let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
1597 let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
@@ -1621,7 +1621,8 @@ fn test_input_edits() {
1621
1621
1622 // Testing with the official example from tree-sitter
1622 // Testing with the official example from tree-sitter
1623 let mut state = State::new("fn test() {}".into());
1623 let mut state = State::new("fn test() {}".into());
1624+ let transaction =
1624− let transaction = Transaction::change(&state, vec![(8, 8, Some("a: u32".into()))].into_iter());
1625+ Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
1625 let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
1626 let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
1626 transaction.apply(&mut state);
1627 transaction.apply(&mut state);
1627
1628
helix-core/src/transaction.rs+4−4
@@ -459,11 +459,11 @@ impl Transaction {
459 }
459 }
460
460
461 /// Generate a transaction from a set of changes.
461 /// 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
463 where
463 where
464 I: IntoIterator<Item = Change> + ExactSizeIterator,
464 I: IntoIterator<Item = Change> + ExactSizeIterator,
465 {
465 {
466− let len = state.doc.len_chars();
466+ let len = doc.len_chars();
467 let acc = Vec::with_capacity(2 * changes.len() + 1);
467 let acc = Vec::with_capacity(2 * changes.len() + 1);
468 let mut changeset = ChangeSet { changes: acc, len };
468 let mut changeset = ChangeSet { changes: acc, len };
469
469
@@ -494,7 +494,7 @@ impl Transaction {
494 where
494 where
495 F: FnMut(&Range) -> Change,
495 F: FnMut(&Range) -> Change,
496 {
496 {
497− Self::change(state, state.selection.ranges().iter().map(f))
497+ Self::change(&state.doc, state.selection.ranges().iter().map(f))
498 }
498 }
499
499
500 /// Insert text at each selection head.
500 /// Insert text at each selection head.
@@ -617,7 +617,7 @@ mod test {
617 fn transaction_change() {
617 fn transaction_change() {
618 let mut state = State::new("hello world!\ntest 123".into());
618 let mut state = State::new("hello world!\ntest 123".into());
619 let transaction = Transaction::change(
619 let transaction = Transaction::change(
620− &state,
620+ &state.doc,
621 // (1, 1, None) is a useless 0-width delete
621 // (1, 1, None) is a useless 0-width delete
622 vec![(1, 1, None), (6, 11, Some("void".into())), (12, 17, None)].into_iter(),
622 vec![(1, 1, None), (6, 11, Some("void".into())), (12, 17, None)].into_iter(),
623 );
623 );
helix-lsp/src/lib.rs+1−1
@@ -58,7 +58,7 @@ pub mod util {
58 ) -> Transaction {
58 ) -> Transaction {
59 let doc = state.doc.slice(..);
59 let doc = state.doc.slice(..);
60 Transaction::change(
60 Transaction::change(
61− state,
61+ &state.doc,
62 edits.into_iter().map(|edit| {
62 edits.into_iter().map(|edit| {
63 // simplify "" into None for cleaner changesets
63 // simplify "" into None for cleaner changesets
64 let replacement = if !edit.new_text.is_empty() {
64 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) {
807 );
807 );
808
808
809 let transaction =
809 let transaction =
810− Transaction::change(&doc.state, changes.into_iter()).with_selection(selection);
810+ Transaction::change(doc.text(), changes.into_iter()).with_selection(selection);
811
811
812 doc.apply(&transaction);
812 doc.apply(&transaction);
813}
813}
@@ -1116,7 +1116,7 @@ pub fn indent(cx: &mut Context) {
1116 let indent = Tendril::from(" ".repeat(TAB_WIDTH));
1116 let indent = Tendril::from(" ".repeat(TAB_WIDTH));
1117
1117
1118 let transaction = Transaction::change(
1118 let transaction = Transaction::change(
1119− &doc.state,
1119+ doc.text(),
1120 lines.into_iter().map(|line| {
1120 lines.into_iter().map(|line| {
1121 let pos = doc.text().line_to_char(line);
1121 let pos = doc.text().line_to_char(line);
1122 (pos, pos, Some(indent.clone()))
1122 (pos, pos, Some(indent.clone()))
@@ -1153,7 +1153,7 @@ pub fn unindent(cx: &mut Context) {
1153 }
1153 }
1154 }
1154 }
1155
1155
1156− let transaction = Transaction::change(&doc.state, changes.into_iter());
1156+ let transaction = Transaction::change(doc.text(), changes.into_iter());
1157
1157
1158 doc.apply(&transaction);
1158 doc.apply(&transaction);
1159 doc.append_changes_to_history();
1159 doc.append_changes_to_history();
@@ -1234,7 +1234,7 @@ pub fn join_selections(cx: &mut Context) {
1234 // TODO: joining multiple empty lines should be replaced by a single space.
1234 // TODO: joining multiple empty lines should be replaced by a single space.
1235 // need to merge change ranges that touch
1235 // need to merge change ranges that touch
1236
1236
1237− let transaction = Transaction::change(&doc.state, changes.into_iter());
1237+ let transaction = Transaction::change(doc.text(), changes.into_iter());
1238 // TODO: select inserted spaces
1238 // TODO: select inserted spaces
1239 // .with_selection(selection);
1239 // .with_selection(selection);
1240
1240
helix-view/src/document.rs+1−1
@@ -394,7 +394,7 @@ mod test {
394
394
395 doc.state.selection = Selection::single(0, 5);
395 doc.state.selection = Selection::single(0, 5);
396 let transaction = Transaction::change(
396 let transaction = Transaction::change(
397− &doc.state,
397+ &doc.state.doc,
398 vec![(0, 2, Some("aei".into())), (3, 5, Some("ou".into()))].into_iter(),
398 vec![(0, 2, Some("aei".into())), (3, 5, Some("ou".into()))].into_iter(),
399 );
399 );
400 // aeilou
400 // aeilou