@@ -24,7 +24,7 @@ pub struct Prompt {
2424 selection: Option<usize>,
2525 history_register: Option<char>,
2626 history_pos: Option<usize>,
27− completion_fn: Box<dyn FnMut(&Context, &str) -> Vec<Completion>>,
27+ completion_fn: Box<dyn FnMut(&Editor, &str) -> Vec<Completion>>,
2828 callback_fn: Box<dyn FnMut(&mut Context, &str, PromptEvent)>,
2929 pub doc_fn: Box<dyn Fn(&str) -> Option<&'static str>>,
3030}
@@ -59,7 +59,7 @@ impl Prompt {
5959 pub fn new(
6060 prompt: Cow<'static, str>,
6161 history_register: Option<char>,
62− completion_fn: impl FnMut(&Context, &str) -> Vec<Completion> + 'static,
62+ completion_fn: impl FnMut(&Editor, &str) -> Vec<Completion> + 'static,
6363 callback_fn: impl FnMut(&mut Context, &str, PromptEvent) + 'static,
6464 ) -> Self {
6565 Self {
@@ -76,6 +76,10 @@ impl Prompt {
7676 }
7777 }
7878
79+ pub fn recalculate_completion(&mut self, editor: &Editor) {
80+ self.completion = (self.completion_fn)(editor, &self.line);
81+ }
82+
7983 /// Compute the cursor position after applying movement
8084 /// Taken from: https://github.com/wez/wezterm/blob/e0b62d07ca9bf8ce69a61e30a3c20e7abc48ce7e/termwiz/src/lineedit/mod.rs#L516-L611
8185 fn eval_movement(&self, movement: Movement) -> usize {
@@ -183,7 +187,7 @@ impl Prompt {
183187 if let Ok(Some(pos)) = cursor.next_boundary(&self.line, 0) {
184188 self.cursor = pos;
185189 }
186− self.completion = (self.completion_fn)(cx, &self.line);
190+ self.recalculate_completion(cx.editor);
187191 self.exit_selection();
188192 }
189193
@@ -211,7 +215,7 @@ impl Prompt {
211215 self.cursor = pos;
212216
213217 self.exit_selection();
214− self.completion = (self.completion_fn)(cx, &self.line);
218+ self.recalculate_completion(cx.editor);
215219 }
216220
217221 pub fn delete_char_forwards(&mut self, cx: &Context) {
@@ -219,7 +223,7 @@ impl Prompt {
219223 self.line.replace_range(self.cursor..pos, "");
220224
221225 self.exit_selection();
222− self.completion = (self.completion_fn)(cx, &self.line);
226+ self.recalculate_completion(cx.editor);
223227 }
224228
225229 pub fn delete_word_backwards(&mut self, cx: &Context) {
@@ -228,7 +232,7 @@ impl Prompt {
228232 self.cursor = pos;
229233
230234 self.exit_selection();
231− self.completion = (self.completion_fn)(cx, &self.line);
235+ self.recalculate_completion(cx.editor);
232236 }
233237
234238 pub fn delete_word_forwards(&mut self, cx: &Context) {
@@ -236,7 +240,7 @@ impl Prompt {
236240 self.line.replace_range(self.cursor..pos, "");
237241
238242 self.exit_selection();
239− self.completion = (self.completion_fn)(cx, &self.line);
243+ self.recalculate_completion(cx.editor);
240244 }
241245
242246 pub fn kill_to_start_of_line(&mut self, cx: &Context) {
@@ -245,7 +249,7 @@ impl Prompt {
245249 self.cursor = pos;
246250
247251 self.exit_selection();
248− self.completion = (self.completion_fn)(cx, &self.line);
252+ self.recalculate_completion(cx.editor);
249253 }
250254
251255 pub fn kill_to_end_of_line(&mut self, cx: &Context) {
@@ -253,13 +257,13 @@ impl Prompt {
253257 self.line.replace_range(self.cursor..pos, "");
254258
255259 self.exit_selection();
256− self.completion = (self.completion_fn)(cx, &self.line);
260+ self.recalculate_completion(cx.editor);
257261 }
258262
259263 pub fn clear(&mut self, cx: &Context) {
260264 self.line.clear();
261265 self.cursor = 0;
262− self.completion = (self.completion_fn)(cx, &self.line);
266+ self.recalculate_completion(cx.editor);
263267 self.exit_selection();
264268 }
265269
@@ -474,7 +478,7 @@ impl Component for Prompt {
474478 }
475479 key!(Enter) => {
476480 if self.selection.is_some() && self.line.ends_with(std::path::MAIN_SEPARATOR) {
477− self.completion = (self.completion_fn)(cx, &self.line);
481+ self.recalculate_completion(cx.editor);
478482 self.exit_selection();
479483 } else {
480484 (self.callback_fn)(cx, &self.line, PromptEvent::Validate);
@@ -525,7 +529,6 @@ impl Component for Prompt {
525529 }
526530
527531 fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
528− self.completion = (self.completion_fn)(cx, &self.line);
529532 self.render_prompt(area, surface, cx)
530533 }
531534