Fixed bug that cursor reset when after TaskWikiBufferSave/Load

This commit is contained in:
daizeng1984 2017-06-13 19:56:15 +08:00 committed by Tomas Babej
parent 406041c868
commit 75305ed33f
2 changed files with 15 additions and 0 deletions

12
taskwiki/decorators.py Normal file
View file

@ -0,0 +1,12 @@
import vim # pylint: disable=F0401
def hold_vim_cursor(original_function):
"""
Decorator that wrap around to save cursor position and restore it
"""
def wrapped_function(*args, **kwargs):
vim.command('let save_pos = getpos(".")')
original_function(*args, **kwargs)
vim.command('call setpos(".", save_pos)')
return wrapped_function

View file

@ -16,6 +16,7 @@ from taskwiki import cache as cache_module
from taskwiki import sort
from taskwiki import util
from taskwiki import viewport
from taskwiki import decorators
cache = cache_module.CacheRegistry()
@ -25,6 +26,7 @@ cache.load_current()
class WholeBuffer(object):
@staticmethod
@errors.pretty_exception_handler
@decorators.hold_vim_cursor
def update_from_tw():
"""
Updates all the incomplete tasks in the vimwiki file if the info from TW is different.
@ -42,6 +44,7 @@ class WholeBuffer(object):
@staticmethod
@errors.pretty_exception_handler
@decorators.hold_vim_cursor
def update_to_tw():
"""
Updates all tasks that differ from their TaskWarrior representation.