diff --git a/src/change.c b/src/change.c index c06991e882..99b12a47fd 100644 --- a/src/change.c +++ b/src/change.c @@ -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 @@ -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 diff --git a/src/charset.c b/src/charset.c index a19e55b628..c5edaf41e0 100644 --- a/src/charset.c +++ b/src/charset.c @@ -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; diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 4938c6f485..ebcd441c81 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -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; diff --git a/src/ex_getln.c b/src/ex_getln.c index 2375962151..89c580998b 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -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 @@ -4669,6 +4671,7 @@ open_cmdwin(void) // Restore window sizes. win_size_restore(&winsizes); + skip_win_fix_cursor = FALSE; } ga_clear(&winsizes); diff --git a/src/globals.h b/src/globals.h index f7160a6bc1..8e727739c6 100644 --- a/src/globals.h +++ b/src/globals.h @@ -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 @@ -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 diff --git a/src/indent.c b/src/indent.c index 134336c12d..51585ec9e8 100644 --- a/src/indent.c +++ b/src/indent.c @@ -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; @@ -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 diff --git a/src/proto/textprop.pro b/src/proto/textprop.pro index b3912c16ae..aa06e61f76 100644 --- a/src/proto/textprop.pro +++ b/src/proto/textprop.pro @@ -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 : */ diff --git a/src/scriptfile.c b/src/scriptfile.c index 34683262a5..bdb7922363 100644 --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -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 diff --git a/src/testdir/dumps/Test_prop_below_split_line_1.dump b/src/testdir/dumps/Test_prop_below_split_line_1.dump new file mode 100644 index 0000000000..671fceaf40 --- /dev/null +++ b/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| diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim index 73bdbb4e66..7febc12269 100644 --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -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') @@ -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') diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim index 5167e8e3b3..8a80e5504f 100644 --- a/src/testdir/test_textprop.vim +++ b/src/testdir/test_textprop.vim @@ -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\" + 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\xx") + call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {}) + + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) +endfunc + func Test_props_with_text_override() CheckRunVimInTerminal @@ -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', {}) @@ -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() diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim index c9f9caa347..872e1bac18 100644 --- a/src/testdir/test_window_cmd.vim +++ b/src/testdir/test_window_cmd.vim @@ -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 diff --git a/src/textprop.c b/src/textprop.c index d2536ce776..6e5c1447ff 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -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; @@ -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; @@ -2289,7 +2298,7 @@ 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; @@ -2297,7 +2306,7 @@ adjust_props_for_split( // 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; diff --git a/src/version.c b/src/version.c index 702941c414..8ad2014d4e 100644 --- a/src/version.c +++ b/src/version.c @@ -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, /**/ diff --git a/src/window.c b/src/window.c index 14c26af69f..926ac13a16 100644 --- a/src/window.c +++ b/src/window.c @@ -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.