Sublime Forum

How to close split/clone views in ST4?

#1

I have been staying on Sublime Text 3 for a long time. My main upgrade blocker was “New View into File” which is a feature I use many times a day, but in Sublime Text 4 was replaced with a “Split View” feature which is not what I want. I discovered I can add “New View into File” back using a custom menu item:

Good, perfect. So now I am trying to upgrade to ST4, but when I test my menu item I find something strange. If I (1) open a second view into the file, then (2) attempt to close it, I get a “do you want to save?” dialog

This is weird and unwelcome friction and does not make sense because I am not closing the file. I am just closing one duplicate view into the file. This problem is not caused by the custom clone_view action. If instead of using “New view into file” I select “Split view” and then immediately attempt to close my split view copy, it also asks if I want to save.

I feel I must be missing something because if creating a split view means you now have a duplicate you cannot remove without performing a destructive operation (saving) then the “Split view” feature seems to broken in its shipped state. How do I close a duplicate split/clone view?

I find other people have asked about this but did not get responses. This is by itself holding me back from buying an ST4 license

0 Likes

#2

I agree that it is annoying, but https://github.com/sublimehq/sublime_text/issues/1879 indicates that this behavior was the same since at least ST3.

Afaik “Split View” is exactly the same as “New View into File”, just with a different name.

0 Likes

#3

I have a copy of Sublime 3.2.2 running right this second and I promise, somehow or other this behavior is not present there (tested on Windows 10, MacOS high sierra). This is awkward because it means I can avoid the bug by simply not upgrading.

I agree split view behaves the same as “new view” in this regard.

0 Likes

#4

A vanilla install of ST 3221 on macOS Monterey 12.6.2 displays exactly the same behaviour as ST4132.
If I File > New view into file then modify one view, closing either view prompts a save dialog in the same way that File > Split View does.

Do you have any user settings or packages that could be modifying the default behaviour of ST 3.2.2?

0 Likes

#5

Doing more rigorous tests I am able to replicate the behavior in ST3. I think the reason I didn’t believe ST3 had it was I was testing ST4 more carefully. That’s embarrassing! D:

I still do wish the behavior was otherwise, but I guess this is no longer an impediment to upgrading :confused:

0 Likes

#6

You could make a command to close cloned views without saving, and assign a key mapping.
While the buffer is marked as scratch ST will not prompt to save on close.

import sublime_plugin

class NoNagCloseCommand(sublime_plugin.WindowCommand):
    def run(self):
        view = self.window.active_view()

        if view.is_primary():
            return

        pv = view.buffer().primary_view()

        # Sublime will not prompt to save if a buffer is marked as scratch
        pv.set_scratch(True)
        view.close()
        pv.set_scratch(False)

NoNag.sublime-commands

[
  { "caption": "NoNag: Close Cloned View",
    "command": "no_nag_close" }
]
0 Likes

#7

That’s very helpful, thank you so much.

0 Likes

#8

No problem.
I’ve put the code on GitHub.

0 Likes

#9

After PackageControl, I consider Origami the next most necessary plugin, and MaxPane is the third. Unlike the built in commands that create a new unsaved file when you use Split View, Origami allows you to open another view of the same file in some other pane (within the same ST window). If you close that file in one pane, you’re just closing that view of the file, you’re not actually closing the file until you close the last view of that file. I typically have two groups in every ST window with a top and bottom layout and then when I need to see more of a single file, I use a MaxPane command to maximize that one pane and then I can use that command again to restore back to the top/bottom layout.

0 Likes