Skip to content

Commit 9bf9635

Browse files
aserebryakovAlexanderS-Vayyar
authored andcommitted
Fixes the cursor position after item toggling (#12)
1 parent cfeed13 commit 9bf9635

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ Changelog
166166
#### 0.5.1
167167

168168
* Fixed the annoying noise when navigating over items in default mode
169+
* Fixed the cursor position after the item is toggled
169170

170171
Credits
171172
-------

doc/vim-todo-lists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim-todo-lists.txt* Version 0.4.0
1+
*vim-todo-lists.txt* Version 0.5.1
22
*vim-todo-lists*
33

44
Plugin for TODO lists management.
@@ -199,6 +199,7 @@ SOFTWARE.
199199
0.5.1
200200

201201
* Fixed the annoying noise when navigating over items in default mode
202+
* Fixed the cursor position after the item is toggled
202203

203204
==============================================================================
204205
8. Credits *VimTodoListsCredits*

plugin/vim-todo-lists.vim

+10-6
Original file line numberDiff line numberDiff line change
@@ -217,21 +217,21 @@ function! VimTodoListsCreateNewItemAbove()
217217
endfunction
218218

219219

220-
" Creates e new item below the current line
220+
" Creates a new item below the current line
221221
function! VimTodoListsCreateNewItemBelow()
222222
normal! o [ ]
223223
startinsert!
224224
endfunction
225225

226226

227-
" Creates e new item in the current line
227+
" Creates a new item in the current line
228228
function! VimTodoListsCreateNewItem()
229229
normal! 0i [ ]
230230
startinsert!
231231
endfunction
232232

233233

234-
" Moves te cursor to the next item
234+
" Moves the cursor to the next item
235235
function! VimTodoListsGoToNextItem()
236236
normal! $
237237
silent! exec '/^\s*\[.\]'
@@ -240,7 +240,7 @@ function! VimTodoListsGoToNextItem()
240240
endfunction
241241

242242

243-
" Moves te cursor to the previous item
243+
" Moves the cursor to the previous item
244244
function! VimTodoListsGoToPreviousItem()
245245
normal! 0
246246
silent! exec '?^\s*\[.\]'
@@ -253,14 +253,18 @@ endfunction
253253
function! VimTodoListsToggleItem()
254254
let l:line = getline('.')
255255

256+
" Store current cursor position
257+
let l:cursor_pos = getcurpos()
258+
256259
if VimTodoListsItemIsNotDone(l:line) == 1
257260
call VimTodoListsForEachChild(line('.'), 'VimTodoListsSetItemDone')
258261
elseif VimTodoListsItemIsDone(l:line) == 1
259262
call VimTodoListsForEachChild(line('.'), 'VimTodoListsSetItemNotDone')
260263
endif
261264

262-
" Restore the cursor position
263-
normal! f[l
265+
" Restore the current position
266+
" Using the {curswant} value to set the proper column
267+
call cursor(l:cursor_pos[1], l:cursor_pos[4])
264268

265269
call VimTodoListsUpdateParent(line('.'))
266270
endfunction

0 commit comments

Comments
 (0)