Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 55 additions & 9 deletions plugin/worklist.vim
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,26 @@ function! s:Note(note='') abort
endfunction


" Wrap text to a list of lines, each no wider than `width` display columns
function! s:WrapText(text, width) abort
let lines = []
for line in split(a:text, '\n', 1)
if strdisplaywidth(line) <= a:width
call add(lines, line)
else
while strdisplaywidth(line) > a:width
call add(lines, strcharpart(line, 0, a:width))
let line = strcharpart(line, a:width)
endwhile
if !empty(line)
call add(lines, line)
endif
endif
endfor
return empty(lines) ? [''] : lines
endfunction


" Show a popup with the note for the current worklist item
function! s:ShowNotePopup(force=v:false) abort
if s:IsCurrentQuickfix()
Expand All @@ -262,22 +282,48 @@ function! s:ShowNotePopup(force=v:false) abort

let item = s:worklist[index]
if !empty(get(item, 'note', ''))
let s:notewinid = popup_atcursor(item.note, {
\ 'border': [1, 1, 1, 1],
\ 'borderchars': [' '],
\ 'moved': [index + 1, 0, 999],
\ 'maxwidth': g:worklist_popup_maxwidth,
\ })
call setwinvar(s:notewinid, '&showbreak', 'NONE')
call setwinvar(s:notewinid, '&linebreak', 1)
if has('nvim')
let lines = s:WrapText(item.note, g:worklist_popup_maxwidth)
let width = max(map(copy(lines), 'strdisplaywidth(v:val)'))
let buf = nvim_create_buf(v:false, v:true)
call nvim_buf_set_lines(buf, 0, -1, v:true, lines)
let s:notewinid = nvim_open_win(buf, v:false, {
\ 'relative': 'cursor',
\ 'row': 1,
\ 'col': 0,
\ 'width': max([width, 1]),
\ 'height': len(lines),
\ 'style': 'minimal',
\ 'border': 'single',
\ })
else
let s:notewinid = popup_atcursor(item.note, {
\ 'border': [1, 1, 1, 1],
\ 'borderchars': [' '],
\ 'moved': [index + 1, 0, 999],
\ 'maxwidth': g:worklist_popup_maxwidth,
\ })
call setwinvar(s:notewinid, '&showbreak', 'NONE')
call setwinvar(s:notewinid, '&linebreak', 1)
endif
endif
endif
endfunction


" Close the note popup
function! s:CloseNotePopup() abort
call popup_close(s:notewinid)
if has('nvim')
if s:notewinid != -1
try
call nvim_win_close(s:notewinid, v:true)
catch
endtry
let s:notewinid = -1
endif
else
call popup_close(s:notewinid)
endif
endfunction


Expand Down