From 2ffd0a75af62a9868dd1037246cbb8014bd9e67a Mon Sep 17 00:00:00 2001 From: Awalrus Date: Tue, 12 Jul 2022 16:42:17 +0300 Subject: [PATCH 1/5] Show "Invalid regex" message on enter (Validate) --- helix-term/src/ui/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 257608f00dac..702b645b0d9d 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -117,7 +117,15 @@ pub fn regex_prompt( view.ensure_cursor_in_view(doc, config.scrolloff); } - Err(_err) => (), // TODO: mark command line as error + Err(_err) => { + if event == PromptEvent::Validate { + let error = format!("Invalid regex: {}", input); + cx.editor.set_error(error); + } else { + // Update + // TODO: mark command line as error + } + } } } } From 8e70ddd2b34a8f24def71a02f0e2005dac904ae4 Mon Sep 17 00:00:00 2001 From: Awalrus Date: Sat, 16 Jul 2022 21:52:17 +0300 Subject: [PATCH 2/5] Reset selection on invalid regex --- helix-term/src/ui/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 702b645b0d9d..f3447fe10351 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -118,6 +118,10 @@ pub fn regex_prompt( view.ensure_cursor_in_view(doc, config.scrolloff); } Err(_err) => { + let (view, doc) = current!(cx.editor); + doc.set_selection(view.id, snapshot.clone()); + view.offset = offset_snapshot; + if event == PromptEvent::Validate { let error = format!("Invalid regex: {}", input); cx.editor.set_error(error); From 116baa378b8be4a83fa4dcb027680578d653d965 Mon Sep 17 00:00:00 2001 From: Awalrus Date: Thu, 21 Jul 2022 14:49:13 +0300 Subject: [PATCH 3/5] Add popup for invalid regex --- helix-term/src/ui/mod.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index f3447fe10351..8f63535ea036 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -12,6 +12,8 @@ mod spinner; mod statusline; mod text; +use crate::compositor::{Component, Compositor}; +use crate::job; pub use completion::Completion; pub use editor::EditorView; pub use markdown::Markdown; @@ -117,14 +119,31 @@ pub fn regex_prompt( view.ensure_cursor_in_view(doc, config.scrolloff); } - Err(_err) => { + Err(err) => { let (view, doc) = current!(cx.editor); doc.set_selection(view.id, snapshot.clone()); view.offset = offset_snapshot; if event == PromptEvent::Validate { - let error = format!("Invalid regex: {}", input); - cx.editor.set_error(error); + let callback = async move { + let call: job::Callback = Box::new( + move |_editor: &mut Editor, compositor: &mut Compositor| { + let contents = Text::new(format!("{}", err)); + let mut popup = Popup::new("invalid-regex", contents); + let size = compositor.size(); + popup.required_size((size.width, size.height)); + popup.set_position(Some(helix_core::Position::new( + size.height as usize - 2, // 2 = statusline + commandline + 0, + ))); + + compositor.replace_or_push("invalid-regex", popup); + }, + ); + Ok(call) + }; + + cx.jobs.callback(callback); } else { // Update // TODO: mark command line as error From bf75a6d5bc69976527cb35b6a9bd20293c519190 Mon Sep 17 00:00:00 2001 From: Awalrus Date: Thu, 21 Jul 2022 14:59:23 +0300 Subject: [PATCH 4/5] Replace set_position with position --- helix-term/src/ui/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 8f63535ea036..f6fc98a63d1c 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -129,13 +129,13 @@ pub fn regex_prompt( let call: job::Callback = Box::new( move |_editor: &mut Editor, compositor: &mut Compositor| { let contents = Text::new(format!("{}", err)); - let mut popup = Popup::new("invalid-regex", contents); let size = compositor.size(); + let mut popup = Popup::new("invalid-regex", contents) + .position(Some(helix_core::Position::new( + size.height as usize - 2, // 2 = statusline + commandline + 0, + ))); popup.required_size((size.width, size.height)); - popup.set_position(Some(helix_core::Position::new( - size.height as usize - 2, // 2 = statusline + commandline - 0, - ))); compositor.replace_or_push("invalid-regex", popup); }, From 6ac556558fdf0d466299d93a6699292d156be286 Mon Sep 17 00:00:00 2001 From: Awalrus Date: Fri, 22 Jul 2022 12:55:52 +0300 Subject: [PATCH 5/5] Make popup auto close --- helix-term/src/ui/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index f6fc98a63d1c..babd77a7a52b 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -134,7 +134,8 @@ pub fn regex_prompt( .position(Some(helix_core::Position::new( size.height as usize - 2, // 2 = statusline + commandline 0, - ))); + ))) + .auto_close(true); popup.required_size((size.width, size.height)); compositor.replace_or_push("invalid-regex", popup);