Skip to content

Commit e23d1bb

Browse files
committed
Highlight the header line for loclist provider
Also move impl.vim to impl/on_typed.vim
1 parent 86169c6 commit e23d1bb

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

autoload/clap.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function! s:inject_default_impl_is_ok(provider_info) abort
101101
" If sync provider
102102
if has_key(provider_info, 'source')
103103
if !has_key(provider_info, 'on_typed')
104-
let provider_info.on_typed = function('clap#impl#on_typed')
104+
let provider_info.on_typed = function('clap#impl#on_typed#')
105105
endif
106106
if !has_key(provider_info, 'filter')
107107
let provider_info.filter = function('clap#filter#sync')
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
" Author: liuchengxu <[email protected]>
2-
" Description: Default implementation for various hooks.
2+
" Description: Default implementation for on_typed hook.
33

44
let s:save_cpo = &cpoptions
55
set cpoptions&vim
@@ -182,7 +182,7 @@ endfunction
182182
" \
183183
" \
184184
" on_move
185-
function! clap#impl#on_typed() abort
185+
function! clap#impl#on_typed#() abort
186186
" If user explicitly uses the external filter, just use the async impl then,
187187
" even the forerunner job is finished already.
188188
if clap#api#has_externalfilter()

autoload/clap/preview.vim

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,33 @@ endfunction
159159

160160
if has('nvim')
161161
let s:header_ns_id = nvim_create_namespace('clap_preview_header')
162+
163+
" lnum is 1-based.
164+
function! s:add_highlight_at(lnum) abort
165+
if nvim_buf_is_valid(g:clap.preview.bufnr)
166+
call nvim_buf_add_highlight(g:clap.preview.bufnr, s:header_ns_id, 'Title', a:lnum - 1, 0, -1)
167+
endif
168+
endfunction
169+
162170
" Sometimes the first line of preview window is used for the header.
163171
function! clap#preview#highlight_header() abort
164-
" try
165-
" let winid = win_getid()
166-
" Do not use matchaddpos() as it needs to be executed in that window.
167-
" call g:clap.preview.goto_win()
168-
" call s:highlight_header()
169-
if nvim_buf_is_valid(g:clap.preview.bufnr)
170-
call nvim_buf_add_highlight(g:clap.preview.bufnr, s:header_ns_id, 'Title', 0, 0, -1)
171-
endif
172-
" finally
173-
" noautocmd call win_gotoid(winid)
174-
" endtry
172+
call s:add_highlight_at(1)
175173
endfunction
176174

177175
function! clap#preview#clear_header_highlight() abort
178176
call nvim_buf_clear_namespace(g:clap.preview.bufnr, s:header_ns_id, 0, -1)
179177
endfunction
180178
else
181-
function! s:highlight_header() abort
179+
function! s:add_highlight_at(lnum) abort
182180
if !exists('w:preview_header_id')
183-
let w:preview_header_id = matchaddpos('Title', [1])
181+
let w:preview_header_id = matchaddpos('Title', [a:lnum])
184182
endif
185183
endfunction
186184

185+
function! s:highlight_header() abort
186+
call s:add_highlight_at(1)
187+
endfunction
188+
187189
function! s:clear_header_highlight() abort
188190
if exists('w:preview_header_id')
189191
call matchdelete(w:preview_header_id)

autoload/clap/provider/loclist.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function! s:loclist.on_move() abort
5353
let locitem = locations[str2nr(s:locline2idx[curline])]
5454

5555
let lines = []
56-
call add(lines, '--> '.bufname(locitem.bufnr).':'.locitem.lnum.':'.locitem.col)
56+
call add(lines, bufname(locitem.bufnr).':'.locitem.lnum.':'.locitem.col)
5757

5858
if locitem.lnum !=# ''
5959
let line = getbufline(locitem.bufnr, str2nr(locitem.lnum))
@@ -77,6 +77,7 @@ function! s:loclist.on_move() abort
7777

7878
call g:clap.preview.show(lines)
7979
call g:clap.preview.setbufvar('&syntax', getbufvar(locitem.bufnr, '&syntax'))
80+
call clap#preview#highlight_header()
8081
endfunction
8182

8283
let s:loclist.syntax = 'qf'

0 commit comments

Comments
 (0)