To: vim_dev@googlegroups.com Subject: Patch 8.2.1837 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1837 Problem: Using "gn" after "gN" does not work. Solution: Extend the other end of the Visual area. (closes #7109) Files: src/search.c, src/testdir/test_gn.vim *** ../vim-8.2.1836/src/search.c 2020-10-10 16:45:20.707469205 +0200 --- src/search.c 2020-10-11 20:39:40.533974414 +0200 *************** *** 2961,2971 **** --- 2961,2977 ---- int flags = 0; pos_T save_VIsual = VIsual; int zero_width; + int skip_first_backward; // Correct cursor when 'selection' is exclusive if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor)) dec_cursor(); + // When searching forward and the cursor is at the start of the Visual + // area, skip the first search backward, otherwise it doesn't move. + skip_first_backward = forward && VIsual_active + && LT_POS(curwin->w_cursor, VIsual); + orig_pos = pos = curwin->w_cursor; if (VIsual_active) { *************** *** 2984,2995 **** /* * The trick is to first search backwards and then search forward again, * so that a match at the current cursor position will be correctly ! * captured. */ for (i = 0; i < 2; i++) { if (forward) dir = i; else dir = !i; --- 2990,3005 ---- /* * The trick is to first search backwards and then search forward again, * so that a match at the current cursor position will be correctly ! * captured. When "forward" is false do it the other way around. */ for (i = 0; i < 2; i++) { if (forward) + { + if (i == 0 && skip_first_backward) + continue; dir = i; + } else dir = !i; *************** *** 3043,3052 **** if (!VIsual_active) VIsual = start_pos; ! // put cursor on last character of match curwin->w_cursor = end_pos; if (LT_POS(VIsual, end_pos) && forward) ! dec_cursor(); else if (VIsual_active && LT_POS(curwin->w_cursor, VIsual) && forward) curwin->w_cursor = pos; // put the cursor on the start of the match VIsual_active = TRUE; --- 3053,3069 ---- if (!VIsual_active) VIsual = start_pos; ! // put the cursor after the match curwin->w_cursor = end_pos; if (LT_POS(VIsual, end_pos) && forward) ! { ! if (skip_first_backward) ! // put the cursor on the start of the match ! curwin->w_cursor = pos; ! else ! // put the cursor on last character of match ! dec_cursor(); ! } else if (VIsual_active && LT_POS(curwin->w_cursor, VIsual) && forward) curwin->w_cursor = pos; // put the cursor on the start of the match VIsual_active = TRUE; *** ../vim-8.2.1836/src/testdir/test_gn.vim 2020-10-10 16:45:20.707469205 +0200 --- src/testdir/test_gn.vim 2020-10-11 20:43:34.429246299 +0200 *************** *** 183,188 **** --- 183,204 ---- bwipe! endfunc + func Test_gN_then_gn() + new + + call setline(1, 'this list is a list with a list of a last.') + /l.st + normal $gNgNgnx + call assert_equal('last', @") + + call setline(1, 'this list is a list with a lust of a last.') + /l.st + normal $gNgNgNgnx + call assert_equal('lust of a last', @") + + bwipe! + endfunc + func Test_gn_multi_line() new call setline(1, [ *** ../vim-8.2.1836/src/version.c 2020-10-11 20:08:39.448720572 +0200 --- src/version.c 2020-10-11 20:24:24.729272344 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1837, /**/ -- hundred-and-one symptoms of being an internet addict: 66. You create a homepage with the impression to cure the afflicted...but your hidden agenda is to receive more e-mail. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///