Skip to content

Commit

Permalink
Fix rounding error in list trimming
Browse files Browse the repository at this point in the history
Fixes #311.
  • Loading branch information
marlonrichert committed Aug 5, 2021
1 parent c37de22 commit ca35064
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions module/.autocomplete.async
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ zle -N history-incremental-search-forward .autocomplete.async.history-incrementa
local -i max_lines
zstyle -s ":autocomplete:${curcontext}:" list-lines max_lines ||
(( max_lines = 16 ))
(( _autocomplete__buffer_start_line = LINES - max_lines ))
(( _autocomplete__buffer_start_line = min( max( LINES - max_lines, 1 ), LINES ) ))
return 0
fi

Expand Down Expand Up @@ -103,7 +103,7 @@ zle -N history-incremental-search-forward .autocomplete.async.history-incrementa
read -rsk
done

(( _autocomplete__buffer_start_line = Y - i ))
(( _autocomplete__buffer_start_line = min( max( Y - i, 1 ), LINES ) ))
}

.autocomplete.async.history-incremental-search() {
Expand Down Expand Up @@ -370,12 +370,11 @@ zle -N history-incremental-search-forward .autocomplete.async.history-incrementa
.autocomplete.async.list-choices.main-complete() {
local -i _async_max_lines
() {
local -i min_lines max_lines lines_below_buffer
(( max_lines = LINES - BUFFERLINES ))
local -i min_lines lines_below_buffer
zstyle -s ":autocomplete:${curcontext}:" list-lines min_lines ||
min_lines=16
(( min_lines = min( min_lines, max_lines ) ))
(( lines_below_buffer = max_lines - _autocomplete__buffer_start_line ))
(( lines_below_buffer = LINES - ( _autocomplete__buffer_start_line + BUFFERLINES ) ))
(( min_lines = min( LINES - ( 1 + BUFFERLINES ), min_lines ) ))
(( _async_max_lines = max( min_lines, lines_below_buffer ) ))
}

Expand Down Expand Up @@ -494,7 +493,7 @@ zle -N history-incremental-search-forward .autocomplete.async.history-incrementa
set -- "${(@kv)groupname}" "$@"

if (( lines_of_new_matches > 0 )); then
local -F matches_per_line
local -i matches_per_line
(( matches_per_line = 1.0 * number_of_new_matches / lines_of_new_matches ))
if (( matches_per_line < 1 )); then
dopt[1]=-ld
Expand Down

0 comments on commit ca35064

Please sign in to comment.