diff --git a/taskwiki/cache.py b/taskwiki/cache.py index ab98e0d..5cc2c73 100644 --- a/taskwiki/cache.py +++ b/taskwiki/cache.py @@ -22,10 +22,12 @@ class BufferProxy(object): def push(self): with util.current_line_preserved(): + buffer = util.get_buffer(self.buffer_number) # Only set the buffer contents if the data is changed. # Avoids extra undo events with empty diff. - if util.get_buffer(self.buffer_number)[:] != self.data: - util.get_buffer(self.buffer_number)[:] = self.data + if buffer[:] != self.data: + buffer[:] = self.data + buffer.options['modified'] = True def __getitem__(self, index): try: diff --git a/tests/test_viewport.py b/tests/test_viewport.py index 1dcdd9f..d3b440a 100644 --- a/tests/test_viewport.py +++ b/tests/test_viewport.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import os from datetime import datetime from tests.base import MultiSyntaxIntegrationTest @@ -614,3 +615,31 @@ class TestViewportDefaultPreservesTags(MultiSyntaxIntegrationTest): assert task['description'] == 'hard task' assert task['status'] == 'pending' assert task['tags'] == set(['work', 'hard']) + + +class TestViewportBufferModified(MultiSyntaxIntegrationTest): + + viminput = """ + HEADER2(Work tasks |) + * [ ] a task #{uuid} + """ + + tasks = [ + dict(description="a task", tags=['work']), + ] + + def execute(self): + testfile2 = os.path.join(self.dir, "testwiki2.txt") + testfile3 = os.path.join(self.dir, "testwiki3.txt") + + self.command("w", regex="written$", lines=1) + self.command("w {}".format(testfile2), regex="written$", lines=1) + self.command("1w {}".format(testfile3), regex="written$", lines=1) + + # testfile2 has the task, so refresh on open shouldn't change anything + self.client.edit(testfile2) + assert self.client.eval('&modified') == '0' + + # testfile3 only has header, so refresh on open makes changes + self.client.edit(testfile3) + assert self.client.eval('&modified') == '1'