aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands/typed.rs
diff options
context:
space:
mode:
authorMichael Davis2022-10-10 20:15:37 +0000
committerBlaž Hrastnik2022-10-11 03:17:32 +0000
commitc388e16e09b36c665c4f92db4f7a071e7c1d9761 (patch)
tree40bf9fe3dbacaac21a131bb67c896d9395930d64 /helix-term/src/commands/typed.rs
parent0aedef03334dfc0cb2a723cce23abc5b4ca55a22 (diff)
Add a helper function for applying transactions
It is easy to forget to call `Document::apply` and/or `View::apply` in the correct order. This commit introduces a helper function which closes over both calls.
Diffstat (limited to 'helix-term/src/commands/typed.rs')
-rw-r--r--helix-term/src/commands/typed.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index 574e895b..726c7456 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -2,7 +2,10 @@ use std::ops::Deref;
use super::*;
-use helix_view::editor::{Action, CloseError, ConfigEvent};
+use helix_view::{
+ apply_transaction,
+ editor::{Action, CloseError, ConfigEvent},
+};
use ui::completers::{self, Completer};
#[derive(Clone)]
@@ -462,8 +465,7 @@ fn set_line_ending(
}
}),
);
- doc.apply(&transaction, view.id);
- view.apply(&transaction, doc);
+ apply_transaction(&transaction, doc, view);
doc.append_changes_to_history(view.id);
Ok(())
@@ -884,8 +886,7 @@ fn replace_selections_with_clipboard_impl(
(range.from(), range.to(), Some(contents.as_str().into()))
});
- doc.apply(&transaction, view.id);
- view.apply(&transaction, doc);
+ apply_transaction(&transaction, doc, view);
doc.append_changes_to_history(view.id);
Ok(())
}
@@ -1400,8 +1401,7 @@ fn sort_impl(
.map(|(s, fragment)| (s.from(), s.to(), Some(fragment))),
);
- doc.apply(&transaction, view.id);
- view.apply(&transaction, doc);
+ apply_transaction(&transaction, doc, view);
doc.append_changes_to_history(view.id);
Ok(())
@@ -1445,8 +1445,7 @@ fn reflow(
(range.from(), range.to(), Some(reflowed_text))
});
- doc.apply(&transaction, view.id);
- view.apply(&transaction, doc);
+ apply_transaction(&transaction, doc, view);
doc.append_changes_to_history(view.id);
view.ensure_cursor_in_view(doc, scrolloff);