From 75305ed33f637447138f5775ffdaea45d7303e40 Mon Sep 17 00:00:00 2001 From: daizeng1984 Date: Tue, 13 Jun 2017 19:56:15 +0800 Subject: [PATCH] Fixed bug that cursor reset when after TaskWikiBufferSave/Load --- taskwiki/decorators.py | 12 ++++++++++++ taskwiki/main.py | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 taskwiki/decorators.py diff --git a/taskwiki/decorators.py b/taskwiki/decorators.py new file mode 100644 index 0000000..70acd15 --- /dev/null +++ b/taskwiki/decorators.py @@ -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 diff --git a/taskwiki/main.py b/taskwiki/main.py index 058a1d3..f791a51 100644 --- a/taskwiki/main.py +++ b/taskwiki/main.py @@ -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.