To: vim_dev@googlegroups.com Subject: Patch 8.2.3828 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3828 Problem: when opening a terminal from a timer the first typed character is lost. (Virginia Senioria) Solution: When opening a terminal while waiting for a character put K_IGNORE in the input buffer. Files: src/terminal.c, src/edit.c, src/testdir/test_terminal.vim *** ../vim-8.2.3827/src/terminal.c 2021-12-14 08:41:26.403677999 +0000 --- src/terminal.c 2021-12-16 17:27:03.160960489 +0000 *************** *** 739,744 **** --- 739,761 ---- curwin->w_buffer = curbuf; ++curbuf->b_nwindows; } + else if (vgetc_busy + #ifdef FEAT_TIMERS + || timer_busy + #endif + || input_busy) + { + char_u ignore[4]; + + // When waiting for input need to return and possibly end up in + // terminal_loop() instead. + ignore[0] = K_SPECIAL; + ignore[1] = KS_EXTRA; + ignore[2] = KE_IGNORE; + ignore[3] = NUL; + ins_typebuf(ignore, REMAP_NONE, 0, TRUE, FALSE); + typebuf_was_filled = TRUE; + } } else { *** ../vim-8.2.3827/src/edit.c 2021-12-12 14:16:34.989862195 +0000 --- src/edit.c 2021-12-16 18:01:50.539978020 +0000 *************** *** 598,606 **** { c = safe_vgetc(); ! if (stop_insert_mode) { ! // Insert mode ended, possibly from a callback. if (c != K_IGNORE && c != K_NOP) vungetc(c); count = 0; --- 598,611 ---- { c = safe_vgetc(); ! if (stop_insert_mode ! #ifdef FEAT_TERMINAL ! || (c == K_IGNORE && term_use_loop()) ! #endif ! ) { ! // Insert mode ended, possibly from a callback, or a timer ! // must have opened a terminal window. if (c != K_IGNORE && c != K_NOP) vungetc(c); count = 0; *** ../vim-8.2.3827/src/testdir/test_terminal.vim 2021-12-14 11:16:26.814008783 +0000 --- src/testdir/test_terminal.vim 2021-12-16 17:58:31.905009547 +0000 *************** *** 1596,1601 **** --- 1596,1602 ---- " 4. 0.5 sec later: should be done, clean up func Test_terminal_statusline() CheckUnix + CheckFeature timers set statusline=x terminal *************** *** 1611,1616 **** --- 1612,1642 ---- set statusline= endfunc + func CheckTerminalWindowWorks(buf) + call WaitForAssert({-> assert_match('!sh \[running\]', term_getline(a:buf, 10))}) + call term_sendkeys(a:buf, "exit\") + call WaitForAssert({-> assert_match('!sh \[finished\]', term_getline(a:buf, 10))}) + call term_sendkeys(a:buf, ":q\") + call WaitForAssert({-> assert_match('^\~', term_getline(a:buf, 10))}) + endfunc + + func Test_start_terminal_from_timer() + CheckUnix + CheckFeature timers + + " Open a terminal window from a timer, typed text goes to the terminal + call writefile(["call timer_start(100, { -> term_start('sh') })"], 'XtimerTerm') + let buf = RunVimInTerminal('-S XtimerTerm', {}) + call CheckTerminalWindowWorks(buf) + + " do the same in Insert mode + call term_sendkeys(buf, ":call timer_start(200, { -> term_start('sh') })\a") + call CheckTerminalWindowWorks(buf) + + call StopVimInTerminal(buf) + call delete('XtimerTerm') + endfunc + func Test_terminal_window_focus() let winid1 = win_getid() terminal *** ../vim-8.2.3827/src/version.c 2021-12-16 16:11:49.217060095 +0000 --- src/version.c 2021-12-16 18:00:29.948619931 +0000 *************** *** 751,752 **** --- 751,754 ---- { /* Add new patch number below this line */ + /**/ + 3828, /**/ -- hundred-and-one symptoms of being an internet addict: 44. Your friends no longer send you e-mail...they just log on to your IRC channel. /// 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 ///