diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs index 566730e1a..23bb3babc 100644 --- a/helix-term/src/commands/dap.rs +++ b/helix-term/src/commands/dap.rs @@ -3,7 +3,7 @@ use crate::{ commands, compositor::Compositor, job::Callback, - ui::{FilePicker, Prompt, PromptEvent}, + ui::{FilePicker, Picker, Prompt, PromptEvent}, }; use helix_core::{ syntax::{DebugArgumentValue, DebugConfigCompletion}, @@ -319,14 +319,16 @@ pub fn dap_launch(cx: &mut Context) { } }; - cx.editor.debug_config_picker = Some(config.templates.iter().map(|t| t.name.clone()).collect()); - cx.editor.debug_config_completions = Some( - config - .templates - .iter() - .map(|t| t.completion.clone()) - .collect(), - ); + cx.push_layer(Box::new(Picker::new( + true, + config.templates.clone(), + |template| template.name.as_str().into(), + |editor, template, _action| { + let completions = template.completion.clone(); + editor.debug_config_completions = completions; + // TODO: need some way to manipulate the compositor to push a new prompt here + }, + ))); // TODO: wrap in popup with fixed size } pub fn dap_toggle_breakpoint(cx: &mut Context) { diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 26a0358d1..706cf8bb5 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -902,29 +902,11 @@ impl EditorView { cxt: &mut commands::Context, event: KeyEvent, ) -> Option { - if let Some(picker) = cxt.editor.debug_config_picker.clone() { - match event { - KeyEvent { - code: KeyCode::Esc, .. - } => {} - KeyEvent { - code: KeyCode::Char(char), - .. - } => { - let (i, name) = match picker.iter().position(|t| t.starts_with(char)) { - Some(pos) => (pos, picker.get(pos).unwrap().clone()), - None => return None, - }; - let completions = cxt.editor.debug_config_completions.clone().unwrap(); - let completion = completions.get(i).unwrap().clone(); - if !completion.is_empty() { - let prompt = Self::debug_parameter_prompt(completion, name, Vec::new()); - cxt.push_layer(Box::new(prompt)); - } - } - _ => return None, - } - cxt.editor.debug_config_picker = None; + if !cxt.editor.debug_config_completions.is_empty() { + let completions = std::mem::take(&mut cxt.editor.debug_config_completions); + // TODO name + let prompt = Self::debug_parameter_prompt(completions, "test".to_string(), Vec::new()); + cxt.push_layer(Box::new(prompt)); return None; } @@ -1429,26 +1411,6 @@ impl Component for EditorView { info.render(area, surface, cx); } - if let Some(ref configs) = cx.editor.debug_config_picker { - let mut text = String::new(); - let mut height = 0; - let mut max_len = 20; - - for line in configs { - max_len = max_len.max(line.len() as u16 + 2); - height += 1; - text.push_str(&format!("{} {}\n", line.chars().next().unwrap(), line)); - } - - let mut info = Info { - height: 20.min(height + 1), - width: 70.min(max_len), - title: "Debug targets".to_owned(), - text: text + "Exit Esc", - }; - info.render(area, surface, cx); - } - if cx.editor.config.auto_info { if let Some(ref mut info) = self.autoinfo { info.render(area, surface, cx); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 591e0492b..4efadaf6a 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -126,8 +126,7 @@ pub struct Editor { pub debugger: Option, pub debugger_events: SelectAll>, pub breakpoints: HashMap>, - pub debug_config_picker: Option>, - pub debug_config_completions: Option>>, + pub debug_config_completions: Vec, pub variables: Option>, pub variables_page: usize, @@ -175,8 +174,7 @@ impl Editor { debugger: None, debugger_events: SelectAll::new(), breakpoints: HashMap::new(), - debug_config_picker: None, - debug_config_completions: None, + debug_config_completions: Vec::new(), variables: None, variables_page: 0, syn_loader: config_loader,