]> granicus.if.org Git - vim/commitdiff
patch 8.2.2428: FocusGained does not work when 'ttymouse' is empty v8.2.2428
authorBram Moolenaar <Bram@vim.org>
Sat, 30 Jan 2021 14:39:47 +0000 (15:39 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 30 Jan 2021 14:39:47 +0000 (15:39 +0100)
Problem:    FocusGained does not work when 'ttymouse' is empty.
Solution:   Don't use the short mouse code if there is a longer matching code.
            (closes #7755)  Add a test.

src/term.c
src/testdir/test_termcodes.vim
src/version.c

index 47e5dfd1eb406b16c48d65cfcb078ed089db2c6d..14405502879153781a8d75a0f575b49bbd643594 100644 (file)
@@ -5339,6 +5339,8 @@ check_termcode(
        else
 #endif // FEAT_GUI
        {
+           int  mouse_index_found = -1;
+
            for (idx = 0; idx < tc_len; ++idx)
            {
                /*
@@ -5376,9 +5378,24 @@ check_termcode(
                            }
                    }
 
-                   key_name[0] = termcodes[idx].name[0];
-                   key_name[1] = termcodes[idx].name[1];
-                   break;
+                   // The mouse termcode "ESC [" is also the prefix of
+                   // "ESC [ I" (focus gained).  Only use it when there is
+                   // no other match.  Do use it when a digit is following to
+                   // avoid waiting for more bytes.
+                   if (slen == 2 && len > 2
+                           && termcodes[idx].code[0] == ESC
+                           && termcodes[idx].code[1] == '['
+                           && !isdigit(tp[2]))
+                   {
+                       if (mouse_index_found < 0)
+                           mouse_index_found = idx;
+                   }
+                   else
+                   {
+                       key_name[0] = termcodes[idx].name[0];
+                       key_name[1] = termcodes[idx].name[1];
+                       break;
+                   }
                }
 
                /*
@@ -5389,7 +5406,7 @@ check_termcode(
                 * When there is a modifier the * matches a number.
                 * When there is no modifier the ;* or * is omitted.
                 */
-               if (termcodes[idx].modlen > 0)
+               if (termcodes[idx].modlen > 0 && mouse_index_found < 0)
                {
                    int at_code;
 
@@ -5442,6 +5459,11 @@ check_termcode(
                    }
                }
            }
+           if (idx == tc_len && mouse_index_found >= 0)
+           {
+               key_name[0] = termcodes[mouse_index_found].name[0];
+               key_name[1] = termcodes[mouse_index_found].name[1];
+           }
        }
 
 #ifdef FEAT_TERMRESPONSE
index 040869cc0bd9b352dde4e1235649daa67fae514c..b77c5067f1630b0613fd45db6685b242511d27a8 100644 (file)
@@ -1868,6 +1868,34 @@ func Test_xx07_xterm_response()
   call test_override('term_props', 0)
 endfunc
 
+func Test_focus_events()
+  let save_term = &term
+  let save_ttymouse = &ttymouse
+  set term=xterm ttymouse=xterm2
+
+  au FocusGained * let g:focus_gained += 1
+  au FocusLost * let g:focus_lost += 1
+  let g:focus_gained = 0
+  let g:focus_lost = 0
+
+  call feedkeys("\<Esc>[O", "Lx!")
+  call assert_equal(1, g:focus_lost)
+  call feedkeys("\<Esc>[I", "Lx!")
+  call assert_equal(1, g:focus_gained)
+
+  " still works when 'ttymouse' is empty
+  set ttymouse=
+  call feedkeys("\<Esc>[O", "Lx!")
+  call assert_equal(2, g:focus_lost)
+  call feedkeys("\<Esc>[I", "Lx!")
+  call assert_equal(2, g:focus_gained)
+
+  au! FocusGained
+  au! FocusLost
+  let &term = save_term
+  let &ttymouse = save_ttymouse
+endfunc
+
 func Test_get_termcode()
   try
     let k1 = &t_k1
@@ -2261,7 +2289,7 @@ func Test_cmdline_literal()
 endfunc
 
 " Test for translation of special key codes (<xF1>, <xF2>, etc.)
-func Test_Keycode_Tranlsation()
+func Test_Keycode_Translation()
   let keycodes = [
         \ ["<xUp>", "<Up>"],
         \ ["<xDown>", "<Down>"],
index 98f01dd790bc7bd389ffcfb0d01521c76445436d..f7e267f030ad4d208af6eaa5c6efdbc2865d95da 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2428,
 /**/
     2427,
 /**/