SublimeText / sublime_lib

Utility library for frequently used functionality in Sublime Text and convenience functions or classes
https://sublimetext.github.io/sublime_lib
MIT License
52 stars 4 forks source link

Possible data loss bug in close_view and close_window, plus new clone_view #147

Closed Thom1729 closed 3 years ago

Thom1729 commented 3 years ago

When using close_view or close_window with force=True, when a view is dirty and not scratch, the function will make the view scratch before closing it. But because scratchness is a buffer property, if there were other clones of that view, they will also be made scratch after the function is done. This could indirectly result in data loss.

The remedy is to keep track of what buffers close_view and close_window set to scratch and revert them afterward. I think that the original behavior is a bug, and the change in behavior is justified as a fix.

Anyway, when testing this, we need to create our own cloned views. Apparently the API doesn't provide anything like view.clone() — you have to:

  1. Activate the view you want to clone.
  2. Send the clone_file command to the window.
  3. Return the active view.

This seems overcomplicated and (possibly) prone to race conditions. I wonder if there's a better way to do it. I also wonder whether a function that does it whatever way is best would be a good sublime_lib feature. See https://github.com/sublimehq/sublime_text/issues/3963.