Merge pull request #24505 from zeertzjq/backport

Backport to release-0.9
This commit is contained in:
zeertzjq
2023-07-28 16:28:04 +08:00
committed by GitHub
9 changed files with 125 additions and 100 deletions

View File

@@ -2328,6 +2328,8 @@ static void cmdpreview_restore_undo(const CpUndoInfo *cp_undoinfo, buf_T *buf)
static void cmdpreview_prepare(CpInfo *cpinfo) static void cmdpreview_prepare(CpInfo *cpinfo)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
PMap(ptr_t) saved_bufs = MAP_INIT;
kv_init(cpinfo->buf_info); kv_init(cpinfo->buf_info);
kv_init(cpinfo->win_info); kv_init(cpinfo->win_info);
@@ -2339,19 +2341,19 @@ static void cmdpreview_prepare(CpInfo *cpinfo)
continue; continue;
} }
CpBufInfo cp_bufinfo; if (!pmap_has(ptr_t)(&saved_bufs, buf)) {
cp_bufinfo.buf = buf; CpBufInfo cp_bufinfo;
cp_bufinfo.buf = buf;
cp_bufinfo.save_b_p_ul = buf->b_p_ul;
cp_bufinfo.save_b_changed = buf->b_changed;
cp_bufinfo.save_changedtick = buf_get_changedtick(buf);
cmdpreview_save_undo(&cp_bufinfo.undo_info, buf);
kv_push(cpinfo->buf_info, cp_bufinfo);
pmap_put(ptr_t)(&saved_bufs, buf, NULL);
cp_bufinfo.save_b_p_ul = buf->b_p_ul; u_clearall(buf);
cp_bufinfo.save_b_changed = buf->b_changed; buf->b_p_ul = LONG_MAX; // Make sure we can undo all changes
cp_bufinfo.save_changedtick = buf_get_changedtick(buf); }
cmdpreview_save_undo(&cp_bufinfo.undo_info, buf);
u_clearall(buf);
kv_push(cpinfo->buf_info, cp_bufinfo);
buf->b_p_ul = LONG_MAX; // Make sure we can undo all changes
CpWinInfo cp_wininfo; CpWinInfo cp_wininfo;
cp_wininfo.win = win; cp_wininfo.win = win;
@@ -2370,6 +2372,8 @@ static void cmdpreview_prepare(CpInfo *cpinfo)
win->w_p_cuc = false; // Disable 'cursorcolumn' so it doesn't mess up the highlights win->w_p_cuc = false; // Disable 'cursorcolumn' so it doesn't mess up the highlights
} }
pmap_destroy(ptr_t)(&saved_bufs);
cpinfo->save_hls = p_hls; cpinfo->save_hls = p_hls;
cpinfo->save_cmdmod = cmdmod; cpinfo->save_cmdmod = cmdmod;
win_size_save(&cpinfo->save_view); win_size_save(&cpinfo->save_view);
@@ -2426,6 +2430,7 @@ static void cmdpreview_restore_state(CpInfo *cpinfo)
// Clear preview highlights. // Clear preview highlights.
extmark_clear(buf, (uint32_t)cmdpreview_ns, 0, 0, MAXLNUM, MAXCOL); extmark_clear(buf, (uint32_t)cmdpreview_ns, 0, 0, MAXLNUM, MAXCOL);
} }
for (size_t i = 0; i < cpinfo->win_info.size; i++) { for (size_t i = 0; i < cpinfo->win_info.size; i++) {
CpWinInfo cp_wininfo = cpinfo->win_info.items[i]; CpWinInfo cp_wininfo = cpinfo->win_info.items[i];
win_T *win = cp_wininfo.win; win_T *win = cp_wininfo.win;

View File

@@ -1,5 +1,6 @@
local luv = require('luv') local luv = require('luv')
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
local clear, command, nvim, testprg = local clear, command, nvim, testprg =
helpers.clear, helpers.command, helpers.nvim, helpers.testprg helpers.clear, helpers.command, helpers.nvim, helpers.testprg
@@ -8,6 +9,7 @@ local eval, eq, neq, retry =
local matches = helpers.matches local matches = helpers.matches
local ok = helpers.ok local ok = helpers.ok
local feed = helpers.feed local feed = helpers.feed
local meths = helpers.meths
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local skip = helpers.skip local skip = helpers.skip
@@ -162,3 +164,21 @@ it('autocmd TermEnter, TermLeave', function()
}, },
eval('g:evs')) eval('g:evs'))
end) end)
describe('autocmd TextChangedT', function()
clear()
local screen = thelpers.screen_setup()
it('works', function()
command('autocmd TextChangedT * ++once let g:called = 1')
thelpers.feed_data('a')
retry(nil, nil, function() eq(1, meths.get_var('called')) end)
end)
it('cannot delete terminal buffer', function()
command([[autocmd TextChangedT * call nvim_input('<CR>') | bwipe!]])
thelpers.feed_data('a')
screen:expect({any = 'E937: '})
matches('^E937: Attempt to delete a buffer that is in use: term://', meths.get_vvar('errmsg'))
end)
end)

View File

@@ -24,8 +24,7 @@ describe(':terminal buffer', function()
before_each(function() before_each(function()
clear() clear()
feed_command('set modifiable swapfile undolevels=20') command('set modifiable swapfile undolevels=20')
poke_eventloop()
screen = thelpers.screen_setup() screen = thelpers.screen_setup()
end) end)
@@ -198,8 +197,7 @@ describe(':terminal buffer', function()
it('handles loss of focus gracefully', function() it('handles loss of focus gracefully', function()
-- Change the statusline to avoid printing the file name, which varies. -- Change the statusline to avoid printing the file name, which varies.
nvim('set_option', 'statusline', '==========') nvim('set_option_value', 'statusline', '==========', {})
feed_command('set laststatus=0')
-- Save the buffer number of the terminal for later testing. -- Save the buffer number of the terminal for later testing.
local tbuf = eval('bufnr("%")') local tbuf = eval('bufnr("%")')
@@ -232,8 +230,6 @@ describe(':terminal buffer', function()
neq(tbuf, eval('bufnr("%")')) neq(tbuf, eval('bufnr("%")'))
feed_command('quit!') -- Should exit the new window, not the terminal. feed_command('quit!') -- Should exit the new window, not the terminal.
eq(tbuf, eval('bufnr("%")')) eq(tbuf, eval('bufnr("%")'))
feed_command('set laststatus=1') -- Restore laststatus to the default.
end) end)
it('term_close() use-after-free #4393', function() it('term_close() use-after-free #4393', function()
@@ -413,14 +409,6 @@ describe('on_lines does not emit out-of-bounds line indexes when', function()
feed_command('bdelete!') feed_command('bdelete!')
eq('', exec_lua([[return _G.cb_error]])) eq('', exec_lua([[return _G.cb_error]]))
end) end)
it('runs TextChangedT event', function()
meths.set_var('called', 0)
command('autocmd TextChangedT * ++once let g:called = 1')
feed_command('terminal')
feed('iaa')
eq(1, meths.get_var('called'))
end)
end) end)
it('terminal truncates number of composing characters to 5', function() it('terminal truncates number of composing characters to 5', function()
@@ -440,7 +428,7 @@ describe('terminal input', function()
_G.input_data = _G.input_data .. data _G.input_data = _G.input_data .. data
end }) end })
]]) ]])
command('startinsert') feed('i')
poke_eventloop() poke_eventloop()
end) end)

View File

