Skip to content

Commit

Permalink
Adjust the fzy matched indices for tags provider
Browse files Browse the repository at this point in the history
Also fix a dummy error in fzy_impl.py
  • Loading branch information
liuchengxu committed Oct 27, 2019
1 parent 751ff99 commit 820980f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions autoload/clap/impl.vim
Expand Up @@ -100,16 +100,22 @@ function! s:add_highlight_for_fuzzy_matched() abort
" TODO: also add highlights for the cached lines?
let hl_lines = g:__clap_fuzzy_matched_indices[:g:clap.display.line_count()-1]

if g:clap.provider.id ==# 'tags' && get(g:, 'vista#renderer#enable_icon', 0)
let offset = 2
else
let offset = 0
endif

let lnum = 0

for indices in hl_lines
let group_idx = 1
for idx in indices
if group_idx < g:__clap_fuzzy_matches_hl_group_cnt + 1
call clap#util#add_highlight_at(lnum, idx, 'ClapFuzzyMatches'.group_idx)
call clap#util#add_highlight_at(lnum, idx+offset, 'ClapFuzzyMatches'.group_idx)
let group_idx += 1
else
call clap#util#add_highlight_at(lnum, idx, 'ClapMatches')
call clap#util#add_highlight_at(lnum, idx+offset, 'ClapMatches')
endif
endfor
let lnum += 1
Expand Down
14 changes: 7 additions & 7 deletions pythonx/clap/fzy_impl.py
Expand Up @@ -59,7 +59,7 @@ def subsequence(niddle, haystack):
"""
niddle, haystack = niddle.lower(), haystack.lower()
if not niddle:
True
return True
offset = 0
for char in niddle:
offset = haystack.find(char, offset) + 1
Expand Down Expand Up @@ -128,9 +128,9 @@ def positions(niddle, haystack):
while i >= 0:
while j >= 0:
if (match_required or D[i][j] == M[i][j]) and D[i][j] != SCORE_MIN:
match_required = (i > 0 and j > 0
and M[i][j] == D[i - 1][j - 1] +
SCORE_MATCH_CONSECUTIVE)
match_required = (
i > 0 and j > 0
and M[i][j] == D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE)
positions[i] = j
j -= 1
break
Expand Down Expand Up @@ -179,9 +179,9 @@ def score(niddle, haystack):
while i >= 0:
while j >= 0:
if (match_required or D[i][j] == M[i][j]) and D[i][j] != SCORE_MIN:
match_required = (i > 0 and j > 0
and M[i][j] == D[i - 1][j - 1] +
SCORE_MATCH_CONSECUTIVE)
match_required = (
i > 0 and j > 0
and M[i][j] == D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE)
positions[i] = j
j -= 1
break
Expand Down

0 comments on commit 820980f

Please sign in to comment.