Skip to content

Commit fbe56fa

Browse files
committed
Fixes the multiple items toggling (#5)
The fact that VimTodoListsToggleItem is called a number of times equal to number of lines in range caused the issue of multiple times toggling the items in range. The solution is to remove range traversal unnecessary in the VimTodoListsToggleItem() function.
1 parent bab7495 commit fbe56fa

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

plugin/vim-todo-lists.vim

+11-12
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function! VimTodoListsSetItemMode()
6363
nnoremap <buffer> j :VimTodoListsGoToNextItem<CR>
6464
nnoremap <buffer> k :VimTodoListsGoToPreviousItem<CR>
6565
nnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
66-
vnoremap <buffer> <Space> :'<,'>VimTodoListsToggleItem<CR>
66+
vnoremap <buffer> <Space> :VimTodoListsToggleItem<CR>
6767
inoremap <buffer> <CR> <CR><ESC>:VimTodoListsCreateNewItem<CR>
6868
noremap <buffer> <leader>e :silent call VimTodoListsSetNormalMode()<CR>
6969
endfunction
@@ -110,17 +110,16 @@ function! VimTodoListsGoToPreviousItem()
110110
endfunction
111111

112112

113-
" Toggles todo items in specified range
114-
function! VimTodoListsToggleItemsRange()
115-
for lineno in range (a:firstline, a:lastline)
116-
let l:line = getline(lineno)
113+
" Toggles todo list item
114+
function! VimTodoListsToggleItem()
115+
let l:line = getline('.')
116+
117+
if match(l:line, '^\s*\[ \].*') != -1
118+
call setline('.', substitute(l:line, '^\(\s*\)\[ \]', '\1[X]', ''))
119+
elseif match(l:line, '^\s*\[X\] .*') != -1
120+
call setline('.', substitute(l:line, '^\(\s*\)\[X\]', '\1[ ]', ''))
121+
endif
117122

118-
if match(l:line, '^\s*\[ \].*') != -1
119-
call setline(lineno, substitute(l:line, '^\(\s*\)\[ \]', '\1[X]', ''))
120-
elseif match(l:line, '^\s*\[X\] .*') != -1
121-
call setline(lineno, substitute(l:line, '^\(\s*\)\[X\]', '\1[ ]', ''))
122-
endif
123-
endfor
124123
endfunction
125124

126125

@@ -145,6 +144,6 @@ if !exists('g:vimtodolists_plugin')
145144
command! VimTodoListsCreateNewItem silent call VimTodoListsCreateNewItem()
146145
command! VimTodoListsGoToNextItem silent call VimTodoListsGoToNextItem()
147146
command! VimTodoListsGoToPreviousItem silent call VimTodoListsGoToPreviousItem()
148-
command! -range VimTodoListsToggleItem silent <line1>,<line2>call VimTodoListsToggleItemsRange()
147+
command! -range VimTodoListsToggleItem silent <line1>,<line2>call VimTodoListsToggleItem()
149148
endif
150149

0 commit comments

Comments
 (0)