@@ -4620,7 +4620,7 @@ current_quote(
46204620
46214621#endif /* FEAT_TEXTOBJ */
46224622
4623- static int is_one_char (char_u * pattern , int move , pos_T * cur );
4623+ static int is_one_char (char_u * pattern , int move , pos_T * cur , int direction );
46244624
46254625/*
46264626 * Find next search match under cursor, cursor at end.
@@ -4641,6 +4641,7 @@ current_search(
46414641 int flags = 0 ;
46424642 pos_T save_VIsual = VIsual ;
46434643 int one_char ;
4644+ int direction = forward ? FORWARD : BACKWARD ;
46444645
46454646 /* wrapping should not occur */
46464647 p_ws = FALSE;
@@ -4667,8 +4668,10 @@ current_search(
46674668 else
46684669 orig_pos = pos = curwin -> w_cursor ;
46694670
4670- /* Is the pattern is zero-width? */
4671- one_char = is_one_char (spats [last_idx ].pat , TRUE, & curwin -> w_cursor );
4671+ /* Is the pattern is zero-width?, this time, don't care about the direction
4672+ */
4673+ one_char = is_one_char (spats [last_idx ].pat , TRUE, & curwin -> w_cursor ,
4674+ FORWARD );
46724675 if (one_char == -1 )
46734676 {
46744677 p_ws = old_p_ws ;
@@ -4727,19 +4730,19 @@ current_search(
47274730 }
47284731
47294732 start_pos = pos ;
4730- flags = forward ? SEARCH_END : 0 ;
4733+ flags = forward ? SEARCH_END : SEARCH_START ;
47314734
47324735 /* Check again from the current cursor position,
47334736 * since the next match might actually by only one char wide */
4734- one_char = is_one_char (spats [last_idx ].pat , FALSE, & pos );
4737+ one_char = is_one_char (spats [last_idx ].pat , FALSE, & pos , direction );
47354738 if (one_char < 0 )
47364739 /* search failed, abort */
47374740 return FAIL ;
47384741
47394742 /* move to match, except for zero-width matches, in which case, we are
47404743 * already on the next match */
47414744 if (!one_char )
4742- result = searchit (curwin , curbuf , & pos , ( forward ? FORWARD : BACKWARD ) ,
4745+ result = searchit (curwin , curbuf , & pos , direction ,
47434746 spats [last_idx ].pat , 0L , flags | SEARCH_KEEP , RE_SEARCH , 0 ,
47444747 NULL , NULL );
47454748
@@ -4788,10 +4791,11 @@ current_search(
47884791 * Check if the pattern is one character long or zero-width.
47894792 * If move is TRUE, check from the beginning of the buffer, else from position
47904793 * "cur".
4794+ * "direction" is FORWARD or BACKWARD.
47914795 * Returns TRUE, FALSE or -1 for failure.
47924796 */
47934797 static int
4794- is_one_char (char_u * pattern , int move , pos_T * cur )
4798+ is_one_char (char_u * pattern , int move , pos_T * cur , int direction )
47954799{
47964800 regmmatch_T regmatch ;
47974801 int nmatched = 0 ;
@@ -4821,7 +4825,7 @@ is_one_char(char_u *pattern, int move, pos_T *cur)
48214825 flag = SEARCH_START ;
48224826 }
48234827
4824- if (searchit (curwin , curbuf , & pos , FORWARD , pattern , 1 ,
4828+ if (searchit (curwin , curbuf , & pos , direction , pattern , 1 ,
48254829 SEARCH_KEEP + flag , RE_SEARCH , 0 , NULL , NULL ) != FAIL )
48264830 {
48274831 /* Zero-width pattern should match somewhere, then we can check if
@@ -4834,7 +4838,8 @@ is_one_char(char_u *pattern, int move, pos_T *cur)
48344838 pos .lnum , regmatch .startpos [0 ].col , NULL , NULL );
48354839 if (!nmatched )
48364840 break ;
4837- } while (regmatch .startpos [0 ].col < pos .col );
4841+ } while (direction == FORWARD ? regmatch .startpos [0 ].col < pos .col
4842+ : regmatch .startpos [0 ].col > pos .col );
48384843
48394844 if (!called_emsg )
48404845 {
0 commit comments