# HG changeset patch # User Bram Moolenaar # Date 1601407803 -7200 # Node ID 5e287462487eb9b5e624e8f1f3b2cb0a11a6ee67 # Parent 0d08767cdb3ef26ade50c53f30df49141b0f8b35 patch 8.2.1772: cannot use CTRL-W to move out of a terminal window Commit: https://github.com/vim/vim/commit/f43e7ac4eee22dbb26fc069ec9a3d1598ec8dfe9 Author: Bram Moolenaar Date: Tue Sep 29 21:23:25 2020 +0200 patch 8.2.1772: cannot use CTRL-W to move out of a terminal window Problem: Cannot use CTRL-W to move out of a terminal window. Solution: Use special_to_buf() instead of mb_char2bytes(). (closes https://github.com/vim/vim/issues/7045) diff --git a/src/terminal.c b/src/terminal.c --- a/src/terminal.c +++ b/src/terminal.c @@ -2640,12 +2640,13 @@ if (raw_c > 0) } else if (termwinkey == 0 || c != termwinkey) { - char_u buf[MB_MAXBYTES + 2]; + // space for CTRL-W, modifier, multi-byte char and NUL + char_u buf[1 + 3 + MB_MAXBYTES + 1]; // Put the command into the typeahead buffer, when using the // stuff buffer KeyStuffed is set and 'langmap' won't be used. buf[0] = Ctrl_W; - buf[(*mb_char2bytes)(c, buf + 1) + 1] = NUL; + buf[special_to_buf(c, mod_mask, FALSE, buf + 1) + 1] = NUL; ins_typebuf(buf, REMAP_NONE, 0, TRUE, FALSE); ret = OK; goto theend; diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim --- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -1379,6 +1379,23 @@ func Test_terminal_statusline() set statusline= endfunc +func Test_terminal_window_focus() + let winid1 = win_getid() + terminal + let winid2 = win_getid() + call feedkeys("\j", 'xt') + call assert_equal(winid1, win_getid()) + call feedkeys("\k", 'xt') + call assert_equal(winid2, win_getid()) + " can use a cursor key here + call feedkeys("\\", 'xt') + call assert_equal(winid1, win_getid()) + call feedkeys("\\", 'xt') + call assert_equal(winid2, win_getid()) + + bwipe! +endfunc + func Api_drop_common(options) call assert_equal(1, winnr('$')) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1772, +/**/ 1771, /**/ 1770,