From 8664d70e731c73fa34dda293b4f6b6dec80a3273 Mon Sep 17 00:00:00 2001 From: BenoƮt CORTIER Date: Thu, 17 Jun 2021 18:09:10 -0400 Subject: Replace `Editor::current` by a macro This is necessary to workaround ownership issues across function calls. The issue notably arised when implementing the registers into `Editor` and I was getting annoyed again when implementing copy/pasting into system clipboard. The problem is addressed by using macro calls instead of function calls. There is no notable side effect. --- helix-term/src/ui/completion.rs | 6 +++--- helix-term/src/ui/editor.rs | 4 ++-- helix-term/src/ui/mod.rs | 10 ++++++---- 3 files changed, 11 insertions(+), 9 deletions(-) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 00ecce03..06ed966d 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -89,7 +89,7 @@ impl Completion { // doc.state = snapshot.clone(); } PromptEvent::Validate => { - let (view, doc) = editor.current(); + let (view, doc) = current!(editor); // revert state to what it was before the last update // doc.state = snapshot.clone(); @@ -169,7 +169,7 @@ impl Completion { pub fn update(&mut self, cx: &mut commands::Context) { // recompute menu based on matches let menu = self.popup.contents_mut(); - let (view, doc) = cx.editor.current(); + let (view, doc) = current!(cx.editor); // cx.hooks() // cx.add_hook(enum type, ||) @@ -233,7 +233,7 @@ impl Component for Completion { // --- // option.documentation - let (view, doc) = cx.editor.current(); + let (view, doc) = current!(cx.editor); let language = doc .language() .and_then(|scope| scope.strip_prefix("source.")) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 07107c9e..ba5e7574 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -615,7 +615,7 @@ impl Component for EditorView { // clear status cx.editor.status_msg = None; - let (view, doc) = cx.editor.current(); + let (view, doc) = current!(cx.editor); let mode = doc.mode(); let mut cxt = commands::Context { @@ -684,7 +684,7 @@ impl Component for EditorView { return EventResult::Ignored; } - let (view, doc) = cx.editor.current(); + let (view, doc) = current!(cx.editor); view.ensure_cursor_in_view(doc); // mode transitions diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 77e53690..b2274d06 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -30,8 +30,9 @@ pub fn regex_prompt( prompt: String, fun: impl Fn(&mut View, &mut Document, &mut Registers, Regex) + 'static, ) -> Prompt { - let view_id = cx.view().id; - let snapshot = cx.doc().selection(view_id).clone(); + let (view, doc) = current!(cx.editor); + let view_id = view.id; + let snapshot = doc.selection(view_id).clone(); Prompt::new( prompt, @@ -40,7 +41,7 @@ pub fn regex_prompt( match event { PromptEvent::Abort => { // TODO: also revert text - let (view, doc) = editor.current(); + let (view, doc) = current!(editor); doc.set_selection(view.id, snapshot.clone()); } PromptEvent::Validate => { @@ -54,7 +55,8 @@ pub fn regex_prompt( match Regex::new(input) { Ok(regex) => { - let (view, doc, registers) = editor.current_with_registers(); + let (view, doc) = current!(editor); + let registers = &mut editor.registers; // revert state to what it was before the last update // TODO: also revert text -- cgit v1.2.3-70-g09d2