From ab2cb3444b543bd1f0f983956f9dbad4620368b8 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Sun, 7 Jul 2019 10:53:28 +0200 Subject: [PATCH] *ctx*: Correct handling of the list boundaries --- history-search-multi-word | 2 +- hsmw-context-main | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/history-search-multi-word b/history-search-multi-word index 62a1b48..ef2eebe 100644 --- a/history-search-multi-word +++ b/history-search-multi-word @@ -39,7 +39,7 @@ typeset -gi __hsmw_page_start_idx __hsmw_prev_offset __hsmw_recedit_trap_execute typeset -ga __hsmw_hcw_found # Context variables -typeset -gi __hsmw_ctx __hsmw_ctx_idx __hsmw_ctx_text_idx __hsmw_ctx_which +typeset -gi __hsmw_ctx __hsmw_ctx_idx __hsmw_ctx_prev_idx __hsmw_ctx_text_idx __hsmw_ctx_which typeset -gi __hsmw_ctx_page_start_idx __hsmw_ctx_prev_offset typeset -g __hsmw_ctx_to_search typeset -ga __hsmw_ctx_disp_list diff --git a/hsmw-context-main b/hsmw-context-main index d8b7d23..6260961 100644 --- a/hsmw-context-main +++ b/hsmw-context-main @@ -1,6 +1,8 @@ # -*- Mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # vim:ft=zsh:sw=4:sts=4:et +__hsmw_ctx_prev_idx="$__hsmw_ctx_idx" + [[ "$WIDGET" = *-word ]] && (( __hsmw_ctx_idx -- )) [[ "$WIDGET" = *-backwards ]] && (( __hsmw_ctx_idx ++ )) [[ "$WIDGET" = *-pforwards ]] && (( __hsmw_ctx_idx = __hsmw_ctx_idx - __hsmw_page_size )) @@ -91,8 +93,8 @@ _hsmw_ctx_main() { integer page_size="$__hsmw_page_size" [[ "$page_size" -gt "$max_index" ]] && page_size="$max_index" - [[ "$the_index" -le 0 ]] && the_index="$max_index" - [[ "$the_index" -gt "$max_index" ]] && the_index=1 + [[ "$the_index" -le 0 ]] && { __hsmw_ctx_idx="$__hsmw_ctx_prev_idx"; the_index=1; } + [[ "$the_index" -gt "$(( max_index - 1))" ]] && { __hsmw_ctx_idx="$__hsmw_ctx_prev_idx"; the_index="$(( max_index - 1 ))"; } integer page_start_idx=$(( ((the_index-1)/page_size)*page_size+1 )) integer on_page_idx=$(( page_size - (the_index - page_start_idx) ))