aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/application.rs101
-rw-r--r--helix-term/src/ui/mod.rs6
2 files changed, 55 insertions, 52 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index 84eba22a..bae3f192 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -287,9 +287,6 @@ impl Application {
where
S: Stream<Item = crossterm::Result<crossterm::event::Event>> + Unpin,
{
- #[cfg(feature = "integration")]
- let mut idle_handled = false;
-
loop {
if self.editor.should_close() {
return false;
@@ -315,56 +312,19 @@ impl Application {
self.render();
}
event = self.editor.wait_event() => {
- log::debug!("received editor event: {:?}", event);
+ let _idle_handled = self.handle_editor_event(event).await;
- match event {
- EditorEvent::DocumentSave(event) => {
- self.handle_document_write(event);
- self.render();
- }
- EditorEvent::ConfigEvent(event) => {
- self.handle_config_events(event);
- self.render();
- }
- EditorEvent::LanguageServerMessage((id, call)) => {
- self.handle_language_server_message(call, id).await;
- // limit render calls for fast language server messages
- let last = self.editor.language_servers.incoming.is_empty();
-
- if last || self.last_render.elapsed() > LSP_DEADLINE {
- self.render();
- self.last_render = Instant::now();
- }
- }
- EditorEvent::DebuggerEvent(payload) => {
- let needs_render = self.editor.handle_debugger_message(payload).await;
- if needs_render {
- self.render();
- }
- }
- EditorEvent::IdleTimer => {
- self.editor.clear_idle_timer();
- self.handle_idle_timeout();
-
- #[cfg(feature = "integration")]
- {
- log::debug!("idle handled");
- idle_handled = true;
- }
+ // for integration tests only, reset the idle timer after every
+ // event to signal when test events are done processing
+ #[cfg(feature = "integration")]
+ {
+ if _idle_handled {
+ return true;
}
- }
- }
- }
- // for integration tests only, reset the idle timer after every
- // event to signal when test events are done processing
- #[cfg(feature = "integration")]
- {
- if idle_handled {
- return true;
+ self.editor.reset_idle_timer();
+ }
}
-
- self.editor.reset_idle_timer();
}
}
}
@@ -517,6 +477,49 @@ impl Application {
}
}
+ #[inline(always)]
+ pub async fn handle_editor_event(&mut self, event: EditorEvent) -> bool {
+ log::debug!("received editor event: {:?}", event);
+
+ match event {
+ EditorEvent::DocumentSave(event) => {
+ self.handle_document_write(event);
+ self.render();
+ }
+ EditorEvent::ConfigEvent(event) => {
+ self.handle_config_events(event);
+ self.render();
+ }
+ EditorEvent::LanguageServerMessage((id, call)) => {
+ self.handle_language_server_message(call, id).await;
+ // limit render calls for fast language server messages
+ let last = self.editor.language_servers.incoming.is_empty();
+
+ if last || self.last_render.elapsed() > LSP_DEADLINE {
+ self.render();
+ self.last_render = Instant::now();
+ }
+ }
+ EditorEvent::DebuggerEvent(payload) => {
+ let needs_render = self.editor.handle_debugger_message(payload).await;
+ if needs_render {
+ self.render();
+ }
+ }
+ EditorEvent::IdleTimer => {
+ self.editor.clear_idle_timer();
+ self.handle_idle_timeout();
+
+ #[cfg(feature = "integration")]
+ {
+ return true;
+ }
+ }
+ }
+
+ false
+ }
+
pub fn handle_terminal_events(&mut self, event: Result<CrosstermEvent, crossterm::ErrorKind>) {
let mut cx = crate::compositor::Context {
editor: &mut self.editor,
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index 6ac4dbb7..f99dea0b 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -14,7 +14,7 @@ mod statusline;
mod text;
use crate::compositor::{Component, Compositor};
-use crate::job;
+use crate::job::{self, Callback};
pub use completion::Completion;
pub use editor::EditorView;
pub use markdown::Markdown;
@@ -121,7 +121,7 @@ pub fn regex_prompt(
if event == PromptEvent::Validate {
let callback = async move {
- let call: job::Callback = Box::new(
+ let call: job::Callback = Callback::EditorCompositor(Box::new(
move |_editor: &mut Editor, compositor: &mut Compositor| {
let contents = Text::new(format!("{}", err));
let size = compositor.size();
@@ -135,7 +135,7 @@ pub fn regex_prompt(
compositor.replace_or_push("invalid-regex", popup);
},
- );
+ ));
Ok(call)
};