]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0507: hard to detect cursor movement in the command line v9.1.0507
authorShougo Matsushita <Shougo.Matsu@gmail.com>
Thu, 20 Jun 2024 20:05:16 +0000 (22:05 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 20 Jun 2024 20:05:16 +0000 (22:05 +0200)
Problem:  hard to detect cursor movement in the command line
Solution: Add the CursorMovedC autocommand
          (Shougo Matsushita)

closes: #15040

Signed-off-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/autocmd.txt
runtime/doc/tags
runtime/doc/version9.txt
src/autocmd.c
src/ex_getln.c
src/testdir/test_autocmd.vim
src/version.c
src/vim.h

index 037f89c4c7dd5880f308eecde913a7fd3411621a..27ab2c73c5ae40f5cb34247867c7fba9ed888a2e 100644 (file)
@@ -1,4 +1,4 @@
-*autocmd.txt*   For Vim version 9.1.  Last change: 2024 May 05
+*autocmd.txt*   For Vim version 9.1.  Last change: 2024 Jun 20
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -379,6 +379,7 @@ Name                        triggered by ~
 |CursorHold|           the user doesn't press a key for a while
 |CursorHoldI|          the user doesn't press a key for a while in Insert mode
 |CursorMoved|          the cursor was moved in Normal mode
+|CursorMovedC|         the cursor was moved in the |Command-line|
 |CursorMovedI|         the cursor was moved in Insert mode
 
 |WinNewPre|            before creating a new window
@@ -748,6 +749,13 @@ CursorMoved                        After the cursor was moved in Normal or Visual
                                Careful: This is triggered very often, don't
                                do anything that the user does not expect or
                                that is slow.
+                                                       *CursorMovedC*
+CursorMovedC                   After the cursor was moved in the command
+                               line. Be careful not to mess up the
+                               command line, it may cause Vim to lock up.
+                               <afile> is set to a single character,
+                               indicating the type of command-line.
+                               |cmdwin-char|
                                                        *CursorMovedI*
 CursorMovedI                   After the cursor was moved in Insert mode.
                                Not triggered when the popup menu is visible.
index ae8320520ab8962aa4dd1419cf7b4701d07f5918..4dd25ba21cf367d7b40fb5a90dbe2019cfe46724 100644 (file)
@@ -4063,6 +4063,7 @@ CursorHold-example        windows.txt     /*CursorHold-example*
 CursorHoldI    autocmd.txt     /*CursorHoldI*
 CursorIM       mbyte.txt       /*CursorIM*
 CursorMoved    autocmd.txt     /*CursorMoved*
+CursorMovedC   autocmd.txt     /*CursorMovedC*
 CursorMovedI   autocmd.txt     /*CursorMovedI*
 D      change.txt      /*D*
 DOS    os_dos.txt      /*DOS*
index e33b8fa70fb514060277cce6c7163f80556ecae9..d50e0e8fa1a48ccde9e71a340a03c31577e99160 100644 (file)
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2024 Jun 19
+*version9.txt*  For Vim version 9.1.  Last change: 2024 Jun 20
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41591,6 +41591,7 @@ Functions: ~
 
 Autocommands: ~
 
+|CursorMovedC|         after the cursor was moved in the comamnd-line
 |SessionWritePost|     after writing the session file |:mksession|
 |TermResponseAll|      after the terminal response to |t_RV| and others is
                        received
index 8380f8a04e4e7b7cf69ce3da138fb0e86c0d39b8..e60eac794d0b203c49439f80f752cb9cb2d65c86 100644 (file)
@@ -120,6 +120,7 @@ static keyvalue_T event_tab[] = {
     KEYVALUE_ENTRY(EVENT_CURSORHOLD, "CursorHold"),
     KEYVALUE_ENTRY(EVENT_CURSORHOLDI, "CursorHoldI"),
     KEYVALUE_ENTRY(EVENT_CURSORMOVED, "CursorMoved"),
+    KEYVALUE_ENTRY(EVENT_CURSORMOVEDC, "CursorMovedC"),
     KEYVALUE_ENTRY(EVENT_CURSORMOVEDI, "CursorMovedI"),
     KEYVALUE_ENTRY(EVENT_DIFFUPDATED, "DiffUpdated"),
     KEYVALUE_ENTRY(EVENT_DIRCHANGED, "DirChanged"),
@@ -2250,6 +2251,7 @@ apply_autocmds_group(
                || event == EVENT_CMDLINECHANGED
                || event == EVENT_CMDLINEENTER
                || event == EVENT_CMDLINELEAVE
+               || event == EVENT_CURSORMOVEDC
                || event == EVENT_CMDWINENTER
                || event == EVENT_CMDWINLEAVE
                || event == EVENT_CMDUNDEFINED
index 3444a0e86e695faaf97a2fdaeb4f6242ca0a5b8d..481b450dc1a90cb6ff45cc5b9fcb1c41864b29c9 100644 (file)
@@ -1586,6 +1586,7 @@ getcmdline_int(
     int                res;
     int                save_msg_scroll = msg_scroll;
     int                save_State = State;     // remember State when called
+    int                save_cmdspos = ccline.cmdspos;
     int                some_key_typed = FALSE; // one of the keys was typed
     // mouse drag and release events are ignored, unless they are
     // preceded with a mouse down event
@@ -2473,6 +2474,10 @@ getcmdline_int(
  * (Sorry for the goto's, I know it is ugly).
  */
 cmdline_not_changed:
+        // Trigger CursorMovedC autocommands.
+        if (ccline.cmdspos != save_cmdspos)
+           trigger_cmd_autocmd(cmdline_type, EVENT_CURSORMOVEDC);
+
 #ifdef FEAT_SEARCH_EXTRA
        if (!is_state.incsearch_postponed)
            continue;
@@ -2484,8 +2489,8 @@ cmdline_changed:
        if (is_state.winid != curwin->w_id)
            init_incsearch_state(&is_state);
 #endif
+       // Trigger CmdlineChanged autocommands.
        if (trigger_cmdlinechanged)
-           // Trigger CmdlineChanged autocommands.
            trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED);
 
 #ifdef FEAT_SEARCH_EXTRA
