Skip to content

Commit cd6ce15

Browse files
A-Walruspathwave
authored andcommitted
Show "Invalid regex" message on enter (Validate) (helix-editor#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
1 parent 67e5fcc commit cd6ce15

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

helix-term/src/ui/mod.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ mod spinner;
1212
mod statusline;
1313
mod text;
1414

15+
use crate::compositor::{Component, Compositor};
16+
use crate::job;
1517
pub use completion::Completion;
1618
pub use editor::EditorView;
1719
pub 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
}

0 commit comments

Comments
 (0)