Skip to content

Commit

Permalink
Add popup for invalid regex
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Walrus committed Jul 21, 2022
1 parent 8e70ddd commit 116baa3
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 116baa3

Please sign in to comment.