]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2082: modeless auto-select not working v9.1.2082
authorFoxe Chen <chen.foxe@gmail.com>
Tue, 13 Jan 2026 20:15:07 +0000 (20:15 +0000)
committerChristian Brabandt <cb@256bit.org>
Tue, 13 Jan 2026 20:15:07 +0000 (20:15 +0000)
Problem:  modeless auto-select not working
          (Coacher)
Solution: Add support for modeless autoselect
          (Foxe Chen)

fixes:  #19159
closes: #19168

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/clipboard.c
src/ex_getln.c
src/mouse.c
src/testdir/test_gui.vim
src/testdir/test_modeless.vim
src/version.c

index d016ee3cafcf3d8c5174c37151cd19154337aab9..ae80ab42ee34c53b9a68b490bff600826cda8689 100644 (file)
@@ -890,7 +890,7 @@ clip_process_selection(
        printf("Selection ended: (%ld,%d) to (%ld,%d)\n", cb->start.lnum,
                cb->start.col, cb->end.lnum, cb->end.col);
 #endif
-       if (clip_isautosel_star()
+       if (clip_isautosel_star() || clip_isautosel_plus()
                || (
 #ifdef FEAT_GUI
                    gui.in_use ? (vim_strchr(p_go, GO_ASELML) != NULL) :
@@ -1119,13 +1119,17 @@ clip_scroll_selection(
 }
 
 /*
- * Copy the currently selected area into the '*' register so it will be
+ * Copy the currently selected area into the '*' or '+' register so it will be
  * available for pasting.
- * When "both" is TRUE also copy to the '+' register.
+ * When "both" is TRUE also copy to the other register.
  */
     void
 clip_copy_modeless_selection(int both UNUSED)
 {
+    // The info for the modeless selection is stored in '*' register, however if
+    // we are using the '+' register for modeless autoselect, we copy to
+    // clip_plus instead while using the info in clip_star.
+    Clipboard_T *cbd = clip_isautosel_plus() ? &clip_plus : &clip_star;
     char_u     *buffer;
     char_u     *bufp;
     int                row;
@@ -1297,23 +1301,24 @@ clip_copy_modeless_selection(int both UNUSED)
        *bufp++ = NL;
 
     // First cleanup any old selection and become the owner.
-    clip_free_selection(&clip_star);
-    clip_own_selection(&clip_star);
+    clip_free_selection(cbd);
+    clip_own_selection(cbd);
 
     // Yank the text into the '*' register.
-    clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_star);
+    clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), cbd);
 
     // Make the register contents available to the outside world.
-    clip_gen_set_selection(&clip_star);
+    clip_gen_set_selection(cbd);
 
 #ifdef FEAT_X11
     if (both)
     {
+       Clipboard_T *other = cbd == &clip_star ? &clip_plus : &clip_star;
        // Do the same for the '+' register.
-       clip_free_selection(&clip_plus);
-       clip_own_selection(&clip_plus);
-       clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_plus);
-       clip_gen_set_selection(&clip_plus);
+       clip_free_selection(other);
+       clip_own_selection(other);
+       clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), other);
+       clip_gen_set_selection(other);
     }
 #endif
     vim_free(buffer);
index 4ebfbfc5e4fba476595659d3323e2762e964d87e..7cf8a10ae1c1c95bfac74c37a2b4a9c7032030d2 100644 (file)
@@ -1347,7 +1347,7 @@ cmdline_left_right_mouse(int c, int *ignore_drag_release)
        if (!mouse_has(MOUSE_COMMAND))
            return;
 # ifdef FEAT_CLIPBOARD
-    if (mouse_row < cmdline_row && clip_star.available)
+    if (mouse_row < cmdline_row && (clip_star.available || clip_plus.available))
     {
        int         button, is_click, is_drag;
 
index d11491005c9cda2b1ca5d9e1832db1c7b14ce516..84b8808dfd7f585da69f72b28913db96b60a8741 100644 (file)
@@ -795,7 +795,8 @@ do_mouse(
 #endif
 
 #if defined(FEAT_CLIPBOARD)
-    if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available)
+    if ((jump_flags & IN_OTHER_WIN) && !VIsual_active &&
+           (clip_star.available || clip_plus.available))
     {
        clip_modeless(which_button, is_click, is_drag);
        return FALSE;
index 7635245b3176188f49a687e7932542a15d7df594..3837837be7ee77f4f7dd6bab86781651ba3e9b60 100644 (file)
@@ -1248,6 +1248,19 @@ func Test_gui_mouse_event()
   call assert_equal([0, 2, 7, 0], getpos('.'))
   call assert_equal('wo thrfour five sixteen', getline(2))
 
+  " Test P option (use '+' register for modeless)
+  set guioptions+=AP
+  call cursor(1, 6)
+  redraw!
+  let @+ = ''
+  let args = #{button: 2, row: 1, col: 11, multiclick: 0, modifiers: 0}
+  call test_gui_event('mouse', args)
+  let args.button = 3
+  call test_gui_event('mouse', args)
+  call feedkeys("\<Esc>", 'Lx!')
+  call assert_equal([0, 1, 6, 0], getpos('.'))
+  call assert_equal('wo thr', @+)
+
   set mouse&
   let &guioptions = save_guioptions
   bw!
index ef597ada18d4fd2f200740ba069d5b44595c4a62..d21df62ab4efe055278a6aa95579cada34f1b526 100644 (file)
@@ -219,6 +219,19 @@ func Test_modeless_characterwise_selection()
     call assert_equal("bar", @*)
     set clipboard&
 
+    " Test for 'clipboard' set to 'autoselectplus' to automatically copy the
+    " modeless selection to the '+' clipboard.
+    set clipboard=autoselectplus
+    let @* = 'clean'
+    let keys = ":"
+    let keys ..= MouseLeftClickCode(2, 5)
+    let keys ..= MouseLeftDragCode(2, 7)
+    let keys ..= MouseLeftReleaseCode(2, 7)
+    let keys ..= "\<CR>"
+    call feedkeys(keys, "x")
+    call assert_equal("bar", @+)
+    set clipboard&
+
     " quadruple click should start characterwise selectmode
     let @* = 'clean'
     call MouseRightClick(1, 1)
index 126e1cf7754a6753ae33a86dea3ba3c85ddeb60e..60c86985b03a2a5c90b1fd0a41ed6c160790aaf3 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2082,
 /**/
     2081,
 /**/