From 3984e4497d0a6466cb82b3749e05600ad6e24603 Mon Sep 17 00:00:00 2001
From: TwoFinger <Two-Finger@users.noreply.github.com>
Date: Mon, 14 May 2018 15:42:05 +0300
Subject: [PATCH] vis: Fix a crash when re-entering prompt window
vis->mode was incorrectly "restored" to a NULL prompt->parent_mode in
prompt_restore() because vis_prompt_show() was assuming that the
currently active window is always a regular one.
But if the active window is the command window, a new command window(s) would
be created with the old command window as its parent.
---
vis-prompt.c | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
--- a/vis-prompt.c
+++ b/vis-prompt.c
@@ -158,24 +158,26 @@ static const KeyBinding prompt_tab_bindi
void vis_prompt_show(Vis *vis, const char *title) {
Win *active = vis->win;
- Win *prompt = window_new_file(vis, title[0] == ':' ? vis->command_file : vis->search_file,
- UI_OPTION_ONELINE);
- if (!prompt)
- return;
- Text *txt = prompt->file->text;
- text_appendf(txt, "%s\n", title);
- Selection *sel = view_selections_primary_get(prompt->view);
- view_cursors_scroll_to(sel, text_size(txt)-1);
- prompt->parent = active;
- prompt->parent_mode = vis->mode;
- vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Enter>", &prompt_enter_binding);
- vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Enter>", &prompt_enter_binding);
- vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<C-j>", &prompt_enter_binding);
- vis_window_mode_map(prompt, VIS_MODE_VISUAL, true, "<Enter>", &prompt_enter_binding);
- vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Escape>", &prompt_esc_binding);
- vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Up>", &prompt_up_binding);
- if (CONFIG_LUA)
- vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Tab>", &prompt_tab_binding);
+ if (active->file != vis->command_file && active->file != vis->search_file) {
+ Win *prompt = window_new_file(vis, title[0] == ':' ? vis->command_file : vis->search_file,
+ UI_OPTION_ONELINE);
+ if (!prompt)
+ return;
+ Text *txt = prompt->file->text;
+ text_appendf(txt, "%s\n", title);
+ Selection *sel = view_selections_primary_get(prompt->view);
+ view_cursors_scroll_to(sel, text_size(txt)-1);
+ prompt->parent = active;
+ prompt->parent_mode = vis->mode;
+ vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Enter>", &prompt_enter_binding);
+ vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Enter>", &prompt_enter_binding);
+ vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<C-j>", &prompt_enter_binding);
+ vis_window_mode_map(prompt, VIS_MODE_VISUAL, true, "<Enter>", &prompt_enter_binding);
+ vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Escape>", &prompt_esc_binding);
+ vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Up>", &prompt_up_binding);
+ if (CONFIG_LUA)
+ vis_window_mode_map(prompt, VIS_MODE_INSERT, true, "<Tab>", &prompt_tab_binding);
+ }
vis_mode_switch(vis, VIS_MODE_INSERT);
}