Skip to content

Commit

Permalink
Only apply v:count1 when highlight_on_keys is set
Browse files Browse the repository at this point in the history
Fix #60

With the Vanilla always on highlight mode we have no way of knowing at
highlight time whether the user will type `[count]f*` or just `f*` so we
have to highlight assuming count of 1.

This adds a conditional to check for the highlight_on_keys variable to
enable using count for highlighting the appropriate [count] targets.
  • Loading branch information
bradford-smith94 committed Jul 31, 2020
1 parent 03f0471 commit 64a5e6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions autoload/quick_scope.vim
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ function! s:get_highlight_patterns(line, cursor, end, targets) abort
" Keeps track of the number of occurrences for each target
let occurrences = {}

" Use 'count_proxy' to account for [count]f when highlight on keys mode is
" used, otherwise just use assume 1
if !exists('g:qs_highlight_on_keys')
let count_proxy = 1
else
let count_proxy = v:count1
endif

" Patterns to match the characters that will be marked with primary and
" secondary highlight groups, respectively
let [patt_p, patt_s] = ['', '']
Expand Down Expand Up @@ -295,10 +303,10 @@ function! s:get_highlight_patterns(line, cursor, end, targets) abort
" composing bytes so we adjust accordingly
" eg. with a multibyte char of length 3, c will point to the
" 3rd byte. Minus (len(char) - 1) to adjust to 1st byte
if char_occurrences == v:count1 && ((direction == 1 && hi_p == 0) || direction == 0)
if char_occurrences == count_proxy && ((direction == 1 && hi_p == 0) || direction == 0)
let hi_p = c - (1 - direction) * (len(char) - 1)
let char_p = char
elseif char_occurrences == (v:count1 + 1) && ((direction == 1 && hi_s == 0) || direction == 0)
elseif char_occurrences == (count_proxy + 1) && ((direction == 1 && hi_s == 0) || direction == 0)
let hi_s = c - (1 - direction) * (len(char)- 1)
let char_s = char
endif
Expand Down
6 changes: 5 additions & 1 deletion doc/quick-scope.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*quick-scope.txt* Highlight unique character targets for f/F and t/T motions.
*quick-scope*

Version: 2.5.7
Version: 2.5.8
Homepage: https://github.com/unblevable/quick-scope
Authors: Brian Le (unblevable)
Bradford Smith (https://github.com/bradford-smith94)
Expand Down Expand Up @@ -248,6 +248,10 @@ http://github.com/unblevable/quick-scope/issues

Version Date Release Notes~
|---------|-----------|-----------------------------------------------------------|
2.5.8 2020-07-31 * Fixed
- Fixes issue in Vanilla highlight mode with [count]
movements throwing off the highlighted characters,
don't enable the 2.5.7 fix for Vanilla mode
2.5.7 2020-06-18 * Fixed
- Fixes which characters are highlighted when using a
count combined with highlight on keys mode
Expand Down

0 comments on commit 64a5e6f

Please sign in to comment.