+1

Save on view leave dirty marker even if is_dirty is false

Rodrigue Cloutier 12 jaar geleden 0

The following plugin will create a new file, open the new file, write to it and then save. Even though the file is marked as not dirty, the tab indicate that it is dirty and trying to close the file prompt the save dialog.


import sublime, sublime_plugin
target = None
def insert_world(view):
    edit = view.begin_edit()
    view.insert(edit, 0, "Hello world!")
    view.end_edit(edit)
    view.run_command('save')
    print view.is_dirty() # print False
class SaveStillDirtyBugListener(sublime_plugin.EventListener):
    def on_load(self, view):
        global target
        if target is None:
            return
        if view.file_name() == target.file_name():
            insert_world(view)
            target = None
class SaveStillDirtyBugCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        with open('test', 'w+') as test:
            test.close()
        view = self.view.window().open_file('test')
        if view.is_loading():
            global target
            target = view
        else:
            insert_world(view)