diff --git a/autoload/traqvim.vim b/autoload/traqvim.vim index 8071716..51cee8e 100644 --- a/autoload/traqvim.vim +++ b/autoload/traqvim.vim @@ -315,6 +315,27 @@ function traqvim#deleteMessage(t) abort call denops#request('traqvim', 'messageDelete', [bufnr(), messageStart]) endfunction +function traqvim#registerTogglePin() abort + let &opfunc = function('traqvim#togglePin') + return 'g@' +endfunction + +function traqvim#togglePin(t) abort + if a:t != 'line' + return + endif + let messageStart = traqvim#get_message_buf(line("'["), bufnr('%')) + let messageEnd = traqvim#get_message_buf(line("']"), bufnr('%')) + if messageStart->get('id') != messageEnd->get('id') + return + endif + if messageStart->get('pinned') + call denops#request('traqvim', 'removePin', [bufnr(), messageStart]) + else + call denops#request('traqvim', 'createPin', [bufnr(), messageStart]) + endif +endfunction + function traqvim#message_motion() abort let position = traqvim#get_message()->get('position') call cursor(position->get('start'), 1) diff --git a/ftplugin/traqvim.vim b/ftplugin/traqvim.vim index 65d4d70..66b6967 100644 --- a/ftplugin/traqvim.vim +++ b/ftplugin/traqvim.vim @@ -19,6 +19,8 @@ nnoremap (traqvim-yank-message-markdown-operator) \ traqvim#registerYankMessageMarkdown() nnoremap (traqvim-delete-message-operator) \ traqvim#registerDeleteMessage() +nnoremap (traqvim-toggle-pin-operator) + \ traqvim#registerTogglePin() onoremap (traqvim-message-motion) \ :call traqvim#message_motion() @@ -35,6 +37,9 @@ nmap Y nmap d \ (traqvim-delete-message-operator) +nmap p + \ (traqvim-toggle-pin-operator) + command! -buffer -nargs=0 TraqYankMessageLink \ call denops#request('traqvim', 'yankMessageLink', [traqvim#get_message()]) command! -buffer -nargs=0 TraqYankMessageMarkdown