SublimeANSI icon indicating copy to clipboard operation
SublimeANSI copied to clipboard

File change on disk causes jumbled content and unfixable state

Open tdhsmith opened this issue 9 years ago • 8 comments

First thanks for the plugin! :+1: I really appreciate being able to read colored log files in the same workflow as my regular editing/etc.

In my current use, I frequently leave a tab open with a log file at all times. But when the file changes on the disk and gets reloaded, the changes jumble up the content and get it into an invalid state that can't be fixed by toggling in/out of ANSI mode. (Closing and reopening the tab works, of course)

Is there an event you can tie into before a reload to revert the style? That's the first solution that comes to my mind, but I know from my limited plugin development that the Sublime API can leave a lot to be desired... If you can't detect reloads, this is way more challenging and probably not worth it, haha.

tdhsmith avatar Nov 06 '15 17:11 tdhsmith

Hi, excellent job indeed, using it everyday! Witnessing the same bug here with the same conditions (log file always open in background)

nchaverou avatar Feb 13 '16 19:02 nchaverou

@tdhsmith @nchaverou Are you guys still able to reproduce this issue?

matt1003 avatar Mar 16 '16 01:03 matt1003

To reproduce it:

  1. Open "ansi_test_file.txt" in sublime
  2. Set ANSI sytax
  3. Open the same file in other editor, add some spaces and save

I couldn't find how to detect file reloading. Any idea?

jakkubu avatar Apr 14 '16 23:04 jakkubu

This is a horribly broken hack, but it was the best I could come up with for detecting a file reload:

class AnsiEventListener(sublime_plugin.EventListener):

    def on_activated(self, view):
        if view.settings().has("ansi_enabled"):
            if view.is_loading():
                sublime.message_dialog("Shit just hit the fan!")

Maybe someone else can come up with something better.

matt1003 avatar Apr 15 '16 06:04 matt1003

Another hack, this time based on trying to detect a change in the file's size:

class AnsiEventListener(sublime_plugin.EventListener):

    def on_activated(self, view):
        if view.settings().has("ansi_enabled"):
            if view.settings().get("ansi_size") != view.size():
                view.settings().set("ansi_size", view.size())
                sublime.message_dialog("Shit just hit the fan!")

This could be a possible solution for log files.

matt1003 avatar Apr 15 '16 11:04 matt1003

on_activated works only if view is in focus. I just finished patch for this issue using periodic callbacks and checking if there are any ansi codes in view.

jakkubu avatar Apr 15 '16 11:04 jakkubu

I just find out, that reloading file fires view.settings() on_change, however it doesn't find new ansi codes immediately after. We can add sublime.set_timeout_async and then look for ANSI codes. What do you think?

jakkubu avatar Apr 16 '16 18:04 jakkubu

Hey, that's not a bad idea! You should probably also use view.is_loaded() in combination with the sublime.set_timeout_async callback. I did like you solution with the periodic callback function, but this would be a much better solution.

matt1003 avatar Apr 17 '16 10:04 matt1003