@@ -4315,6 +4320,10 @@ set_cmdline_pos(
        new_cmdpos = 0;
     else
        new_cmdpos = pos;
+
+    // Trigger CursorMovedC autocommands.
+    trigger_cmd_autocmd(get_cmdline_type(), EVENT_CURSORMOVEDC);
+
     return 0;
 }
 
index c9f257a87cfa208e025b2fc52a7128bc295c5ef3..faa0f9771c974347a9ba66114130d99099684c11 100644 (file)
@@ -2096,6 +2096,21 @@ func Test_Cmdline()
   au! CmdlineEnter
   au! CmdlineLeave
   let &shellslash = save_shellslash
+
+  au! CursorMovedC : let g:pos = getcmdpos()
+  let g:pos = 0
+  call feedkeys(":hello\<Left>\<ESC>", 'xt')
+  call assert_equal(5, g:pos)
+  call feedkeys(":12345678\<C-R>=setcmdpos(3)\<CR>\<ESC>", 'xt')
+  call assert_equal(3, g:pos)
+  au! CursorMovedC
+
+  " CursorMovedC changes the cursor position.
+  au! CursorMovedC : let g:pos = getcmdpos() | call setcmdpos(getcmdpos()-1)
+  let g:pos = 0
+  call feedkeys(":hello\<Left>\<ESC>", 'xt')
+  call assert_equal(5, g:pos)
+  au! CursorMovedC
 endfunc
 
 " Test for BufWritePre autocommand that deletes or unloads the buffer.
index 9d40d8fde8b52d8e5569e26f07e43f34a5b1c17b..da82b3683fb6232007188d69d8828db32125b343 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    507,
 /**/
     506,
 /**/
index e703239371476a82625853f109cca566aa170914..a80f8448487d617e42392aa9d2d989b06635798f 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1361,6 +1361,7 @@ enum auto_event
     EVENT_CURSORHOLD,          // cursor in same position for a while
     EVENT_CURSORHOLDI,         // idem, in Insert mode
     EVENT_CURSORMOVED,         // cursor was moved
+    EVENT_CURSORMOVEDC,                // cursor was moved in Command line mode
     EVENT_CURSORMOVEDI,                // cursor was moved in Insert mode
     EVENT_DIFFUPDATED,         // after diffs were updated
     EVENT_DIRCHANGED,          // after user changed directory