aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
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/ui
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/ui')
-rw-r--r--helix-term/src/ui/completion.rs11
-rw-r--r--helix-term/src/ui/editor.rs4
2 files changed, 6 insertions, 9 deletions
diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs
index c0a5da2e..7348dcf4 100644
--- a/helix-term/src/ui/completion.rs
+++ b/helix-term/src/ui/completion.rs
@@ -1,5 +1,5 @@
use crate::compositor::{Component, Context, Event, EventResult};
-use helix_view::editor::CompleteAction;
+use helix_view::{apply_transaction, editor::CompleteAction};
use tui::buffer::Buffer as Surface;
use tui::text::Spans;
@@ -164,8 +164,7 @@ impl Completion {
// initialize a savepoint
doc.savepoint();
- doc.apply(&transaction, view.id);
- view.apply(&transaction, doc);
+ apply_transaction(&transaction, doc, view);
editor.last_completion = Some(CompleteAction {
trigger_offset,
@@ -184,8 +183,7 @@ impl Completion {
trigger_offset,
);
- doc.apply(&transaction, view.id);
- view.apply(&transaction, doc);
+ apply_transaction(&transaction, doc, view);
editor.last_completion = Some(CompleteAction {
trigger_offset,
@@ -215,8 +213,7 @@ impl Completion {
additional_edits.clone(),
offset_encoding, // TODO: should probably transcode in Client
);
- doc.apply(&transaction, view.id);
- view.apply(&transaction, doc);
+ apply_transaction(&transaction, doc, view);
}
}
}
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 3b71748b..4e4fd49c 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -16,6 +16,7 @@ use helix_core::{
visual_coords_at_pos, LineEnding, Position, Range, Selection, Transaction,
};
use helix_view::{
+ apply_transaction,
document::{Mode, SCRATCH_BUFFER_NAME},
editor::{CompleteAction, CursorShapeConfig},
graphics::{Color, CursorKind, Modifier, Rect, Style},
@@ -1002,8 +1003,7 @@ impl EditorView {
(shift_position(start), shift_position(end), t)
}),
);
- doc.apply(&tx, view.id);
- view.apply(&tx, doc);
+ apply_transaction(&tx, doc, view);
}
InsertEvent::TriggerCompletion => {
let (_, doc) = current!(cxt.editor);