on master help sign in
Fix preview bug (#3644)

* Fix preview bug * Add comment to empty case

commitaa00a470f31514b792e219513ffb3806a5e5b53e authorJoe <Josephharrisonlim@gmail.com> dateTue 20 Sep 2022, 03:40 (4 years ago) parent1df32c9
2 files changed+6−3
helix-term/src/commands/typed.rs+4−1 helix-term/src/ui/prompt.rs+2−2
helix-term/src/commands/typed.rs+4−1
@@ -715,7 +715,10 @@ fn theme(
715715 cx.editor.unset_theme_preview();
716716 }
717717 PromptEvent::Update => {
718− if let Some(theme_name) = args.first() {
718+ if args.is_empty() {
719+ // Ensures that a preview theme gets cleaned up if the user backspaces until the prompt is empty.
720+ cx.editor.unset_theme_preview();
721+ } else if let Some(theme_name) = args.first() {
719722 if let Ok(theme) = cx.editor.theme_loader.load(theme_name) {
720723 if !(true_color || theme.is_16_color()) {
721724 bail!("Unsupported theme: theme requires true color support");
helix-term/src/ui/prompt.rs+2−2
@@ -293,6 +293,7 @@ impl Prompt {
293293 register: char,
294294 direction: CompletionDirection,
295295 ) {
296+ (self.callback_fn)(cx, &self.line, PromptEvent::Abort);
296297 let register = cx.editor.registers.get_mut(register).read();
297298
298299 if register.is_empty() {
@@ -314,6 +315,7 @@ impl Prompt {
314315 self.history_pos = Some(index);
315316
316317 self.move_end();
318+ (self.callback_fn)(cx, &self.line, PromptEvent::Update);
317319 self.recalculate_completion(cx.editor);
318320 }
319321
@@ -564,13 +566,11 @@ impl Component for Prompt {
564566 ctrl!('p') | key!(Up) => {
565567 if let Some(register) = self.history_register {
566568 self.change_history(cx, register, CompletionDirection::Backward);
567− (self.callback_fn)(cx, &self.line, PromptEvent::Update);
568569 }
569570 }
570571 ctrl!('n') | key!(Down) => {
571572 if let Some(register) = self.history_register {
572573 self.change_history(cx, register, CompletionDirection::Forward);
573− (self.callback_fn)(cx, &self.line, PromptEvent::Update);
574574 }
575575 }
576576 key!(Tab) => {