mirror of
https://github.com/tbabej/taskwiki.git
synced 2025-08-19 06:43:06 +02:00
cache: Mark buffer as modified on push
When a (task)wiki file is opened, viewports are refreshed but the buffer is not marked as modified and therefore a subsequent :xa doesn't update the file. This is, IMO, undesired. vim documentation for the 'modified' option: This option is not set when a change is made to the buffer as the result of a BufNewFile, BufRead/BufReadPost, BufWritePost, FileAppendPost or VimLeave autocommand event. See |gzip-example| for an explanation.
This commit is contained in:
parent
1e3ccb16f8
commit
d66a7b5b94
2 changed files with 33 additions and 2 deletions
|
@ -22,10 +22,12 @@ class BufferProxy(object):
|
||||||
|
|
||||||
def push(self):
|
def push(self):
|
||||||
with util.current_line_preserved():
|
with util.current_line_preserved():
|
||||||
|
buffer = util.get_buffer(self.buffer_number)
|
||||||
# Only set the buffer contents if the data is changed.
|
# Only set the buffer contents if the data is changed.
|
||||||
# Avoids extra undo events with empty diff.
|
# Avoids extra undo events with empty diff.
|
||||||
if util.get_buffer(self.buffer_number)[:] != self.data:
|
if buffer[:] != self.data:
|
||||||
util.get_buffer(self.buffer_number)[:] = self.data
|
buffer[:] = self.data
|
||||||
|
buffer.options['modified'] = True
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from tests.base import MultiSyntaxIntegrationTest
|
from tests.base import MultiSyntaxIntegrationTest
|
||||||
|
|
||||||
|
@ -614,3 +615,31 @@ class TestViewportDefaultPreservesTags(MultiSyntaxIntegrationTest):
|
||||||
assert task['description'] == 'hard task'
|
assert task['description'] == 'hard task'
|
||||||
assert task['status'] == 'pending'
|
assert task['status'] == 'pending'
|
||||||
assert task['tags'] == set(['work', 'hard'])
|
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'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue