Skip to content

Commit

Permalink
Merge remote-tracking branch 'vim/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ychin committed Sep 15, 2022
2 parents fa37c18 + 3735f11 commit d404ddd
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 19 deletions.
9 changes: 8 additions & 1 deletion src/change.c
Expand Up @@ -1404,12 +1404,19 @@ open_line(
int vreplace_mode;
int did_append; // appended a new line
int saved_pi = curbuf->b_p_pi; // copy of preserveindent setting
#ifdef FEAT_PROP_POPUP
int at_eol; // cursor after last character
#endif

// make a copy of the current line so we can mess with it
saved_line = vim_strsave(ml_get_curline());
if (saved_line == NULL) // out of memory!
return FALSE;

#ifdef FEAT_PROP_POPUP
at_eol = curwin->w_cursor.col >= (int)STRLEN(saved_line);
#endif

if (State & VREPLACE_FLAG)
{
// With MODE_VREPLACE we make a copy of the next line, which we will be
Expand Down Expand Up @@ -2133,7 +2140,7 @@ open_line(
if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0)
// Properties after the split move to the next line.
adjust_props_for_split(curwin->w_cursor.lnum, curwin->w_cursor.lnum,
curwin->w_cursor.col + 1, 0);
curwin->w_cursor.col + 1, 0, at_eol);
#endif
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/charset.c
Expand Up @@ -954,7 +954,7 @@ init_chartabsize_arg(
cts->cts_line = line;
cts->cts_ptr = ptr;
#ifdef FEAT_PROP_POPUP
if (lnum > 0)
if (lnum > 0 && !ignore_text_props)
{
char_u *prop_start;
int count;
Expand Down
3 changes: 2 additions & 1 deletion src/ex_cmds.c
Expand Up @@ -4684,7 +4684,8 @@ ex_substitute(exarg_T *eap)
last_line = lnum + 1;
}
#ifdef FEAT_PROP_POPUP
adjust_props_for_split(lnum + 1, lnum, plen, 1);
adjust_props_for_split(lnum + 1, lnum,
plen, 1, FALSE);
#endif
// all line numbers increase
++sub_firstlnum;
Expand Down
3 changes: 3 additions & 0 deletions src/ex_getln.c
Expand Up @@ -4655,6 +4655,8 @@ open_cmdwin(void)
// First go back to the original window.
wp = curwin;
set_bufref(&bufref, curbuf);

skip_win_fix_cursor = TRUE;
win_goto(old_curwin);

// win_goto() may trigger an autocommand that already closes the
Expand All @@ -4669,6 +4671,7 @@ open_cmdwin(void)

// Restore window sizes.
win_size_restore(&winsizes);
skip_win_fix_cursor = FALSE;
}

ga_clear(&winsizes);
Expand Down
8 changes: 8 additions & 0 deletions src/globals.h
Expand Up @@ -755,6 +755,9 @@ EXTERN int popup_visible INIT(= FALSE);
EXTERN int popup_uses_mouse_move INIT(= FALSE);

EXTERN int text_prop_frozen INIT(= 0);

// when TRUE computing the cursor position ignores text properties.
EXTERN int ignore_text_props INIT(= FALSE);
#endif

// When set the popup menu will redraw soon using the pum_win_ values. Do not
Expand Down Expand Up @@ -1738,3 +1741,8 @@ EXTERN int channel_need_redraw INIT(= FALSE);
// While executing a regexp and set to OPTION_MAGIC_ON or OPTION_MAGIC_OFF this
// overrules p_magic. Otherwise set to OPTION_MAGIC_NOT_SET.
EXTERN optmagic_T magic_overruled INIT(= OPTION_MAGIC_NOT_SET);

#ifdef FEAT_CMDWIN
// Skip win_fix_cursor() call for 'nosplitscroll' when cmdwin is closed.
EXTERN int skip_win_fix_cursor INIT(= FALSE);
#endif
6 changes: 6 additions & 0 deletions src/indent.c
Expand Up @@ -1289,6 +1289,9 @@ change_indent(
// for the following tricks we don't want list mode
save_p_list = curwin->w_p_list;
curwin->w_p_list = FALSE;
#ifdef FEAT_PROP_POPUP
ignore_text_props = TRUE;
#endif
vc = getvcol_nolist(&curwin->w_cursor);
vcol = vc;

Expand Down Expand Up @@ -1440,6 +1443,9 @@ change_indent(
++start_col;
}
}
#ifdef FEAT_PROP_POPUP
ignore_text_props = FALSE;
#endif

// For MODE_VREPLACE state, we also have to fix the replace stack. In this
// case it is always possible because we backspace over the whole line and
Expand Down
2 changes: 1 addition & 1 deletion src/proto/textprop.pro
Expand Up @@ -22,6 +22,6 @@ void f_prop_type_list(typval_T *argvars, typval_T *rettv);
void clear_global_prop_types(void);
void clear_buf_prop_types(buf_T *buf);
int adjust_prop_columns(linenr_T lnum, colnr_T col, int bytes_added, int flags);
void adjust_props_for_split(linenr_T lnum_props, linenr_T lnum_top, int kept, int deleted);
void adjust_props_for_split(linenr_T lnum_props, linenr_T lnum_top, int kept, int deleted, int at_eol);
void prepend_joined_props(char_u *new_props, int propcount, int *props_remaining, linenr_T lnum, int last_line, long col, int removed);
/* vim: set ft=c : */
3 changes: 3 additions & 0 deletions src/scriptfile.c
Expand Up @@ -1639,6 +1639,9 @@ do_source_ext(
}
}
# endif
#else
// Keep the sourcing name/lnum, for recursive calls.
estack_push(ETYPE_SCRIPT, fname_exp, 0);
#endif

cookie.conv.vc_type = CONV_NONE; // no conversion
Expand Down
8 changes: 8 additions & 0 deletions src/testdir/dumps/Test_prop_below_split_line_1.dump
@@ -0,0 +1,8 @@
|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| @63
|t|w|o| |t|w|o| |t|w|o| @63
@3|└+2&&|─| |V|i|r|t|u|a|l| |t|e|x|t| |b|e|l|o|w| |t|h|e| |2|n|d| |l|i|n|e| +0&&@37
|x@1> @72
|t|h|r|e@1| |t|h|r|e@1| |t|h|r|e@1| @57
|~+0#4040ff13&| @73
|~| @73
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|3| @10|A|l@1|
4 changes: 2 additions & 2 deletions src/testdir/test_cmdline.vim
Expand Up @@ -2149,7 +2149,7 @@ func Test_wildmenu_pum()
call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})

" Directory name completion
call mkdir('Xnamedir/XdirA/XdirB', 'p')
call mkdir('Xnamedir/XdirA/XdirB', 'pR')
call writefile([], 'Xnamedir/XfileA')
call writefile([], 'Xnamedir/XdirA/XfileB')
call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
Expand Down Expand Up @@ -2229,7 +2229,7 @@ func Test_wildmenu_pum()
call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})

" Tests a directory name contained full-width characters.
call mkdir('Xnamedir/あいう', 'pR')
call mkdir('Xnamedir/あいう', 'p')
call writefile([], 'Xnamedir/あいう/abc')
call writefile([], 'Xnamedir/あいう/xyz')
call writefile([], 'Xnamedir/あいう/123')
Expand Down
42 changes: 40 additions & 2 deletions src/testdir/test_textprop.vim
Expand Up @@ -2892,6 +2892,45 @@ func Test_props_with_text_above()
call StopVimInTerminal(buf)
endfunc

