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:
Activate the view you want to clone.
Send the clone_file command to the window.
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.
When using
close_view
orclose_window
withforce=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
andclose_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:clone_file
command to the window.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.