comparison src/popupwin.c @ 19265:ce8c47ed54e5 v8.2.0191

patch 8.2.0191: cannot put a terminal in a popup window Commit: https://github.com/vim/vim/commit/219c7d063823498be22aae46dd024d77b5fb2a58 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 1 21:57:29 2020 +0100 patch 8.2.0191: cannot put a terminal in a popup window Problem: Cannot put a terminal in a popup window. Solution: Allow opening a terminal in a popup window. It will always have keyboard focus until closed.
author Bram Moolenaar <Bram@vim.org>
date Sat, 01 Feb 2020 22:00:04 +0100
parents c53dbbf3229b
children c7903f92ed75
comparison
equal deleted inserted replaced
19264:489e4c8101ba 19265:ce8c47ed54e5
1335 if (wp->w_firstline < 0) 1335 if (wp->w_firstline < 0)
1336 wp->w_topline = lnum > 0 ? lnum + 1 : lnum; 1336 wp->w_topline = lnum > 0 ? lnum + 1 : lnum;
1337 1337
1338 wp->w_has_scrollbar = wp->w_want_scrollbar 1338 wp->w_has_scrollbar = wp->w_want_scrollbar
1339 && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count); 1339 && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count);
1340 #ifdef FEAT_TERMINAL
1341 if (wp->w_buffer->b_term != NULL)
1342 // Terminal window never has a scrollbar, adjusts to window height.
1343 wp->w_has_scrollbar = FALSE;
1344 #endif
1340 if (wp->w_has_scrollbar) 1345 if (wp->w_has_scrollbar)
1341 { 1346 {
1342 ++right_extra; 1347 ++right_extra;
1343 ++extra_width; 1348 ++extra_width;
1344 // make space for the scrollbar if needed, when lines wrap and when 1349 // make space for the scrollbar if needed, when lines wrap and when
1767 if (buf == NULL) 1772 if (buf == NULL)
1768 { 1773 {
1769 semsg(_(e_nobufnr), argvars[0].vval.v_number); 1774 semsg(_(e_nobufnr), argvars[0].vval.v_number);
1770 return NULL; 1775 return NULL;
1771 } 1776 }
1772 #ifdef FEAT_TERMINAL
1773 if (buf->b_term != NULL)
1774 {
1775 emsg(_("E278: Cannot put a terminal buffer in a popup window"));
1776 return NULL;
1777 }
1778 #endif
1779 } 1777 }
1780 else if (!(argvars[0].v_type == VAR_STRING 1778 else if (!(argvars[0].v_type == VAR_STRING
1781 && argvars[0].vval.v_string != NULL) 1779 && argvars[0].vval.v_string != NULL)
1782 && !(argvars[0].v_type == VAR_LIST 1780 && !(argvars[0].v_type == VAR_LIST
1783 && argvars[0].vval.v_list != NULL)) 1781 && argvars[0].vval.v_list != NULL))
1784 { 1782 {
1785 emsg(_(e_listreq)); 1783 emsg(_("E450: buffer number, text or a list required"));
1786 return NULL; 1784 return NULL;
1787 } 1785 }
1788 if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) 1786 if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL)
1789 { 1787 {
1790 emsg(_(e_dictreq)); 1788 emsg(_(e_dictreq));
2029 wp->w_vsep_width = 0; 2027 wp->w_vsep_width = 0;
2030 2028
2031 redraw_all_later(NOT_VALID); 2029 redraw_all_later(NOT_VALID);
2032 popup_mask_refresh = TRUE; 2030 popup_mask_refresh = TRUE;
2033 2031
2032 // When running a terminal in the popup it becomes the current window.
2033 if (buf->b_term != NULL)
2034 win_enter(wp, FALSE);
2035
2034 return wp; 2036 return wp;
2035 } 2037 }
2036 2038
2037 /* 2039 /*
2038 * popup_clear() 2040 * popup_clear()
2105 static void 2107 static void
2106 popup_close_and_callback(win_T *wp, typval_T *arg) 2108 popup_close_and_callback(win_T *wp, typval_T *arg)
2107 { 2109 {
2108 int id = wp->w_id; 2110 int id = wp->w_id;
2109 2111
2112 if (wp == curwin && curbuf->b_term != NULL)
2113 {
2114 // Closing popup window with a terminal: put focus back on the previous
2115 // window.
2116 win_enter(prevwin, FALSE);
2117 }
2118
2110 // Just in case a check higher up is missing. 2119 // Just in case a check higher up is missing.
2111 if (wp == curwin && ERROR_IF_POPUP_WINDOW) 2120 if (wp == curwin && ERROR_IF_POPUP_WINDOW)
2112 return; 2121 return;
2113 2122
2114 if (wp->w_close_cb.cb_name != NULL) 2123 if (wp->w_close_cb.cb_name != NULL)
2116 invoke_popup_callback(wp, arg); 2125 invoke_popup_callback(wp, arg);
2117 2126
2118 popup_close(id); 2127 popup_close(id);
2119 } 2128 }
2120 2129
2121 static void 2130 void
2122 popup_close_with_retval(win_T *wp, int retval) 2131 popup_close_with_retval(win_T *wp, int retval)
2123 { 2132 {
2124 typval_T res; 2133 typval_T res;
2125 2134
2126 res.v_type = VAR_NUMBER; 2135 res.v_type = VAR_NUMBER;
2832 } 2841 }
2833 2842
2834 int 2843 int
2835 error_if_popup_window() 2844 error_if_popup_window()
2836 { 2845 {
2837 if (WIN_IS_POPUP(curwin)) 2846 // win_execute() may set "curwin" to a popup window temporarily, but many
2847 // commands are disallowed then. When a terminal runs in the popup most
2848 // things are allowed.
2849 if (WIN_IS_POPUP(curwin) && curbuf->b_term == NULL)
2838 { 2850 {
2839 emsg(_("E994: Not allowed in a popup window")); 2851 emsg(_("E994: Not allowed in a popup window"));
2852 return TRUE;
2853 }
2854 return FALSE;
2855 }
2856
2857 int
2858 error_if_term_popup_window()
2859 {
2860 if (WIN_IS_POPUP(curwin) && curbuf->b_term != NULL)
2861 {
2862 emsg(_("E899: Not allowed for a terminal in a popup window"));
2840 return TRUE; 2863 return TRUE;
2841 } 2864 }
2842 return FALSE; 2865 return FALSE;
2843 } 2866 }
2844 2867
2958 int res = FALSE; 2981 int res = FALSE;
2959 win_T *wp; 2982 win_T *wp;
2960 int save_KeyTyped = KeyTyped; 2983 int save_KeyTyped = KeyTyped;
2961 int state; 2984 int state;
2962 int was_must_redraw = must_redraw; 2985 int was_must_redraw = must_redraw;
2986
2987 // Popup window with terminal always gets focus.
2988 if (popup_is_popup(curwin) && curbuf->b_term != NULL)
2989 return FALSE;
2963 2990
2964 if (recursive) 2991 if (recursive)
2965 return FALSE; 2992 return FALSE;
2966 recursive = TRUE; 2993 recursive = TRUE;
2967 2994
3428 wp->w_cursor.lnum = wp->w_botline - 1; 3455 wp->w_cursor.lnum = wp->w_botline - 1;
3429 } 3456 }
3430 3457
3431 wp->w_winrow -= top_off; 3458 wp->w_winrow -= top_off;
3432 wp->w_wincol -= left_extra; 3459 wp->w_wincol -= left_extra;
3460 // cursor position matters in terminal
3461 wp->w_wrow += top_off;
3462 wp->w_wcol += left_extra;
3433 3463
3434 total_width = popup_width(wp); 3464 total_width = popup_width(wp);
3435 total_height = popup_height(wp); 3465 total_height = popup_height(wp);
3436 popup_attr = get_wcr_attr(wp); 3466 popup_attr = get_wcr_attr(wp);
3437 3467