diff options
author | A-Walrus | 2022-10-03 14:33:48 +0000 |
---|---|---|
committer | GitHub | 2022-10-03 14:33:48 +0000 |
commit | 57dc5fbe3aab5807e5895e37e609310b684e2c15 (patch) | |
tree | f43bda5c9e5349c79d378b1cfc4df841c52bf562 /helix-term/src | |
parent | bcba5d67f9b8650936c391f6c113945291941f51 (diff) |
Show "Invalid regex" message on enter (Validate) (#3049)
* Show "Invalid regex" message on enter (Validate)
* Reset selection on invalid regex
* Add popup for invalid regex
* Replace set_position with position
* Make popup auto close
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/ui/mod.rs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 60ad3b24..ba809d9b 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; @@ -110,7 +112,37 @@ pub fn regex_prompt( view.ensure_cursor_in_view(doc, config.scrolloff); } - Err(_err) => (), // TODO: mark command line as error + Err(err) => { + let (view, doc) = current!(cx.editor); + doc.set_selection(view.id, snapshot.clone()); + view.offset = offset_snapshot; + + if event == PromptEvent::Validate { + let callback = async move { + let call: job::Callback = Box::new( + move |_editor: &mut Editor, compositor: &mut Compositor| { + let contents = Text::new(format!("{}", err)); + 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, + ))) + .auto_close(true); + popup.required_size((size.width, size.height)); + + compositor.replace_or_push("invalid-regex", popup); + }, + ); + Ok(call) + }; + + cx.jobs.callback(callback); + } else { + // Update + // TODO: mark command line as error + } + } } } } |