aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-18 04:28:27 +0000
committerBlaž Hrastnik2021-03-18 04:39:56 +0000
commit8eaf9a432d14b6c2dd084dabbea606e4b1e3baa0 (patch)
treea353a3a9182622b8434165825e03e2264bb444ea
parent51c15da3c32b2f0bf3da6db9bca9496d333ec15a (diff)
Make Transaction::change only rely on the rope.
-rw-r--r--helix-core/src/comment.rs2
-rw-r--r--helix-core/src/history.rs4
-rw-r--r--helix-core/src/syntax.rs5
-rw-r--r--helix-core/src/transaction.rs8
-rw-r--r--helix-lsp/src/lib.rs2
-rw-r--r--helix-term/src/commands.rs8
-rw-r--r--helix-view/src/document.rs2
7 files changed, 16 insertions, 15 deletions
diff --git a/helix-core/src/comment.rs b/helix-core/src/comment.rs
index 9109e2d6..969d4d92 100644
--- a/helix-core/src/comment.rs
+++ b/helix-core/src/comment.rs
@@ -67,7 +67,7 @@ pub fn toggle_line_comments(state: &State) -> Transaction {
}
}
}
- Transaction::change(state, changes.into_iter())
+ Transaction::change(&state.doc, changes.into_iter())
}
#[cfg(test)]
diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs
index 99de3f7c..c92c2a89 100644
--- a/helix-core/src/history.rs
+++ b/helix-core/src/history.rs
@@ -96,7 +96,7 @@ mod test {
let mut state = State::new(doc);
let transaction1 =
- Transaction::change(&state, vec![(5, 5, Some(" world!".into()))].into_iter());
+ Transaction::change(&state.doc, vec![(5, 5, Some(" world!".into()))].into_iter());
// Need to commit before applying!
history.commit_revision(&transaction1, &state);
@@ -106,7 +106,7 @@ mod test {
// ---
let transaction2 =
- Transaction::change(&state, vec![(6, 11, Some("世界".into()))].into_iter());
+ Transaction::change(&state.doc, vec![(6, 11, Some("世界".into()))].into_iter());
// Need to commit before applying!
history.commit_revision(&transaction2, &state);
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index 2ad06bef..3d665953 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -1591,7 +1591,7 @@ fn test_input_edits() {
let mut state = State::new("hello world!\ntest 123".into());
let transaction = Transaction::change(
- &state,
+ &state.doc,
vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
);
let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
@@ -1621,7 +1621,8 @@ fn test_input_edits() {
// Testing with the official example from tree-sitter
let mut state = State::new("fn test() {}".into());
- let transaction = Transaction::change(&state, vec![(8, 8, Some("a: u32".into()))].into_iter());
+ let transaction =
+ Transaction::change(&state.doc, vec![(8, 8, Some("a: u32".into()))].into_iter());
let edits = LanguageLayer::generate_edits(state.doc.slice(..), &transaction.changes);
transaction.apply(&mut state);
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs
index bd605305..dbc5d588 100644
--- a/helix-core/src/transaction.rs
+++ b/helix-core/src/transaction.rs
@@ -459,11 +459,11 @@ impl Transaction {
}
/// Generate a transaction from a set of changes.
- pub fn change<I>(state: &State, changes: I) -> Self
+ pub fn change<I>(doc: &Rope, changes: I) -> Self
where
I: IntoIterator<Item = Change> + ExactSizeIterator,
{
- let len = state.doc.len_chars();
+ let len = doc.len_chars();
let acc = Vec::with_capacity(2 * changes.len() + 1);
let mut changeset = ChangeSet { changes: acc, len };
@@ -494,7 +494,7 @@ impl Transaction {
where
F: FnMut(&Range) -> Change,
{
- Self::change(state, state.selection.ranges().iter().map(f))
+ Self::change(&state.doc, state.selection.ranges().iter().map(f))
}
/// Insert text at each selection head.
@@ -617,7 +617,7 @@ mod test {
fn transaction_change() {
let mut state = State::new("hello world!\ntest 123".into());
let transaction = Transaction::change(
- &state,
+ &state.doc,
// (1, 1, None) is a useless 0-width delete
vec![(1, 1, None), (6, 11, Some("void".into())), (12, 17, None)].into_iter(),
);
diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs
index 3e4f55ea..3dcdeb07 100644
--- a/helix-lsp/src/lib.rs
+++ b/helix-lsp/src/lib.rs
@@ -58,7 +58,7 @@ pub mod util {
) -> Transaction {
let doc = state.doc.slice(..);
Transaction::change(
- state,
+ &state.doc,
edits.into_iter().map(|edit| {
// simplify "" into None for cleaner changesets
let replacement = if !edit.new_text.is_empty() {
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 34e4a813..34e18e3e 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -807,7 +807,7 @@ pub fn open_below(cx: &mut Context) {
);
let transaction =
- Transaction::change(&doc.state, changes.into_iter()).with_selection(selection);
+ Transaction::change(doc.text(), changes.into_iter()).with_selection(selection);
doc.apply(&transaction);
}
@@ -1116,7 +1116,7 @@ pub fn indent(cx: &mut Context) {
let indent = Tendril::from(" ".repeat(TAB_WIDTH));
let transaction = Transaction::change(
- &doc.state,
+ doc.text(),
lines.into_iter().map(|line| {
let pos = doc.text().line_to_char(line);
(pos, pos, Some(indent.clone()))
@@ -1153,7 +1153,7 @@ pub fn unindent(cx: &mut Context) {
}
}
- let transaction = Transaction::change(&doc.state, changes.into_iter());
+ let transaction = Transaction::change(doc.text(), changes.into_iter());
doc.apply(&transaction);
doc.append_changes_to_history();
@@ -1234,7 +1234,7 @@ pub fn join_selections(cx: &mut Context) {
// TODO: joining multiple empty lines should be replaced by a single space.
// need to merge change ranges that touch
- let transaction = Transaction::change(&doc.state, changes.into_iter());
+ let transaction = Transaction::change(doc.text(), changes.into_iter());
// TODO: select inserted spaces
// .with_selection(selection);
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 82258bde..eba6478d 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -394,7 +394,7 @@ mod test {
doc.state.selection = Selection::single(0, 5);
let transaction = Transaction::change(
- &doc.state,
+ &doc.state.doc,
vec![(0, 2, Some("aei".into())), (3, 5, Some("ou".into()))].into_iter(),
);
// aeilou