diff --git a/history-substring-search.zsh b/history-substring-search.zsh index c1e51e0..53f707c 100644 --- a/history-substring-search.zsh +++ b/history-substring-search.zsh @@ -319,10 +319,28 @@ function _history-substring-search-begin() { _history_substring_search_matches_count_sans=$(( _history_substring_search_matches_count - 1 )) # - # initial value of $_history_substring_search_match_index, which - # can only be decreased by the history-substring-search-* widgets. + # If $_history_substring_search_match_index is equal to + # $_history_substring_search_matches_count_plus, this indicates that we + # are beyond the beginning of $_history_substring_search_matches. # - _history_substring_search_match_index=$_history_substring_search_matches_count_plus + # If $_history_substring_search_match_index is equal to 0, this indicates + # that we are beyond the end of $_history_substring_search_matches. + # + # If we have initially pressed "up" we have to initialize + # $_history_substring_search_match_index to + # $_history_substring_search_matches_count_plus so that it will be + # decreased to $_history_substring_search_matches_count. + # + # If we have initially pressed "down" we have to initialize + # $_history_substring_search_match_index to + # $_history_substring_search_matches_count so that it will be increased to + # $_history_substring_search_matches_count_plus. + # + if [[ $WIDGET == history-substring-search-down ]]; then + _history_substring_search_match_index=$_history_substring_search_matches_count + else + _history_substring_search_match_index=$_history_substring_search_matches_count_plus + fi fi } @@ -465,23 +483,29 @@ function _history-substring-search-up-search() { _history_substring_search_move_cursor_eol=true # - # Highlight matches during a history-substring-search: + # Highlight matches during history-substring-up-search: # - # * $_history_substring_search_matches: the current list of matches - # * $_history_substring_search_matches_count: the current number of matches - # * $_history_substring_search_matches_count_plus: the current number of matches + 1 - # * $_history_substring_search_matches_count_sans: the current number of matches - 1 - # * $_history_substring_search_match_index: the number of the current match + # The following constants have been initialized in + # _history-substring-search-up/down-search(): # - # The range of values that $_history_substring_search_match_index - # can take is: [0, $_history_substring_search_matches_count_plus]. - # A value of 0 indicates that we are beyond the end of + # $_history_substring_search_matches is the current list of matches + # $_history_substring_search_matches_count is the current number of matches + # $_history_substring_search_matches_count_plus is the current number of matches + 1 + # $_history_substring_search_matches_count_sans is the current number of matches - 1 + # $_history_substring_search_match_index is the index of the current match + # + # The range of values that $_history_substring_search_match_index can take + # is: [0, $_history_substring_search_matches_count_plus]. A value of 0 + # indicates that we are beyond the end of # $_history_substring_search_matches. A value of - # $_history_substring_search_matches_count_plus indicates that we - # are beyond the beginning of $_history_substring_search_matches. + # $_history_substring_search_matches_count_plus indicates that we are beyond + # the beginning of $_history_substring_search_matches. # - # The initial value of $_history_substring_search_match_index is - # $_history_substring_search_matches_count_plus. + # In _history-substring-search-up-search() the initial value of + # $_history_substring_search_match_index is + # $_history_substring_search_matches_count_plus. This value is set in + # _history-substring-search-begin(). _history-substring-search-up-search() + # will initially decrease it to $_history_substring_search_matches_count. # if [[ $_history_substring_search_match_index -ge 2 ]]; then # @@ -538,36 +562,32 @@ function _history-substring-search-down-search() { _history_substring_search_move_cursor_eol=true # - # Highlight matches during a history-substring-search: + # Highlight matches during history-substring-up-search: # - # $_history_substring_search_matches: the current list of matches - # $_history_substring_search_matches_count: the current number of matches - # $_history_substring_search_matches_count_plus: the current number of matches + 1 - # $_history_substring_search_matches_count_sans: the current number of matches - 1 - # $_history_substring_search_match_index: the number of the current match + # The following constants have been initialized in + # _history-substring-search-up/down-search(): # - # The range of values that $_history_substring_search_match_index - # can take is: [0, $_history_substring_search_matches_count_plus]. - # A value of 0 indicates that we are beyond the end of + # $_history_substring_search_matches is the current list of matches + # $_history_substring_search_matches_count is the current number of matches + # $_history_substring_search_matches_count_plus is the current number of matches + 1 + # $_history_substring_search_matches_count_sans is the current number of matches - 1 + # $_history_substring_search_match_index is the index of the current match + # + # The range of values that $_history_substring_search_match_index can take + # is: [0, $_history_substring_search_matches_count_plus]. A value of 0 + # indicates that we are beyond the end of # $_history_substring_search_matches. A value of - # $_history_substring_search_matches_count_plus indicates that we - # are beyond the beginning of $_history_substring_search_matches. + # $_history_substring_search_matches_count_plus indicates that we are beyond + # the beginning of $_history_substring_search_matches. # - # The initial value of $_history_substring_search_match_index is + # In _history-substring-search-down-search() the initial value of + # $_history_substring_search_match_index is + # $_history_substring_search_matches_count. This value is set in + # _history-substring-search-begin(). + # _history-substring-search-down-search() will initially increase it to # $_history_substring_search_matches_count_plus. # - if [[ $_history_substring_search_match_index -eq $_history_substring_search_matches_count_plus ]]; then - # - # DOWN was pressed immediately. $_history_substring_search_match_index is - # still equal to $_history_substring_search_match_number_plus. - # However, there is no highlighting yet: - # - # 1. We have to use $HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND - # to highlight the current buffer. - # - _history_substring_search_query_highlight=$HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND - - elif [[ $_history_substring_search_match_index -le $_history_substring_search_matches_count_sans ]]; then + if [[ $_history_substring_search_match_index -le $_history_substring_search_matches_count_sans ]]; then # # Highlight the next match: #