16

patch 8.2.0191: cannot put a terminal in a popup window · vim/vim@219c7d0 · GitH...

 4 years ago
source link: https://github.com/vim/vim/commit/219c7d063823498be22aae46dd024d77b5fb2a58
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

cannot put a terminal in a popup window · vim/vim@219c7d0 · GitHubPermalink

Browse files

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.
  • Loading branch information

brammool

committed on Feb 2

1 parent ab067a2 commit 219c7d063823498be22aae46dd024d77b5fb2a58
Showing with 306 additions and 60 deletions.
@@ -491,7 +491,7 @@ win_line(
{
extra_check = TRUE;
get_term_attr = TRUE;
win_attr = term_get_attr(wp->w_buffer, lnum, -1);
win_attr = term_get_attr(wp, lnum, -1);
}
#endif
@@ -1419,7 +1419,7 @@ win_line(
syntax_attr = 0;
# ifdef FEAT_TERMINAL
if (get_term_attr)
syntax_attr = term_get_attr(wp->w_buffer, lnum, vcol);
syntax_attr = term_get_attr(wp, lnum, vcol);
# endif
// Get syntax attribute.
if (has_syntax)
@@ -3134,8 +3134,9 @@ syn_id2colors(int hl_id, guicolor_T *fgp, guicolor_T *bgp)
#endif
#if (defined(MSWIN) \
&& (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) \
&& defined(FEAT_TERMGUICOLORS)) || defined(PROTO)
&& (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) \
&& defined(FEAT_TERMGUICOLORS)) \
|| defined(FEAT_TERMINAL) || defined(PROTO)
void
syn_id2cterm_bg(int hl_id, int *fgp, int *bgp)
{
@@ -345,8 +345,10 @@
// Give an error in curwin is a popup window and evaluate to TRUE.
#ifdef FEAT_PROP_POPUP
# define ERROR_IF_POPUP_WINDOW error_if_popup_window()
# define ERROR_IF_TERM_POPUP_WINDOW error_if_term_popup_window()
#else
# define ERROR_IF_POPUP_WINDOW 0
# define ERROR_IF_TERM_POPUP_WINDOW 0
#endif
@@ -1735,6 +1735,11 @@ jump_to_mouse(
wp = curwin;
# endif
}
#endif
#if defined(FEAT_PROP_POPUP) && defined(FEAT_TERMINAL)
if (popup_is_popup(curwin) && curbuf->b_term != NULL)
// terminal in popup window: don't jump to another window
return IN_OTHER_WIN;
#endif
// Only change window focus when not clicking on or dragging the
// status line. Do change focus when releasing the mouse button
@@ -2128,6 +2128,12 @@ did_set_string_option(
errmsg = e_invarg;
}
}
// 'wincolor'
else if (varp == &curwin->w_p_wcr)
{
if (curwin->w_buffer->b_term != NULL)
term_update_colors();
}
# if defined(MSWIN)
// 'termwintype'
else if (varp == &p_twt)
@@ -1337,6 +1337,11 @@ popup_adjust_position(win_T *wp)
wp->w_has_scrollbar = wp->w_want_scrollbar
&& (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count);
#ifdef FEAT_TERMINAL
if (wp->w_buffer->b_term != NULL)
// Terminal window never has a scrollbar, adjusts to window height.
wp->w_has_scrollbar = FALSE;
#endif
if (wp->w_has_scrollbar)
{
++right_extra;
@@ -1769,20 +1774,13 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
semsg(_(e_nobufnr), argvars[0].vval.v_number);
return NULL;
}
#ifdef FEAT_TERMINAL
if (buf->b_term != NULL)
{
emsg(_("E278: Cannot put a terminal buffer in a popup window"));
return NULL;
}
#endif
}
else if (!(argvars[0].v_type == VAR_STRING
&& argvars[0].vval.v_string != NULL)
&& !(argvars[0].v_type == VAR_LIST
&& argvars[0].vval.v_list != NULL))
{
emsg(_(e_listreq));
emsg(_("E450: buffer number, text or a list required"));
return NULL;
}
if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL)
@@ -2031,6 +2029,10 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
redraw_all_later(NOT_VALID);
popup_mask_refresh = TRUE;
// When running a terminal in the popup it becomes the current window.
if (buf->b_term != NULL)
win_enter(wp, FALSE);
return wp;
}
@@ -2107,6 +2109,13 @@ popup_close_and_callback(win_T *wp, typval_T *arg)
{
int id = wp->w_id;
if (wp == curwin && curbuf->b_term != NULL)
{
// Closing popup window with a terminal: put focus back on the previous
// window.
win_enter(prevwin, FALSE);
}
// Just in case a check higher up is missing.
if (wp == curwin && ERROR_IF_POPUP_WINDOW)
return;
@@ -2118,7 +2127,7 @@ popup_close_and_callback(win_T *wp, typval_T *arg)
popup_close(id);
}
static void
void
popup_close_with_retval(win_T *wp, int retval)
{
typval_T res;
@@ -2834,14 +2843,28 @@ f_popup_getoptions(typval_T *argvars, typval_T *rettv)
int
error_if_popup_window()
{
if (WIN_IS_POPUP(curwin))
// win_execute() may set "curwin" to a popup window temporarily, but many
// commands are disallowed then. When a terminal runs in the popup most
// things are allowed.
if (WIN_IS_POPUP(curwin) && curbuf->b_term == NULL)
{
emsg(_("E994: Not allowed in a popup window"));
return TRUE;
}
return FALSE;
}
int
error_if_term_popup_window()
{
if (WIN_IS_POPUP(curwin) && curbuf->b_term != NULL)
{
emsg(_("E899: Not allowed for a terminal in a popup window"));

itchyny on Feb 3

Bram, E899 is already used for Argument of %s must be a List or Blob.

static char *e_listblobarg = N_("E899: Argument of %s must be a List or Blob");

brammool via email on Feb 4

Author

Member

Bram, `E899` is already used for `Argument of %s must be a List or Blob`. https://github.com/vim/vim/blob/db661fb95dc41b7a9438cf3cd4e77f8410bc81c0/src/list.c#L18
I think that was meant to be E999 and renumbered later. I'll use one of the available numbers.
return TRUE;
}
return FALSE;
}
/*
* Reset all the "handled_flag" flags in global popup windows and popup windows
* in the current tab page.
@@ -2961,6 +2984,10 @@ popup_do_filter(int c)
int state;
int was_must_redraw = must_redraw;
// Popup window with terminal always gets focus.
if (popup_is_popup(curwin) && curbuf->b_term != NULL)
return FALSE;
if (recursive)
return FALSE;
recursive = TRUE;
@@ -3430,6 +3457,9 @@ update_popups(void (*win_update)(win_T *wp))
wp->w_winrow -= top_off;
wp->w_wincol -= left_extra;
// cursor position matters in terminal
wp->w_wrow += top_off;
wp->w_wcol += left_extra;
total_width = popup_width(wp);
total_height = popup_height(wp);
@@ -19,6 +19,7 @@ void f_popup_clear(typval_T *argvars, typval_T *rettv);
void f_popup_create(typval_T *argvars, typval_T *rettv);
void f_popup_atcursor(typval_T *argvars, typval_T *rettv);
void f_popup_beval(typval_T *argvars, typval_T *rettv);
void popup_close_with_retval(win_T *wp, int retval);
void popup_close_for_mouse_click(win_T *wp);
void popup_handle_mouse_moved(void);
void f_popup_filter_menu(typval_T *argvars, typval_T *rettv);
@@ -41,6 +42,7 @@ void f_popup_getpos(typval_T *argvars, typval_T *rettv);
void f_popup_locate(typval_T *argvars, typval_T *rettv);
void f_popup_getoptions(typval_T *argvars, typval_T *rettv);
int error_if_popup_window(void);
int error_if_term_popup_window(void);
void popup_reset_handled(int handled_flag);
win_T *find_next_popup(int lowest, int handled_flag);
int popup_do_filter(int c);
@@ -26,7 +26,8 @@ void term_update_window(win_T *wp);
int term_is_finished(buf_T *buf);
int term_show_buffer(buf_T *buf);
void term_change_in_curbuf(void);
int term_get_attr(buf_T *buf, linenr_T lnum, int col);
int term_get_attr(win_T *wp, linenr_T lnum, int col);
void term_update_colors(void);
char_u *term_get_status_text(term_T *term);
int set_ref_in_term(int copyID);
void set_terminal_default_colors(int cterm_fg, int cterm_bg);

0 comments on commit 219c7d0

Please sign in to comment.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK