To: vim_dev@googlegroups.com Subject: Patch 8.2.4002 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4002 Problem: First char typed in Select mode can be wrong. Solution: Escape special bytes in the input buffer. (closes #9469) Files: src/getchar.c, src/testdir/test_utf8.vim *** ../vim-8.2.4001/src/getchar.c 2022-01-04 17:01:40.598663106 +0000 --- src/getchar.c 2022-01-04 17:57:22.981493744 +0000 *************** *** 1121,1127 **** int ins_char_typebuf(int c, int modifier) { ! char_u buf[MB_MAXBYTES + 4]; int len = 0; if (modifier != 0) --- 1121,1127 ---- int ins_char_typebuf(int c, int modifier) { ! char_u buf[MB_MAXBYTES * 3 + 4]; int len = 0; if (modifier != 0) *************** *** 1142,1149 **** } else { ! len += (*mb_char2bytes)(c, buf + len); ! buf[len] = NUL; } (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent); return len; --- 1142,1159 ---- } else { ! char_u *p = buf + len; ! int char_len = (*mb_char2bytes)(c, p); ! #ifdef FEAT_GUI ! int save_gui_in_use = gui.in_use; ! ! gui.in_use = FALSE; ! #endif ! // if the character contains CSI or K_SPECIAL bytes they need escaping ! len += fix_input_buffer(p, char_len); ! #ifdef FEAT_GUI ! gui.in_use = save_gui_in_use; ! #endif } (void)ins_typebuf(buf, KeyNoremap, 0, !KeyTyped, cmd_silent); return len; *************** *** 3644,3650 **** p += 2; i -= 2; } - # ifndef MSWIN // When the GUI is not used CSI needs to be escaped. else if (!gui.in_use && p[0] == CSI) { --- 3654,3659 ---- *************** *** 3654,3660 **** *p = (int)KE_CSI; len += 2; } - # endif else #endif if (p[0] == NUL || (p[0] == K_SPECIAL --- 3663,3668 ---- *** ../vim-8.2.4001/src/testdir/test_utf8.vim 2021-10-20 11:01:10.760166755 +0100 --- src/testdir/test_utf8.vim 2022-01-04 18:00:36.269188726 +0000 *************** *** 1,5 **** --- 1,6 ---- " Tests for Unicode manipulations + source check.vim source view_util.vim " Visual block Insert adjusts for multi-byte char *************** *** 206,209 **** --- 207,261 ---- bwipe! endfunc + func Test_recording_with_select_mode_utf8() + call Run_test_recording_with_select_mode_utf8() + endfunc + + func Run_test_recording_with_select_mode_utf8() + new + + " No escaping + call feedkeys("qacc12345\gH哦\q", "tx") + call assert_equal("哦", getline(1)) + call assert_equal("cc12345\gH哦\", @a) + call setline(1, 'asdf') + normal! @a + call assert_equal("哦", getline(1)) + + " 固 is 0xE5 0x9B 0xBA where 0x9B is CSI + call feedkeys("qacc12345\gH固\q", "tx") + call assert_equal("固", getline(1)) + call assert_equal("cc12345\gH固\", @a) + call setline(1, 'asdf') + normal! @a + call assert_equal("固", getline(1)) + + " 四 is 0xE5 0x9B 0x9B where 0x9B is CSI + call feedkeys("qacc12345\gH四\q", "tx") + call assert_equal("四", getline(1)) + call assert_equal("cc12345\gH四\", @a) + call setline(1, 'asdf') + normal! @a + call assert_equal("四", getline(1)) + + " 倒 is 0xE5 0x80 0x92 where 0x80 is K_SPECIAL + call feedkeys("qacc12345\gH倒\q", "tx") + call assert_equal("倒", getline(1)) + call assert_equal("cc12345\gH倒\", @a) + call setline(1, 'asdf') + normal! @a + call assert_equal("倒", getline(1)) + + bwipe! + endfunc + + " This must be done as one of the last tests, because it starts the GUI, which + " cannot be undone. + func Test_zz_recording_with_select_mode_utf8_gui() + CheckCanRunGui + + gui -f + call Run_test_recording_with_select_mode_utf8() + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.4001/src/version.c 2022-01-04 17:01:40.602663101 +0000 --- src/version.c 2022-01-04 17:55:41.921654989 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4002, /**/ -- From the classified section of a city newspaper: Dog for sale: eats anything and is fond of children. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///