diff src/testdir/test_terminal.vim @ 26462:3af56224dca6 v8.2.3761

patch 8.2.3761: focus change is not passed on to a terminal window Commit: https://github.com/vim/vim/commit/a48d4e44a24191f5495e17d7616771c20ae3e3c1 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 8 22:13:38 2021 +0000 patch 8.2.3761: focus change is not passed on to a terminal window Problem: Focus change is not passed on to a terminal window. Solution: If the current window is a terminal and focus events are enabled send a focus event escape sequence to the terminal.
author Bram Moolenaar <Bram@vim.org>
date Wed, 08 Dec 2021 23:15:04 +0100
parents d25c0b0aad7d
children d413104a94c8
line wrap: on
line diff
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -1124,6 +1124,40 @@ func Test_terminal_response_to_control_s
   unlet g:job
 endfunc
 
+func Test_terminal_focus_events()
+  CheckNotGui
+  CheckUnix
+  CheckRunVimInTerminal
+
+  let save_term = &term
+  let save_ttymouse = &ttymouse
+  set term=xterm ttymouse=xterm2
+
+  let lines =<< trim END
+      set term=xterm ttymouse=xterm2
+      au FocusLost * echo 'I am lost'
+      au FocusGained * echo 'I am back'
+      " FIXME: sometimes this job hangs, exit after a couple of seconds
+      call timer_start(2000, {id -> execute('qall')})
+  END
+  call writefile(lines, 'XtermFocus')
+  let buf = RunVimInTerminal('-S XtermFocus', #{rows: 6})
+
+  " Send a focus event to ourselves, it should be forwarded to the terminal
+  call feedkeys("\<Esc>[O", "Lx!")
+  call TermWait(buf)
+  call VerifyScreenDump(buf, 'Test_terminal_focus_1', {})
+
+  call feedkeys("\<Esc>[I", "Lx!")
+  call TermWait(buf)
+  call VerifyScreenDump(buf, 'Test_terminal_focus_2', {})
+
+  call StopVimInTerminal(buf)
+  call delete('XtermFocus')
+  let &term = save_term
+  let &ttymouse = save_ttymouse
+endfunc
+
 " Run Vim, start a terminal in that Vim with the kill argument,
 " :qall works.
 func Run_terminal_qall_kill(line1, line2)