@@ -6,7 +6,7 @@ local testprg, command = helpers.testprg, helpers.command
local nvim_prog = helpers.nvim_prog local nvim_prog = helpers.nvim_prog
local eq, eval = helpers.eq, helpers.eval local eq, eval = helpers.eq, helpers.eval
local matches = helpers.matches local matches = helpers.matches
local feed_command = helpers.feed_command local poke_eventloop = helpers.poke_eventloop
local hide_cursor = thelpers.hide_cursor local hide_cursor = thelpers.hide_cursor
local show_cursor = thelpers.show_cursor local show_cursor = thelpers.show_cursor
local is_os = helpers.is_os local is_os = helpers.is_os
@@ -153,7 +153,8 @@ describe('cursor with customized highlighting', function()
}) })
screen:attach({rgb=false}) screen:attach({rgb=false})
command('call termopen(["'..testprg('tty-test')..'"])') command('call termopen(["'..testprg('tty-test')..'"])')
feed_command('startinsert') feed('i')
poke_eventloop()
end) end)
it('overrides the default highlighting', function() it('overrides the default highlighting', function()
@@ -187,13 +188,16 @@ describe('buffer cursor position is correct in terminal without number column',
..[[", "-u", "NONE", "-i", "NONE", "-E", "--cmd", "let @r = ']]..str..[['", ]] ..[[", "-u", "NONE", "-i", "NONE", "-E", "--cmd", "let @r = ']]..str..[['", ]]
-- <Left> and <Right> don't always work -- <Left> and <Right> don't always work
..[["--cmd", "cnoremap <C-X> <Left>", "--cmd", "cnoremap <C-O> <Right>"]]..']', 70) ..[["--cmd", "cnoremap <C-X> <Left>", "--cmd", "cnoremap <C-O> <Right>"]]..']', 70)
-- Also check for real cursor position, as it is used for stuff like input methods
screen._handle_busy_start = function() end
screen._handle_busy_stop = function() end
screen:expect([[ screen:expect([[
| |
| |
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:{1: } | :{1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
end end
@@ -213,7 +217,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:aaaaaaaa{1: } | :aaaaaaaa{1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 9}, eval('nvim_win_get_cursor(0)')) eq({6, 9}, eval('nvim_win_get_cursor(0)'))
@@ -238,7 +242,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:aaaaaa{1:a}a | :aaaaaa{1:^a}a |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 7}, eval('nvim_win_get_cursor(0)')) eq({6, 7}, eval('nvim_win_get_cursor(0)'))
@@ -263,7 +267,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:a{1:a}aaaaaa | :a{1:^a}aaaaaa |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 2}, eval('nvim_win_get_cursor(0)')) eq({6, 2}, eval('nvim_win_get_cursor(0)'))
@@ -294,7 +298,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:µµµµµµµµ{1: } | :µµµµµµµµ{1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 17}, eval('nvim_win_get_cursor(0)')) eq({6, 17}, eval('nvim_win_get_cursor(0)'))
@@ -319,7 +323,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:µµµµµµ{1:µ}µ | :µµµµµµ{1:^µ}µ |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 13}, eval('nvim_win_get_cursor(0)')) eq({6, 13}, eval('nvim_win_get_cursor(0)'))
@@ -344,7 +348,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:µ{1:µ}µµµµµµ | :µ{1:^µ}µµµµµµ |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 3}, eval('nvim_win_get_cursor(0)')) eq({6, 3}, eval('nvim_win_get_cursor(0)'))
@@ -377,7 +381,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1: } | :µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 33}, eval('nvim_win_get_cursor(0)')) eq({6, 33}, eval('nvim_win_get_cursor(0)'))
@@ -402,7 +406,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:µ̳µ̳µ̳µ̳µ̳µ̳{1:µ̳}µ̳ | :µ̳µ̳µ̳µ̳µ̳µ̳{1:^µ̳}µ̳ |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 25}, eval('nvim_win_get_cursor(0)')) eq({6, 25}, eval('nvim_win_get_cursor(0)'))
@@ -427,7 +431,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:µ̳{1:µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ | :µ̳{1:^µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 5}, eval('nvim_win_get_cursor(0)')) eq({6, 5}, eval('nvim_win_get_cursor(0)'))
@@ -446,7 +450,7 @@ describe('buffer cursor position is correct in terminal without number column',
end) end)
describe('in a line with double-cell multibyte characters and no trailing spaces,', function() describe('in a line with double-cell multibyte characters and no trailing spaces,', function()
skip(is_os('win'), "Encoding problem?") if skip(is_os('win'), "Encoding problem?") then return end
before_each(function() before_each(function()
setup_ex_register('哦哦哦哦哦哦哦哦') setup_ex_register('哦哦哦哦哦哦哦哦')
@@ -460,7 +464,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:哦哦哦哦哦哦哦哦{1: } | :哦哦哦哦哦哦哦哦{1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 25}, eval('nvim_win_get_cursor(0)')) eq({6, 25}, eval('nvim_win_get_cursor(0)'))
@@ -485,7 +489,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:哦哦哦哦哦哦{1:哦}哦 | :哦哦哦哦哦哦{1:^哦}哦 |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 19}, eval('nvim_win_get_cursor(0)')) eq({6, 19}, eval('nvim_win_get_cursor(0)'))
@@ -510,7 +514,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:哦{1:哦}哦哦哦哦哦哦 | :哦{1:^哦}哦哦哦哦哦哦 |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 4}, eval('nvim_win_get_cursor(0)')) eq({6, 4}, eval('nvim_win_get_cursor(0)'))
@@ -537,7 +541,7 @@ describe('buffer cursor position is correct in terminal without number column',
| |
| |
Entering Ex mode. Type "visual" to go to Normal mode. | Entering Ex mode. Type "visual" to go to Normal mode. |
:aaaaaaaa {1: } | :aaaaaaaa {1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
matches('^:aaaaaaaa [ ]*$', eval('nvim_get_current_line()')) matches('^:aaaaaaaa [ ]*$', eval('nvim_get_current_line()'))
@@ -564,13 +568,16 @@ describe('buffer cursor position is correct in terminal with number column', fun
..[[", "-u", "NONE", "-i", "NONE", "-E", "--cmd", "let @r = ']]..str..[['", ]] ..[[", "-u", "NONE", "-i", "NONE", "-E", "--cmd", "let @r = ']]..str..[['", ]]
-- <Left> and <Right> don't always work -- <Left> and <Right> don't always work
..[["--cmd", "cnoremap <C-X> <Left>", "--cmd", "cnoremap <C-O> <Right>"]]..']', 70) ..[["--cmd", "cnoremap <C-X> <Left>", "--cmd", "cnoremap <C-O> <Right>"]]..']', 70)
-- Also check for real cursor position, as it is used for stuff like input methods
screen._handle_busy_start = function() end
screen._handle_busy_stop = function() end
screen:expect([[ screen:expect([[
{7: 1 } | {7: 1 } |
{7: 2 } | {7: 2 } |
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:{1: } | {7: 6 }:{1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
end end
@@ -593,7 +600,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:aaaaaaaa{1: } | {7: 6 }:aaaaaaaa{1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 9}, eval('nvim_win_get_cursor(0)')) eq({6, 9}, eval('nvim_win_get_cursor(0)'))
@@ -618,7 +625,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:aaaaaa{1:a}a | {7: 6 }:aaaaaa{1:^a}a |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 7}, eval('nvim_win_get_cursor(0)')) eq({6, 7}, eval('nvim_win_get_cursor(0)'))
@@ -643,7 +650,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:a{1:a}aaaaaa | {7: 6 }:a{1:^a}aaaaaa |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 2}, eval('nvim_win_get_cursor(0)')) eq({6, 2}, eval('nvim_win_get_cursor(0)'))
@@ -674,7 +681,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:µµµµµµµµ{1: } | {7: 6 }:µµµµµµµµ{1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 17}, eval('nvim_win_get_cursor(0)')) eq({6, 17}, eval('nvim_win_get_cursor(0)'))
@@ -699,7 +706,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:µµµµµµ{1:µ}µ | {7: 6 }:µµµµµµ{1:^µ}µ |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 13}, eval('nvim_win_get_cursor(0)')) eq({6, 13}, eval('nvim_win_get_cursor(0)'))
@@ -724,7 +731,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:µ{1:µ}µµµµµµ | {7: 6 }:µ{1:^µ}µµµµµµ |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 3}, eval('nvim_win_get_cursor(0)')) eq({6, 3}, eval('nvim_win_get_cursor(0)'))
@@ -757,7 +764,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1: } | {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳µ̳µ̳{1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 33}, eval('nvim_win_get_cursor(0)')) eq({6, 33}, eval('nvim_win_get_cursor(0)'))
@@ -782,7 +789,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳{1:µ̳}µ̳ | {7: 6 }:µ̳µ̳µ̳µ̳µ̳µ̳{1:^µ̳}µ̳ |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 25}, eval('nvim_win_get_cursor(0)')) eq({6, 25}, eval('nvim_win_get_cursor(0)'))
@@ -807,7 +814,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:µ̳{1:µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ | {7: 6 }:µ̳{1:^µ̳}µ̳µ̳µ̳µ̳µ̳µ̳ |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 5}, eval('nvim_win_get_cursor(0)')) eq({6, 5}, eval('nvim_win_get_cursor(0)'))
@@ -826,7 +833,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
end) end)
describe('in a line with double-cell multibyte characters and no trailing spaces,', function() describe('in a line with double-cell multibyte characters and no trailing spaces,', function()
skip(is_os('win'), "Encoding problem?") if skip(is_os('win'), "Encoding problem?") then return end
before_each(function() before_each(function()
setup_ex_register('哦哦哦哦哦哦哦哦') setup_ex_register('哦哦哦哦哦哦哦哦')
@@ -840,7 +847,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:哦哦哦哦哦哦哦哦{1: } | {7: 6 }:哦哦哦哦哦哦哦哦{1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 25}, eval('nvim_win_get_cursor(0)')) eq({6, 25}, eval('nvim_win_get_cursor(0)'))
@@ -865,7 +872,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:哦哦哦哦哦哦{1:哦}哦 | {7: 6 }:哦哦哦哦哦哦{1:^哦}哦 |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 19}, eval('nvim_win_get_cursor(0)')) eq({6, 19}, eval('nvim_win_get_cursor(0)'))
@@ -890,7 +897,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:哦{1:哦}哦哦哦哦哦哦 | {7: 6 }:哦{1:^哦}哦哦哦哦哦哦 |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
eq({6, 4}, eval('nvim_win_get_cursor(0)')) eq({6, 4}, eval('nvim_win_get_cursor(0)'))
@@ -917,7 +924,7 @@ describe('buffer cursor position is correct in terminal with number column', fun
{7: 3 } | {7: 3 } |
{7: 4 } | {7: 4 } |
{7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. | {7: 5 }Entering Ex mode. Type "visual" to go to Normal mode. |
{7: 6 }:aaaaaaaa {1: } | {7: 6 }:aaaaaaaa {1:^ } |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
matches('^:aaaaaaaa [ ]*$', eval('nvim_get_current_line()')) matches('^:aaaaaaaa [ ]*$', eval('nvim_get_current_line()'))

View File

@@ -99,7 +99,7 @@ describe(':terminal', function()
end) end)
it('nvim_get_mode() in :terminal', function() it('nvim_get_mode() in :terminal', function()
command(':terminal') command('terminal')
eq({ blocking=false, mode='nt' }, nvim('get_mode')) eq({ blocking=false, mode='nt' }, nvim('get_mode'))
feed('i') feed('i')
eq({ blocking=false, mode='t' }, nvim('get_mode')) eq({ blocking=false, mode='t' }, nvim('get_mode'))
@@ -108,17 +108,19 @@ describe(':terminal', function()
end) end)
it(':stopinsert RPC request exits terminal-mode #7807', function() it(':stopinsert RPC request exits terminal-mode #7807', function()
command(':terminal') command('terminal')
feed('i[tui] insert-mode') feed('i[tui] insert-mode')
eq({ blocking=false, mode='t' }, nvim('get_mode')) eq({ blocking=false, mode='t' }, nvim('get_mode'))
command('stopinsert') command('stopinsert')
feed('<Ignore>') -- Add input to separate two RPC requests
eq({ blocking=false, mode='nt' }, nvim('get_mode')) eq({ blocking=false, mode='nt' }, nvim('get_mode'))
end) end)
it(':stopinsert in normal mode doesn\'t break insert mode #9889', function() it(':stopinsert in normal mode doesn\'t break insert mode #9889', function()
command(':terminal') command('terminal')
eq({ blocking=false, mode='nt' }, nvim('get_mode')) eq({ blocking=false, mode='nt' }, nvim('get_mode'))
command(':stopinsert') command('stopinsert')
feed('<Ignore>') -- Add input to separate two RPC requests
eq({ blocking=false, mode='nt' }, nvim('get_mode')) eq({ blocking=false, mode='nt' }, nvim('get_mode'))
feed('a') feed('a')
eq({ blocking=false, mode='t' }, nvim('get_mode')) eq({ blocking=false, mode='t' }, nvim('get_mode'))

View File

@@ -5,7 +5,7 @@ local helpers = require('test.functional.helpers')(nil)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local testprg = helpers.testprg local testprg = helpers.testprg
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local feed_command, nvim = helpers.feed_command, helpers.nvim local nvim = helpers.nvim
local function feed_data(data) local function feed_data(data)
if type(data) == 'table' then if type(data) == 'table' then
@@ -82,15 +82,16 @@ local function screen_setup(extra_rows, command, cols, opts)
screen:attach(opts or {rgb=false}) screen:attach(opts or {rgb=false})
feed_command('enew | call termopen('..command..')') nvim('command', 'enew | call termopen('..command..')')
nvim('input', '<CR>') nvim('input', '<CR>')
local vim_errmsg = nvim('eval', 'v:errmsg') local vim_errmsg = nvim('eval', 'v:errmsg')
if vim_errmsg and "" ~= vim_errmsg then if vim_errmsg and "" ~= vim_errmsg then
error(vim_errmsg) error(vim_errmsg)
end end
feed_command('setlocal scrollback=10') nvim('command', 'setlocal scrollback=10')
feed_command('startinsert') nvim('command', 'startinsert')
nvim('input', '<Ignore>') -- Add input to separate two RPC requests
-- tty-test puts the terminal into raw mode and echoes input. Tests work by -- tty-test puts the terminal into raw mode and echoes input. Tests work by
-- feeding termcodes to control the display and asserting by screen:expect. -- feeding termcodes to control the display and asserting by screen:expect.

View File

@@ -2,7 +2,7 @@ local Screen = require('test.functional.ui.screen')
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf
local feed, testprg, feed_command = helpers.feed, helpers.testprg, helpers.feed_command local feed, testprg = helpers.feed, helpers.testprg
local eval = helpers.eval local eval = helpers.eval
local command = helpers.command local command = helpers.command
local matches = helpers.matches local matches = helpers.matches
@@ -349,8 +349,7 @@ describe(':terminal prints more lines than the screen height and exits', functio
clear() clear()
local screen = Screen.new(30, 7) local screen = Screen.new(30, 7)
screen:attach({rgb=false}) screen:attach({rgb=false})
feed_command(("call termopen(['%s', '10']) | startinsert"):format(testprg('tty-test'))) command(("call termopen(['%s', '10']) | startinsert"):format(testprg('tty-test')))
poke_eventloop()
screen:expect([[ screen:expect([[
line6 | line6 |
line7 | line7 |

View File

@@ -8,7 +8,6 @@ local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers') local thelpers = require('test.functional.terminal.helpers')
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local eq = helpers.eq local eq = helpers.eq
local feed_command = helpers.feed_command
local feed_data = thelpers.feed_data local feed_data = thelpers.feed_data
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
@@ -109,14 +108,14 @@ describe('TUI', function()
end) end)
it('accepts resize while pager is active', function() it('accepts resize while pager is active', function()
child_session:request("nvim_exec", [[ child_session:request('nvim_exec2', [[
set more set more
func! ManyErr() func! ManyErr()
for i in range(20) for i in range(20)
echoerr "FAIL ".i echoerr "FAIL ".i
endfor endfor
endfunc endfunc
]], false) ]], {})
feed_data(':call ManyErr()\r') feed_data(':call ManyErr()\r')
screen:expect{grid=[[ screen:expect{grid=[[
{8:Error detected while processing function ManyErr:} | {8:Error detected while processing function ManyErr:} |
@@ -240,7 +239,7 @@ describe('TUI', function()
it('interprets leading <Esc> byte as ALT modifier in normal-mode', function() it('interprets leading <Esc> byte as ALT modifier in normal-mode', function()
local keys = 'dfghjkl' local keys = 'dfghjkl'
for c in keys:gmatch('.') do for c in keys:gmatch('.') do
feed_command('nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>') feed_data(':nnoremap <a-'..c..'> ialt-'..c..'<cr><esc>\r')
feed_data('\027'..c) feed_data('\027'..c)
end end
screen:expect([[ screen:expect([[
@@ -280,9 +279,11 @@ describe('TUI', function()
end) end)
it('interprets <Esc>[27u as <Esc>', function() it('interprets <Esc>[27u as <Esc>', function()
feed_command('nnoremap <M-;> <Nop>') child_session:request('nvim_exec2', [[
feed_command('nnoremap <Esc> AESC<Esc>') nnoremap <M-;> <Nop>
feed_command('nnoremap ; Asemicolon<Esc>') nnoremap <Esc> AESC<Esc>
nnoremap ; Asemicolon<Esc>
]], {})
feed_data('\027[27u;') feed_data('\027[27u;')
screen:expect([[ screen:expect([[
ESCsemicolo{1:n} | ESCsemicolo{1:n} |
@@ -330,11 +331,11 @@ describe('TUI', function()
end) end)
it('accepts mouse wheel events #19992', function() it('accepts mouse wheel events #19992', function()
child_session:request('nvim_exec', [[ child_session:request('nvim_exec2', [[
set number nostartofline nowrap mousescroll=hor:1,ver:1 set number nostartofline nowrap mousescroll=hor:1,ver:1
call setline(1, repeat([join(range(10), '----')], 10)) call setline(1, repeat([join(range(10), '----')], 10))
vsplit vsplit
]], false) ]], {})
screen:expect([[ screen:expect([[
{11: 1 }{1:0}----1----2----3----4│{11: 1 }0----1----2----3----| {11: 1 }{1:0}----1----2----3----4│{11: 1 }0----1----2----3----|
{11: 2 }0----1----2----3----4│{11: 2 }0----1----2----3----| {11: 2 }0----1----2----3----4│{11: 2 }0----1----2----3----|
@@ -660,11 +661,11 @@ describe('TUI', function()
| |
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
child_session:request('nvim_exec', [[ child_session:request('nvim_exec2', [[
tab split tab split
tabnew tabnew
highlight Tabline ctermbg=NONE ctermfg=NONE cterm=underline highlight Tabline ctermbg=NONE ctermfg=NONE cterm=underline
]], false) ]], {})
screen:expect([[ screen:expect([[
{12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}| {12: + [No Name] + [No Name] }{3: [No Name] }{1: }{12:X}|
{1: } | {1: } |
@@ -719,7 +720,7 @@ describe('TUI', function()
end) end)
it('mouse events work with right-click menu', function() it('mouse events work with right-click menu', function()
child_session:request('nvim_exec', [[ child_session:request('nvim_exec2', [[
call setline(1, 'popup menu test') call setline(1, 'popup menu test')
set mouse=a mousemodel=popup set mouse=a mousemodel=popup
@@ -729,7 +730,7 @@ describe('TUI', function()
menu PopUp.baz :let g:menustr = 'baz'<CR> menu PopUp.baz :let g:menustr = 'baz'<CR>
highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse highlight Pmenu ctermbg=NONE ctermfg=NONE cterm=underline,reverse
highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold highlight PmenuSel ctermbg=NONE ctermfg=NONE cterm=underline,reverse,bold
]], false) ]], {})
meths.input_mouse('right', 'press', '', 0, 0, 4) meths.input_mouse('right', 'press', '', 0, 0, 4)
screen:expect([[ screen:expect([[
{1:p}opup menu test | {1:p}opup menu test |
@@ -1583,11 +1584,11 @@ describe('TUI', function()
it('no stack-use-after-scope with cursor color #22432', function() it('no stack-use-after-scope with cursor color #22432', function()
screen:set_option('rgb', true) screen:set_option('rgb', true)
command('set termguicolors') command('set termguicolors')
child_session:request('nvim_exec', [[ child_session:request('nvim_exec2', [[
set tgc set tgc
hi Cursor guifg=Red guibg=Green hi Cursor guifg=Red guibg=Green
set guicursor=n:block-Cursor/lCursor set guicursor=n:block-Cursor/lCursor
]], false) ]], {})
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {reverse = true}, [1] = {reverse = true},
[2] = {bold = true, foreground = Screen.colors.Blue}, [2] = {bold = true, foreground = Screen.colors.Blue},
@@ -1771,10 +1772,10 @@ describe('TUI FocusGained/FocusLost', function()
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]]) ]])
child_session = helpers.connect(child_server) child_session = helpers.connect(child_server)
child_session:request('nvim_exec', [[ child_session:request('nvim_exec2', [[
autocmd FocusGained * echo 'gained' autocmd FocusGained * echo 'gained'
autocmd FocusLost * echo 'lost' autocmd FocusLost * echo 'lost'
]], false) ]], {})
feed_data("\034\016") -- CTRL-\ CTRL-N feed_data("\034\016") -- CTRL-\ CTRL-N
end) end)
@@ -1805,7 +1806,7 @@ describe('TUI FocusGained/FocusLost', function()
end) end)
it('in insert-mode', function() it('in insert-mode', function()
feed_command('set noshowmode') feed_data(':set noshowmode\r')
feed_data('i') feed_data('i')
screen:expect{grid=[[ screen:expect{grid=[[
{1: } | {1: } |
@@ -1870,11 +1871,11 @@ describe('TUI FocusGained/FocusLost', function()
-- Set up autocmds that modify the buffer, instead of just calling :echo. -- Set up autocmds that modify the buffer, instead of just calling :echo.
-- This is how we can test handling of focus gained/lost during cmdline-mode. -- This is how we can test handling of focus gained/lost during cmdline-mode.
-- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419. -- See commit: 5cc87d4dabd02167117be7a978b5c8faaa975419.
child_session:request('nvim_exec', [[ child_session:request('nvim_exec2', [[
autocmd! autocmd!
autocmd FocusLost * call append(line('$'), 'lost') autocmd FocusLost * call append(line('$'), 'lost')
autocmd FocusGained * call append(line('$'), 'gained') autocmd FocusGained * call append(line('$'), 'gained')
]], false) ]], {})
retry(2, 3 * screen.timeout, function() retry(2, 3 * screen.timeout, function()
-- Enter cmdline-mode. -- Enter cmdline-mode.
feed_data(':') feed_data(':')

View File

@@ -2,7 +2,6 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
@@ -175,11 +174,14 @@ describe(":substitute, 'inccommand' preserves", function()
it("'undolevels' (inccommand="..case..")", function() it("'undolevels' (inccommand="..case..")", function()
feed_command("set undolevels=139") feed_command("set undolevels=139")
feed_command("setlocal undolevels=34") feed_command("setlocal undolevels=34")
feed_command("split") -- Show the buffer in multiple windows
feed_command("set inccommand=" .. case) feed_command("set inccommand=" .. case)
insert("as") insert("as")
feed(":%s/as/glork/<enter>") feed(":%s/as/glork/")
eq(meths.get_option('undolevels'), 139) poke_eventloop()
eq(curbufmeths.get_option('undolevels'), 34) feed("<enter>")
eq(meths.get_option_value('undolevels', {scope='global'}), 139)
eq(meths.get_option_value('undolevels', {buf=0}), 34)
end) end)
end end