diff --git a/doc/taskwiki.txt b/doc/taskwiki.txt index 81a8ed53e..1dd209d8b 100644 --- a/doc/taskwiki.txt +++ b/doc/taskwiki.txt @@ -767,6 +767,15 @@ constructs. Example: let g:taskwiki_maplocalleader=",t" +*taskwiki_scan_for_duplicates* + If set to a non-empty value (such as "yes"), taskwiki will force-scan the + current file for other mentions of the task being processed and update + them too. This is useful if you have multiple overlapping viewports. If + you edit a task that appears in several of these viewports (e.g. mark it + as done) and save the file, the non-updated mentions of the task may undo + your edits. This option is disabled by default as it will add some + overhead to simple operations that you perform on selected tasks. + ============================================================================= 9. TROUBLESHOOTING *taskwiki-trouble* diff --git a/taskwiki/cache.py b/taskwiki/cache.py index 59892480d..1cbc3f98a 100644 --- a/taskwiki/cache.py +++ b/taskwiki/cache.py @@ -313,3 +313,6 @@ def get_relevant_tw(self): def get_relevant_completion(self): return self.completion[self.get_relevant_tw()] + + def get_task_replications(self, uuid): + return [vwtask for vwtask in self.vwtask.values() if vwtask and vwtask.uuid == uuid] diff --git a/taskwiki/main.py b/taskwiki/main.py index 2a8716f24..9d30f4630 100644 --- a/taskwiki/main.py +++ b/taskwiki/main.py @@ -79,6 +79,10 @@ def __init__(self): self.tw = cache().get_relevant_tw() # Load the current tasks + if util.get_var('taskwiki_scan_for_duplicates'): + for i in range(len(cache().buffer)): + cache().vwtask[i] # loads the line into the cache + range_tasks = [cache().vwtask[i] for i in util.selected_line_numbers()] self.tasks = [t for t in range_tasks if t is not None] @@ -114,6 +118,8 @@ def done(self): vimwikitask.update_in_buffer() print(u"Task \"{0}\" completed.".format(vimwikitask['description'])) + self._update_replications() + cache().buffer.push() self.save_action('done') @@ -277,6 +283,14 @@ def sort(self, sortstring): sort.TaskSorter(cache(), self.tasks, sortstring).execute() cache().buffer.push() + def _update_replications(self): + """Update all same tasks occurrences in current buffer from taskwarrior.""" + + for vimwikitask in self.tasks: + for replica in cache().get_task_replications(vimwikitask.uuid): + replica.update_from_task() + replica.update_in_buffer() + class Mappings(object):