From b4c32ee6fca860949c7120099d4476bd31588cb3 Mon Sep 17 00:00:00 2001 From: Joseph Harrison-Lim Date: Thu, 1 Sep 2022 22:20:18 -0400 Subject: [PATCH 1/2] Fix preview bug --- helix-term/src/commands/typed.rs | 4 +++- helix-term/src/ui/prompt.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index ad4e7f4ce9da..943684758140 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -715,7 +715,9 @@ fn theme( cx.editor.unset_theme_preview(); } PromptEvent::Update => { - if let Some(theme_name) = args.first() { + if args.is_empty() { + cx.editor.unset_theme_preview(); + } else if let Some(theme_name) = args.first() { if let Ok(theme) = cx.editor.theme_loader.load(theme_name) { if !(true_color || theme.is_16_color()) { bail!("Unsupported theme: theme requires true color support"); diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 24fc8233339d..5ab0fb215b86 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -293,6 +293,7 @@ impl Prompt { register: char, direction: CompletionDirection, ) { + (self.callback_fn)(cx, &self.line, PromptEvent::Abort); let register = cx.editor.registers.get_mut(register).read(); if register.is_empty() { @@ -314,6 +315,7 @@ impl Prompt { self.history_pos = Some(index); self.move_end(); + (self.callback_fn)(cx, &self.line, PromptEvent::Update); self.recalculate_completion(cx.editor); } @@ -564,13 +566,11 @@ impl Component for Prompt { ctrl!('p') | key!(Up) => { if let Some(register) = self.history_register { self.change_history(cx, register, CompletionDirection::Backward); - (self.callback_fn)(cx, &self.line, PromptEvent::Update); } } ctrl!('n') | key!(Down) => { if let Some(register) = self.history_register { self.change_history(cx, register, CompletionDirection::Forward); - (self.callback_fn)(cx, &self.line, PromptEvent::Update); } } key!(Tab) => { From 3b3873a081b63566e4ce58c9d224cf9c02c08f19 Mon Sep 17 00:00:00 2001 From: Joseph Harrison-Lim Date: Thu, 1 Sep 2022 22:25:09 -0400 Subject: [PATCH 2/2] Add comment to empty case --- helix-term/src/commands/typed.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 943684758140..4c19327559c9 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -716,6 +716,7 @@ fn theme( } PromptEvent::Update => { if args.is_empty() { + // Ensures that a preview theme gets cleaned up if the user backspaces until the prompt is empty. cx.editor.unset_theme_preview(); } else if let Some(theme_name) = args.first() { if let Ok(theme) = cx.editor.theme_loader.load(theme_name) {