diff --git a/plugin/worklist.vim b/plugin/worklist.vim index bf59ae1..0942b89 100644 --- a/plugin/worklist.vim +++ b/plugin/worklist.vim @@ -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() @@ -262,14 +282,30 @@ 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 @@ -277,7 +313,17 @@ 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