on master help sign in
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

commit57dc5fbe3aab5807e5895e37e609310b684e2c15 authorA-Walrus <58790821+A-Walrus@users.noreply.github.com> dateMon 3 Oct 2022, 17:33 (4 years ago) parentbcba5d6
1 file changed+33−1
helix-term/src/ui/mod.rs+33−1
helix-term/src/ui/mod.rs+33−1
@@ -12,6 +12,8 @@ mod spinner;
1212mod statusline;
1313mod text;
1414
15+use crate::compositor::{Component, Compositor};
16+use crate::job;
1517pub use completion::Completion;
1618pub use editor::EditorView;
1719pub use markdown::Markdown;
@@ -110,7 +112,37 @@ pub fn regex_prompt(
110112
111113 view.ensure_cursor_in_view(doc, config.scrolloff);
112114 }
113− Err(_err) => (), // TODO: mark command line as error
115+ Err(err) => {
116+ let (view, doc) = current!(cx.editor);
117+ doc.set_selection(view.id, snapshot.clone());
118+ view.offset = offset_snapshot;
119+
120+ if event == PromptEvent::Validate {
121+ let callback = async move {
122+ let call: job::Callback = Box::new(
123+ move |_editor: &mut Editor, compositor: &mut Compositor| {
124+ let contents = Text::new(format!("{}", err));
125+ let size = compositor.size();
126+ let mut popup = Popup::new("invalid-regex", contents)
127+ .position(Some(helix_core::Position::new(
128+ size.height as usize - 2, // 2 = statusline + commandline
129+ 0,
130+ )))
131+ .auto_close(true);
132+ popup.required_size((size.width, size.height));
133+
134+ compositor.replace_or_push("invalid-regex", popup);
135+ },
136+ );
137+ Ok(call)
138+ };
139+
140+ cx.jobs.callback(callback);
141+ } else {
142+ // Update
143+ // TODO: mark command line as error
144+ }
145+ }
114146 }
115147 }
116148 }