mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.1.1455: popup_atcursor() not completely implemented
Problem: Popup_atcursor() not completely implemented. Solution: Add the default for the "moved" property.
This commit is contained in:
15
src/normal.c
15
src/normal.c
@@ -3461,13 +3461,14 @@ find_ident_at_pos(
|
|||||||
if (ptr[col] == NUL || (i == 0
|
if (ptr[col] == NUL || (i == 0
|
||||||
&& (has_mbyte ? this_class != 2 : !vim_iswordc(ptr[col]))))
|
&& (has_mbyte ? this_class != 2 : !vim_iswordc(ptr[col]))))
|
||||||
{
|
{
|
||||||
/*
|
// didn't find an identifier or string
|
||||||
* didn't find an identifier or string
|
if ((find_type & FIND_NOERROR) == 0)
|
||||||
*/
|
{
|
||||||
if (find_type & FIND_STRING)
|
if (find_type & FIND_STRING)
|
||||||
emsg(_("E348: No string under cursor"));
|
emsg(_("E348: No string under cursor"));
|
||||||
else
|
else
|
||||||
emsg(_(e_noident));
|
emsg(_(e_noident));
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ptr += col;
|
ptr += col;
|
||||||
|
@@ -138,12 +138,39 @@ get_padding_border(dict_T *dict, int *array, char *name, int max_val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Go through the options in "dict" and apply them to buffer "buf" displayed in
|
* Used when popup options contain "moved": set default moved values.
|
||||||
* popup window "wp".
|
|
||||||
* When called from f_popup_atcursor() "atcursor" is TRUE.
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict, int atcursor)
|
set_moved_values(win_T *wp)
|
||||||
|
{
|
||||||
|
wp->w_popup_curwin = curwin;
|
||||||
|
wp->w_popup_lnum = curwin->w_cursor.lnum;
|
||||||
|
wp->w_popup_mincol = curwin->w_cursor.col;
|
||||||
|
wp->w_popup_maxcol = curwin->w_cursor.col;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Used when popup options contain "moved" with "word" or "WORD".
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
set_moved_columns(win_T *wp, int flags)
|
||||||
|
{
|
||||||
|
char_u *ptr;
|
||||||
|
int len = find_ident_under_cursor(&ptr, flags | FIND_NOERROR);
|
||||||
|
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
wp->w_popup_mincol = (int)(ptr - ml_get_curline());
|
||||||
|
wp->w_popup_maxcol = wp->w_popup_mincol + len - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Go through the options in "dict" and apply them to buffer "buf" displayed in
|
||||||
|
* popup window "wp".
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict)
|
||||||
{
|
{
|
||||||
int nr;
|
int nr;
|
||||||
char_u *str;
|
char_u *str;
|
||||||
@@ -155,19 +182,6 @@ apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict, int atcursor)
|
|||||||
wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth");
|
wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth");
|
||||||
wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight");
|
wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight");
|
||||||
|
|
||||||
if (atcursor)
|
|
||||||
{
|
|
||||||
wp->w_popup_pos = POPPOS_BOTLEFT;
|
|
||||||
setcursor_mayforce(TRUE);
|
|
||||||
wp->w_wantline = screen_screenrow();
|
|
||||||
if (wp->w_wantline == 0) // cursor in first line
|
|
||||||
{
|
|
||||||
wp->w_wantline = 2;
|
|
||||||
wp->w_popup_pos = POPPOS_TOPLEFT;
|
|
||||||
}
|
|
||||||
wp->w_wantcol = screen_screencol() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
get_pos_options(wp, dict);
|
get_pos_options(wp, dict);
|
||||||
|
|
||||||
wp->w_zindex = dict_get_number(dict, (char_u *)"zindex");
|
wp->w_zindex = dict_get_number(dict, (char_u *)"zindex");
|
||||||
@@ -289,10 +303,7 @@ apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict, int atcursor)
|
|||||||
di = dict_find(dict, (char_u *)"moved", -1);
|
di = dict_find(dict, (char_u *)"moved", -1);
|
||||||
if (di != NULL)
|
if (di != NULL)
|
||||||
{
|
{
|
||||||
wp->w_popup_curwin = curwin;
|
set_moved_values(wp);
|
||||||
wp->w_popup_lnum = curwin->w_cursor.lnum;
|
|
||||||
wp->w_popup_mincol = curwin->w_cursor.col;
|
|
||||||
wp->w_popup_maxcol = curwin->w_cursor.col;
|
|
||||||
if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL)
|
if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL)
|
||||||
{
|
{
|
||||||
char_u *s = di->di_tv.vval.v_string;
|
char_u *s = di->di_tv.vval.v_string;
|
||||||
@@ -305,16 +316,7 @@ apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict, int atcursor)
|
|||||||
else if (STRCMP(s, "any") != 0)
|
else if (STRCMP(s, "any") != 0)
|
||||||
semsg(_(e_invarg2), s);
|
semsg(_(e_invarg2), s);
|
||||||
if (flags != 0)
|
if (flags != 0)
|
||||||
{
|
set_moved_columns(wp, flags);
|
||||||
char_u *ptr;
|
|
||||||
int len = find_ident_under_cursor(&ptr, flags);
|
|
||||||
|
|
||||||
if (len > 0)
|
|
||||||
{
|
|
||||||
wp->w_popup_mincol = (int)(ptr - ml_get_curline());
|
|
||||||
wp->w_popup_maxcol = wp->w_popup_mincol + len - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (di->di_tv.v_type == VAR_LIST
|
else if (di->di_tv.v_type == VAR_LIST
|
||||||
&& di->di_tv.vval.v_list != NULL
|
&& di->di_tv.vval.v_list != NULL
|
||||||
@@ -554,13 +556,19 @@ popup_adjust_position(win_T *wp)
|
|||||||
wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer);
|
wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
TYPE_NORMAL,
|
||||||
|
TYPE_ATCURSOR
|
||||||
|
} create_type_T;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* popup_create({text}, {options})
|
* popup_create({text}, {options})
|
||||||
* popup_atcursor({text}, {options})
|
* popup_atcursor({text}, {options})
|
||||||
* When called from f_popup_atcursor() "atcursor" is TRUE.
|
* When called from f_popup_atcursor() "atcursor" is TRUE.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
popup_create(typval_T *argvars, typval_T *rettv, int atcursor)
|
popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
|
||||||
{
|
{
|
||||||
win_T *wp;
|
win_T *wp;
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
@@ -652,8 +660,23 @@ popup_create(typval_T *argvars, typval_T *rettv, int atcursor)
|
|||||||
ml_delete(buf->b_ml.ml_line_count, FALSE);
|
ml_delete(buf->b_ml.ml_line_count, FALSE);
|
||||||
curbuf = curwin->w_buffer;
|
curbuf = curwin->w_buffer;
|
||||||
|
|
||||||
|
if (type == TYPE_ATCURSOR)
|
||||||
|
{
|
||||||
|
wp->w_popup_pos = POPPOS_BOTLEFT;
|
||||||
|
setcursor_mayforce(TRUE);
|
||||||
|
wp->w_wantline = screen_screenrow();
|
||||||
|
if (wp->w_wantline == 0) // cursor in first line
|
||||||
|
{
|
||||||
|
wp->w_wantline = 2;
|
||||||
|
wp->w_popup_pos = POPPOS_TOPLEFT;
|
||||||
|
}
|
||||||
|
wp->w_wantcol = screen_screencol() + 1;
|
||||||
|
set_moved_values(wp);
|
||||||
|
set_moved_columns(wp, FIND_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
// Deal with options.
|
// Deal with options.
|
||||||
apply_options(wp, buf, argvars[1].vval.v_dict, atcursor);
|
apply_options(wp, buf, argvars[1].vval.v_dict);
|
||||||
|
|
||||||
// set default values
|
// set default values
|
||||||
if (wp->w_zindex == 0)
|
if (wp->w_zindex == 0)
|
||||||
@@ -672,7 +695,7 @@ popup_create(typval_T *argvars, typval_T *rettv, int atcursor)
|
|||||||
void
|
void
|
||||||
f_popup_create(typval_T *argvars, typval_T *rettv)
|
f_popup_create(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
popup_create(argvars, rettv, FALSE);
|
popup_create(argvars, rettv, TYPE_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -681,7 +704,7 @@ f_popup_create(typval_T *argvars, typval_T *rettv)
|
|||||||
void
|
void
|
||||||
f_popup_atcursor(typval_T *argvars, typval_T *rettv)
|
f_popup_atcursor(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
popup_create(argvars, rettv, TRUE);
|
popup_create(argvars, rettv, TYPE_ATCURSOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -1009,8 +1009,9 @@ func Test_popup_moved()
|
|||||||
call assert_equal({}, popup_getpos(winid))
|
call assert_equal({}, popup_getpos(winid))
|
||||||
popupclear
|
popupclear
|
||||||
|
|
||||||
|
" WORD is the default
|
||||||
exe "normal gg0/WORD\<CR>"
|
exe "normal gg0/WORD\<CR>"
|
||||||
let winid = popup_atcursor('text', {'moved': 'WORD'})
|
let winid = popup_atcursor('text', {})
|
||||||
redraw
|
redraw
|
||||||
call assert_equal(1, popup_getpos(winid).visible)
|
call assert_equal(1, popup_getpos(winid).visible)
|
||||||
call feedkeys("eli\<Esc>", 'xt')
|
call feedkeys("eli\<Esc>", 'xt')
|
||||||
|
@@ -767,6 +767,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1455,
|
||||||
/**/
|
/**/
|
||||||
1454,
|
1454,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -879,10 +879,11 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
|
|||||||
#define SEARCH_PEEK 0x800 /* peek for typed char, cancel search */
|
#define SEARCH_PEEK 0x800 /* peek for typed char, cancel search */
|
||||||
#define SEARCH_COL 0x1000 /* start at specified column instead of zero */
|
#define SEARCH_COL 0x1000 /* start at specified column instead of zero */
|
||||||
|
|
||||||
/* Values for find_ident_under_cursor() */
|
// Values for find_ident_under_cursor()
|
||||||
#define FIND_IDENT 1 /* find identifier (word) */
|
#define FIND_IDENT 1 // find identifier (word)
|
||||||
#define FIND_STRING 2 /* find any string (WORD) */
|
#define FIND_STRING 2 // find any string (WORD)
|
||||||
#define FIND_EVAL 4 /* include "->", "[]" and "." */
|
#define FIND_EVAL 4 // include "->", "[]" and "."
|
||||||
|
#define FIND_NOERROR 8 // no error when no word found
|
||||||
|
|
||||||
/* Values for file_name_in_line() */
|
/* Values for file_name_in_line() */
|
||||||
#define FNAME_MESS 1 /* give error message */
|
#define FNAME_MESS 1 /* give error message */
|
||||||
|
Reference in New Issue
Block a user