aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-01-22 08:13:14 +0000
committerBlaž Hrastnik2021-01-22 08:13:14 +0000
commit2bea5db7bdb3ad3fa029df830d824cd5c26a153f (patch)
treee45016157d4c3db7a56c5935f3e33843bc0daf87 /helix-term/src/ui
parenta702af0aeb4562cbcdf8e2bc4008b8ce95da9a56 (diff)
commands: Implement select_on_matches.
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r--helix-term/src/ui/mod.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index 5ef967b0..bd40b249 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -9,12 +9,53 @@ pub use prompt::{Prompt, PromptEvent};
pub use tui::layout::Rect;
pub use tui::style::{Color, Modifier, Style};
+use helix_core::regex::Regex;
+use helix_view::{Document, Editor};
+
// TODO: temp
#[inline(always)]
pub fn text_color() -> Style {
Style::default().fg(Color::Rgb(219, 191, 239)) // lilac
}
+pub fn regex_prompt(
+ cx: &mut crate::commands::Context,
+ prompt: String,
+ fun: impl Fn(&mut Document, Regex) + 'static,
+) -> Prompt {
+ let snapshot = cx.doc().state.clone();
+
+ Prompt::new(
+ prompt,
+ |input: &str| Vec::new(), // this is fine because Vec::new() doesn't allocate
+ move |editor: &mut Editor, input: &str, event: PromptEvent| {
+ match event {
+ PromptEvent::Abort => {
+ // revert state
+ let doc = &mut editor.view_mut().doc;
+ doc.state = snapshot.clone();
+ }
+ PromptEvent::Validate => {
+ //
+ }
+ PromptEvent::Update => {
+ match Regex::new(input) {
+ Ok(regex) => {
+ let doc = &mut editor.view_mut().doc;
+
+ // revert state to what it was before the last update
+ doc.state = snapshot.clone();
+
+ fun(doc, regex);
+ }
+ Err(_err) => (), // TODO: mark command line as error
+ }
+ }
+ }
+ },
+ )
+}
+
use std::path::{Path, PathBuf};
pub fn file_picker(root: &str, ex: &'static smol::Executor) -> Picker<PathBuf> {
use ignore::Walk;