on master help sign in
Extract idle timeout code into ui/editor.rs
commit68bad148a58cb580333cc545376b7bc6c2c5abd4 authorBlaž Hrastnik <blaz@mxxn.io> dateWed 2 Mar 2022, 16:10 (5 years ago) parent78fba86
2 files changed+30−24
helix-term/src/application.rs+9−24 helix-term/src/ui/editor.rs+21
helix-term/src/application.rs+9−24
@@ -187,17 +187,13 @@ impl Application {
187187 }
188188
189189 fn render(&mut self) {
190− let editor = &mut self.editor;
191− let compositor = &mut self.compositor;
192− let jobs = &mut self.jobs;
193−
194190 let mut cx = crate::compositor::Context {
195− editor,
196− jobs,
191+ editor: &mut self.editor,
192+ jobs: &mut self.jobs,
197193 scroll: None,
198194 };
199195
200− compositor.render(&mut cx);
196+ self.compositor.render(&mut cx);
201197 }
202198
203199 pub async fn event_loop(&mut self) {
@@ -278,31 +274,20 @@ impl Application {
278274 }
279275
280276 pub fn handle_idle_timeout(&mut self) {
281− use crate::commands::{insert::idle_completion, Context};
282− use helix_view::document::Mode;
283−
284− if doc!(self.editor).mode != Mode::Insert || !self.config.editor.auto_completion {
285− return;
286− }
277+ use crate::compositor::EventResult;
287278 let editor_view = self
288279 .compositor
289280 .find::<ui::EditorView>()
290281 .expect("expected at least one EditorView");
291282
292− if editor_view.completion.is_some() {
293− return;
294− }
295−
296− let mut cx = Context {
297− register: None,
283+ let mut cx = crate::compositor::Context {
298284 editor: &mut self.editor,
299285 jobs: &mut self.jobs,
300− count: None,
301− callback: None,
302− on_next_key_callback: None,
286+ scroll: None,
303287 };
304− idle_completion(&mut cx);
305− self.render();
288+ if let EventResult::Consumed(_) = editor_view.handle_idle_timeout(&mut cx) {
289+ self.render();
290+ }
306291 }
307292
308293 pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
helix-term/src/ui/editor.rs+21
@@ -856,6 +856,27 @@ impl EditorView {
856856 doc.savepoint = None;
857857 editor.clear_idle_timer(); // don't retrigger
858858 }
859+
860+ pub fn handle_idle_timeout(&mut self, cx: &mut crate::compositor::Context) -> EventResult {
861+ if self.completion.is_some()
862+ || !cx.editor.config.auto_completion
863+ || doc!(cx.editor).mode != Mode::Insert
864+ {
865+ return EventResult::Ignored(None);
866+ }
867+
868+ let mut cx = commands::Context {
869+ register: None,
870+ editor: cx.editor,
871+ jobs: cx.jobs,
872+ count: None,
873+ callback: None,
874+ on_next_key_callback: None,
875+ };
876+ crate::commands::insert::idle_completion(&mut cx);
877+
878+ EventResult::Consumed(None)
879+ }
859880}
860881
861882impl EditorView {