From cf9ea1d8facd1c9ae0612f9b188bb2b97ae56816 Mon Sep 17 00:00:00 2001 From: Kim K Date: Mon, 18 Nov 2019 22:42:17 +0800 Subject: [PATCH] fix(#58): Change logic for jump_forward() and jump_backward() to fix conflict with vim-cool --- autoload/doge/comment.vim | 40 +++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/autoload/doge/comment.vim b/autoload/doge/comment.vim index e6095fdd..12c8ab0a 100644 --- a/autoload/doge/comment.vim +++ b/autoload/doge/comment.vim @@ -5,29 +5,33 @@ let s:comment_placeholder = doge#helpers#placeholder() " vint: next-line -ProhibitUnusedVariable function! s:jump_forward() abort - let l:next_pos = search(s:comment_placeholder, 'nW') + let @/ = s:comment_placeholder + let l:next_pos = searchpos(s:comment_placeholder, 'nW') + let l:cpos = getpos('.') + let l:cpos[1] = l:next_pos[0] + let l:cpos[2] = l:next_pos[1] - if (l:next_pos > b:doge_interactive['lnum_comment_end_pos'] || l:next_pos == 0) + if (l:next_pos[0] > b:doge_interactive['lnum_comment_end_pos'] || l:next_pos[0] == 0) \ && g:doge_comment_jump_wrap == v:true " If we have more TODO items below the comment or we are at the last TODO " inside the comment, then we'll go backward to the start position of the " comment so we can continue to cycle. - return "\:" . b:doge_interactive['lnum_comment_start_pos'] . "\^/" . s:comment_placeholder . "\:silent! noh\gno\" + return "\:" . b:doge_interactive['lnum_comment_start_pos'] . "\^:call search('" . s:comment_placeholder . "')\gno\" endif " Check if the next pos we want to jump to is still inside the comment. - if l:next_pos != 0 && l:next_pos <= b:doge_interactive['lnum_comment_end_pos'] + if l:next_pos[0] != 0 && l:next_pos[0] <= b:doge_interactive['lnum_comment_end_pos'] if mode() ==# 'i' - return "\/" . s:comment_placeholder . "\\:silent! noh\\gno\" + return "\:call setpos('.', " . string(l:cpos) . ")\\gno\" elseif mode() ==# 's' - return "\/" . s:comment_placeholder . "\:silent! noh\gno\" + return "\:call setpos('.', " . string(l:cpos) . ")\gno\" elseif mode() ==# 'n' - return '/' . s:comment_placeholder . "\:silent! noh\gno\" + return ":call setpos('.', " . string(l:cpos) . ")\gno\" else return "viw\" endif elseif expand('') ==# s:comment_placeholder && mode() ==# 'i' - return "\viw\" + return "\viw\" endif " No more next TODOs found. @@ -36,29 +40,33 @@ endfunction " vint: next-line -ProhibitUnusedVariable function! s:jump_backward() abort - let l:prev_pos = search(s:comment_placeholder, 'bnW') + let @/ = s:comment_placeholder + let l:prev_pos = searchpos(s:comment_placeholder, 'bnW') + let l:cpos = getpos('.') + let l:cpos[1] = l:prev_pos[0] + let l:cpos[2] = l:prev_pos[1] - if (l:prev_pos < b:doge_interactive['lnum_comment_start_pos'] || l:prev_pos == 0) + if (l:prev_pos[0] < b:doge_interactive['lnum_comment_start_pos'] || l:prev_pos[0] == 0) \ && g:doge_comment_jump_wrap == v:true " If we have more TODO items above the comment or we are at the first TODO " inside the comment, then we'll go forward to the end position of the " comment so we can continue to cycle. - return "\:" . b:doge_interactive['lnum_comment_end_pos'] . "\$?" . s:comment_placeholder . "\:silent! noh\gno\" + return "\:" . b:doge_interactive['lnum_comment_end_pos'] . "\$:call search('" . s:comment_placeholder . "', 'b')\gno\" endif " Check if the prev pos we want to jump to is still inside the comment. - if l:prev_pos != 0 && l:prev_pos >= b:doge_interactive['lnum_comment_start_pos'] + if l:prev_pos[0] != 0 && l:prev_pos[0] >= b:doge_interactive['lnum_comment_start_pos'] if mode() ==# 'i' - return "\?" . s:comment_placeholder . "\\:silent! noh\\gno\" + return "\:call setpos('.', " . string(l:cpos) . ")\\gNo\" elseif mode() ==# 's' - return "\?" . s:comment_placeholder . "\:silent! noh\gno\" + return "\:call setpos('.', " . string(l:cpos) . ")\gno\" elseif mode() ==# 'n' - return '?' . s:comment_placeholder . "\:silent! noh\gno\" + return ":call setpos('.', " . string(l:cpos) . ")\gno\" else return "viW\" endif elseif expand('') ==# s:comment_placeholder && mode() ==# 'i' - return "\viw\" + return "\viw\" endif " No more previous TODOs found.