on master help sign in
Extract idle timeout code into ui/editor.rs
68bad14Blaž Hrastnik
helix-term/src/application.rs+9−24
@@ -187,17 +187,13 @@ impl Application {
187 }
187 }
188
188
189 fn render(&mut self) {
189 fn render(&mut self) {
190− let editor = &mut self.editor;
191− let compositor = &mut self.compositor;
192− let jobs = &mut self.jobs;
193−
194 let mut cx = crate::compositor::Context {
190 let mut cx = crate::compositor::Context {
195− editor,
191+ editor: &mut self.editor,
196− jobs,
192+ jobs: &mut self.jobs,
197 scroll: None,
193 scroll: None,
198 };
194 };
199
195
200− compositor.render(&mut cx);
196+ self.compositor.render(&mut cx);
201 }
197 }
202
198
203 pub async fn event_loop(&mut self) {
199 pub async fn event_loop(&mut self) {
@@ -278,31 +274,20 @@ impl Application {
278 }
274 }
279
275
280 pub fn handle_idle_timeout(&mut self) {
276 pub fn handle_idle_timeout(&mut self) {
281− use crate::commands::{insert::idle_completion, Context};
277+ use crate::compositor::EventResult;
282− use helix_view::document::Mode;
283−
284− if doc!(self.editor).mode != Mode::Insert || !self.config.editor.auto_completion {
285− return;
286− }
287 let editor_view = self
278 let editor_view = self
288 .compositor
279 .compositor
289 .find::<ui::EditorView>()
280 .find::<ui::EditorView>()
290 .expect("expected at least one EditorView");
281 .expect("expected at least one EditorView");
291
282
292− if editor_view.completion.is_some() {
293− return;
294− }
295−
296− let mut cx = Context {
283+ let mut cx = crate::compositor::Context {
297− register: None,
298 editor: &mut self.editor,
284 editor: &mut self.editor,
299 jobs: &mut self.jobs,
285 jobs: &mut self.jobs,
300− count: None,
286+ scroll: None,
301− callback: None,
302− on_next_key_callback: None,
303 };
287 };
304− idle_completion(&mut cx);
288+ if let EventResult::Consumed(_) = editor_view.handle_idle_timeout(&mut cx) {
305− self.render();
289+ self.render();
290+ }
306 }
291 }
307
292
308 pub fn handle_terminal_events(&mut self, event: Option<Result<Event, crossterm::ErrorKind>>) {
293 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 {
856 doc.savepoint = None;
856 doc.savepoint = None;
857 editor.clear_idle_timer(); // don't retrigger
857 editor.clear_idle_timer(); // don't retrigger
858 }
858 }
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+ }
859}
880}
860
881
861impl EditorView {
882impl EditorView {