From 2ae4554bec24e1684a52a0bda41ff446d5d3da42 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 21 Aug 2012 14:36:09 +0200 Subject: [PATCH 1/2] FIX: Index out-of-bounds error when at last choice. The index must be reset to zero. As the element is guaranteed to be inside the match list, we can simply use modulo for that. --- plugin/swapit.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/swapit.vim b/plugin/swapit.vim index 9812da8..68b6476 100755 --- a/plugin/swapit.vim +++ b/plugin/swapit.vim @@ -343,8 +343,9 @@ fun! ShowSwapChoices(match_list, cur_word, direction, is_visual) "Generate the prompt {{{3 for swap_list in a:match_list + let next_index = (index(swap_list['options'], a:cur_word) + 1) % len(swap_list['options']) let confirm_options = confirm_options . ' ' . a_opts[con_index] . " . " . swap_list['name'] . ' (' . - \a:cur_word . ' > ' . swap_list['options'][index(swap_list['options'], a:cur_word) + 1] . ') ' + \a:cur_word . ' > ' . swap_list['options'][next_index] . ') ' " For some reason concatenating stuffs up the string, using an " if con_index > 0 From 3695a6da5a0c3f06bbe49fcebbc98fd3b73573a0 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 21 Aug 2012 14:45:48 +0200 Subject: [PATCH 2/2] Show correct choice when moving backward. At the first element, the index is turned into -1, the modulo operation leaves that alone, and Vim indexing accesses the last element, leading to a correct wrap-around. --- plugin/swapit.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/swapit.vim b/plugin/swapit.vim index 68b6476..efa423b 100755 --- a/plugin/swapit.vim +++ b/plugin/swapit.vim @@ -343,7 +343,7 @@ fun! ShowSwapChoices(match_list, cur_word, direction, is_visual) "Generate the prompt {{{3 for swap_list in a:match_list - let next_index = (index(swap_list['options'], a:cur_word) + 1) % len(swap_list['options']) + let next_index = (index(swap_list['options'], a:cur_word) + (a:direction == 'forward' ? 1 : -1)) % len(swap_list['options']) let confirm_options = confirm_options . ' ' . a_opts[con_index] . " . " . swap_list['name'] . ' (' . \a:cur_word . ' > ' . swap_list['options'][next_index] . ') '