func Test_prop_above_with_indent()
new
call setline(1, ['first line', ' second line', ' line below'])
setlocal cindent
call prop_type_add('indented', #{highlight: 'Search'})
call prop_add(3, 0, #{type: 'indented', text: 'here', text_align: 'above', text_padding_left: 4})
call assert_equal(' line below', getline(3))

exe "normal 3G2|a\<CR>"
call assert_equal(' ', getline(3))
call assert_equal(' line below', getline(4))

bwipe!
call prop_type_delete('indented')
endfunc

func Test_prop_below_split_line()
CheckRunVimInTerminal

let lines =<< trim END
vim9script
setline(1, ['one one one', 'two two two', 'three three three'])
prop_type_add('test', {highlight: 'ModeMsg'})
prop_add(2, 0, {
text: '└─ Virtual text below the 2nd line',
type: 'test',
text_align: 'below',
text_padding_left: 3
})
END
call writefile(lines, 'XscriptPropBelowSpitLine', 'D')
let buf = RunVimInTerminal('-S XscriptPropBelowSpitLine', #{rows: 8})
call term_sendkeys(buf, "2GA\<CR>xx")
call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {})

call term_sendkeys(buf, "\<Esc>")
call StopVimInTerminal(buf)
endfunc

func Test_props_with_text_override()
CheckRunVimInTerminal

Expand All @@ -2904,7 +2943,7 @@ func Test_props_with_text_override()
hi CursorLine cterm=underline ctermbg=lightgrey
set cursorline
END
call writefile(lines, 'XscriptPropsOverride')
call writefile(lines, 'XscriptPropsOverride', 'D')
let buf = RunVimInTerminal('-S XscriptPropsOverride', #{rows: 6, cols: 60})
call VerifyScreenDump(buf, 'Test_prop_with_text_override_1', {})

Expand All @@ -2913,7 +2952,6 @@ func Test_props_with_text_override()
call VerifyScreenDump(buf, 'Test_prop_with_text_override_2', {})

call StopVimInTerminal(buf)
call delete('XscriptPropsOverride')
endfunc

func Test_props_with_text_CursorMoved()
Expand Down
8 changes: 6 additions & 2 deletions src/testdir/test_window_cmd.vim
Expand Up @@ -1734,9 +1734,13 @@ func Test_splitscroll_with_splits()
above copen | wincmd j
call assert_equal(win_screenpos(0)[0] - tabline, line("w0"))

" No scroll when opening cmdwin
only | norm ggLq:
" No scroll when opening cmdwin, and no cursor move when closing
" cmdwin.
only | norm ggL
let curpos = getcurpos()
norm q:
call assert_equal(1, line("w0"))
call assert_equal(curpos, getcurpos())

" Scroll when cursor becomes invalid in insert mode
norm Lic
Expand Down
27 changes: 18 additions & 9 deletions src/textprop.c
Expand Up @@ -2232,13 +2232,15 @@ adjust_prop_columns(
* "lnum_top" is the top line.
* "kept" is the number of bytes kept in the first line, while
* "deleted" is the number of bytes deleted.
* "at_eol" is true if the split is after the end of the line.
*/
void
adjust_props_for_split(
linenr_T lnum_props,
linenr_T lnum_top,
int kept,
int deleted)
linenr_T lnum_props,
linenr_T lnum_top,
int kept,
int deleted,
int at_eol)
{
char_u *props;
int count;
Expand Down Expand Up @@ -2276,9 +2278,16 @@ adjust_props_for_split(
// a text prop "above" behaves like it is on the first text column
prop_col = (prop.tp_flags & TP_FLAG_ALIGN_ABOVE) ? 1 : prop.tp_col;

cont_prev = prop_col != MAXCOL && prop_col + !start_incl <= kept;
cont_next = prop_col != MAXCOL
&& skipped <= prop_col + prop.tp_len - !end_incl;
if (prop_col == MAXCOL)
{
cont_prev = at_eol;
cont_next = !at_eol;
}
else
{
cont_prev = prop_col + !start_incl <= kept;
cont_next = skipped <= prop_col + prop.tp_len - !end_incl;
}
// when a prop has text it is never copied
if (prop.tp_id < 0 && cont_next)
cont_prev = FALSE;
Expand All @@ -2289,15 +2298,15 @@ adjust_props_for_split(

*p = prop;
++prevprop.ga_len;
if (p->tp_col + p->tp_len >= kept)
if (p->tp_col != MAXCOL && p->tp_col + p->tp_len >= kept)
p->tp_len = kept - p->tp_col;
if (cont_next)
p->tp_flags |= TP_FLAG_CONT_NEXT;
}

// Only add the property to the next line if the length is bigger than
// zero.
if ((cont_next || prop_col == MAXCOL) && ga_grow(&nextprop, 1) == OK)
if (cont_next && ga_grow(&nextprop, 1) == OK)
{
textprop_T *p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len;

Expand Down
16 changes: 16 additions & 0 deletions src/version.c
Expand Up @@ -718,6 +718,22 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
469,
/**/
468,
/**/
467,
/**/
466,
/**/
465,
/**/
464,
/**/
463,
/**/
462,
/**/
461,
/**/
Expand Down
4 changes: 4 additions & 0 deletions src/window.c
Expand Up @@ -6416,6 +6416,10 @@ win_fix_cursor(int normal)

if (wp->w_buffer->b_ml.ml_line_count < wp->w_height)
return;
#ifdef FEAT_CMDWIN
if (skip_win_fix_cursor)
return;
#endif

so = MIN(wp->w_height / 2, so);
// Check if cursor position is above topline or below botline.
Expand Down

0 comments on commit d404ddd

Please sign in to comment.