Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

On "core:close" (ctrl/cmd-w), closes window if no files/panes left to close - #2411

Closed
jingchan wants to merge 1 commit into
atom:masterfrom
jingchan:master
Closed

jingchan wants to merge 1 commit into
atom:masterfrom
jingchan:master

Conversation

@jingchan

Copy link
Copy Markdown

Fixes #863

@probablycorey

Copy link
Copy Markdown

Thanks @jingchan, could you write some specs to cover this change.

I may be alone, but I consider not closing the window with cmd-w a feature. So I'd like a config option that keeps that functionality.

@benogle

benogle commented May 27, 2014

Copy link
Copy Markdown
Contributor

I agree with @probablycorey. I like that I can mash core close and not
close the window. I have 'cmd-shift-w' to close the window.

On Tuesday, May 27, 2014, Corey Johnson [email protected] wrote:

Thanks @jingchan https://github.com/jingchan, could you write some
specs to cover this change.

I may be alone, but I consider not closing the window with cmd-w a
feature. So I'd like a config option that keeps that functionality.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/2411#issuecomment-44327610
.

@jingchan

Copy link
Copy Markdown
Author

Sure, I'll look into specs and a flag.. I'm not very familiar with this code so any tips would be appreciated =)

@izuzak

izuzak commented May 28, 2014

Copy link
Copy Markdown
Contributor

@jingchan Sure thing! To add a new config option, take a look at this snippet.

For some related specs, see this snippet for the core:close event which closes a pane, and this one for the window:close event which closes a window.

@benogle

benogle commented May 28, 2014

Copy link
Copy Markdown
Contributor

The more I think about this, the less I like it.

I dont think any of our commands should have different behavior based on state. cmd-w only closes a tab, cmd-shift-w only closes a window, cmd-\ only toggles the tree view, etc. That way you always know what you're going to get without having to keep state in your head.

IMO, this should be a package.

If this does end up in core, I think it's in the wrong place. workspace::destroyActivePane should only destroy the pane.

@lee-dohm

Copy link
Copy Markdown
Contributor

I kind of agree with @benogle on this one as far as the commands underlying the keymaps go.

Emacs seems to have a tradition of more complex commands having more complex names such as newline-and-indent. If we added a command called something like closePaneOrEmptyWindow and let people map that to Cmd+W if they wanted ... maybe that would be better?

I think following this composition model though is the better path than making commands with simple names more complex (and thereby making their names deceptive).

@probablycorey

Copy link
Copy Markdown

I agree with @lee-dohm and @benogle now, we shouldn't add this functionality to core. We could create a closePaneOrEmptyWindow command on core, but I think it makes more sense as a package. In fact, a package for this already exists! https://atom.io/packages/close-after-last-tab

@jingchan

Copy link
Copy Markdown
Author

After investigating behavior in other editors (i.e. SublimeText 3), it seems that cmd+w only closes the window if more than one windows are open. I guess I typically have extra windows in the background, so I never noticed this. Could this branching behavior be what's causing the disagreement in "expected behavior" here?

Only for an empty final window, does cmd+w not work, and in that case, cmd+q is always safe to use since you will never be inadvertently closing things in the background. This approach is nice because end users don't have to learn anything new. (At least on mac, cmd+shift+w felt strange to me, while the other editors' behavior felt natural and standard.)

Either way, I'd be okay with this being in the trunk or package or wherever (just let me know), as long as I can have it mimic the behavior of ST and TM. (old habits die hard =)

@benogle ctrl-w actually already does more than just close tab because it will close a pane if that pane has only has one tab remaining. I don't have easy access to the code right now, but you will see this logic in the workspace_view code that calls the modified function (I didn't think the edit belonged there, either.). So I would submit that consistency depends on whether users typically perceive an editor window as a pane or as something else =).

@probablycorey That package closes the last tab along with the last tab, rather than after it. I was unaware of how to create a package to achieve that, as I couldn't find an appropriate hook. That's what led to this patch. (See discussion about that package at #863 )

@lee-dohm

Copy link
Copy Markdown
Contributor

@jingchan I don't think that there really is disagreement over "expected behavior". I think we all agree that your desire for this feature is valid and we want you to have exactly the feature you want. The discussion happening is about the design of the commands underlying the key combinations that you want to perform this operation. And you may well be right that there are already instances of inconsistency in behavior ... but they should be fixed when they're found too 😄

@jingchan

Copy link
Copy Markdown
Author

@lee-dohm Thanks for the clarification. I was short on time with my last response, but I see that now. Also, the word 'disagreement' maybe came across stronger than intended. =)

I agree that both features should be available. It appears the default behavior in Sublime Text on Windows never closes the window (current behavior), while the default behavior on Mac only closes the window if others are available (proposed above). So it seems the defaults are OS-specific in ST's case.

Related Question: Has it been a priority for Atom to closely mimic behavior in other editors?

@lee-dohm

Copy link
Copy Markdown
Contributor

Has it been a priority for Atom to closely mimic behavior in other editors?

That's a complicated question. But I'll try to answer it from a couple different perspectives:

  1. I'm not employed by GitHub, so if there is an official priority list, I'm not privy to it
  2. I don't know of a publicly stated priority for Atom to closely mimic the behavior of other editors
  3. I do know that a lot of (perhaps even most) feature requests on Discuss are requests for Atom to more closely mimic the behavior of other editors (vim, Emacs, Sublime Text and TextMate are the most common ... though not necessarily in that order)
  4. My personal opinion is that Atom should be its own editor. We should use other editors as a indicator of what could work ... but we shouldn't be afraid to do something radically different if it will be better ... even if that means that Atom will feel wrong to people at first. In other words, rewriting Sublime Text in CoffeeScript is a waste of time, in my opinion. From my blog post In Search Of: The Perfect Editor when I was still using Emacs:

Emacs isn't really an editor. It is a programming language that you use to write your dream editor with.

I feel the same way about Atom ... it should be a high-level language that people like you use to build their dream editor with, whether that closely mimics the behavior of other editors or not.

@izuzak

izuzak commented Jun 3, 2014

Copy link
Copy Markdown
Contributor

Since we have second-thoughts about adding this to Atom core, and since there already is a package that provides this functionality -- should we close this PR? Personally, I'm also leaning towards that option. /cc @probablycorey @benogle

To help users find packages which provide functionality that commonly comes built-in with editors -- we could make a list of such packages and link to it from the docs and in the Welcome screen (?).

@jingchan

jingchan commented Jun 3, 2014

Copy link
Copy Markdown
Author

@izuzak as discussed above and in the referenced issue, that package does not provide the feature being discussed.

@jingchan

jingchan commented Jun 3, 2014

Copy link
Copy Markdown
Author

It is also discussed on that packages repo here: JRHeaton/atom-close-after-last-tab#2

(Sorry for new comment, can't edit on phone)

@izuzak

izuzak commented Jun 3, 2014

Copy link
Copy Markdown
Contributor

as discussed above and in the referenced issue, that package does not provide the feature being discussed.

@jingchan Thanks for pointing that out, I did miss that discussion. However, I'm not sure everyone agrees on what the feature being discussed is (should the window close always, or only if there is another window open? should the window close with the last tab or after it, requiring another cmd-w keystroke? should it completely mimic an existing editor or not?). And even if there was agreement, it seems that there are concerns about adding this functionality into Atom core.

How do you feel about creating a new package for this, which implements this feature in the way you expect it to work, or with configuration options to cover the possibilities mentioned above?

@jingchan

jingchan commented Jun 3, 2014

Copy link
Copy Markdown
Author

@izuzak Not a problem. I'll close this. I didn't realize the existing behavior would be preferable to some, but since that is the case, it probably shouldn't be in core.

I wouldn't mind writing a package for this (when I find the time), but I believe some new events need to be emitted for that to be possible.

However, as a UI/UX guy, I would recommend a sublime-like "close if no tabs" functionality as default, simply because it covers more typical end-user use-cases with less keys. It's lessens the learning/thinking burden. But that is up to you guys to decide =).

@jingchan jingchan closed this Jun 3, 2014
@izuzak

izuzak commented Jun 3, 2014

Copy link
Copy Markdown
Contributor

Sorry if my comments sounded like my goal was to close this PR (it wasn't). I agree that having this functionality would be useful, but it seems that this PR wasn't moving forward.

My intention was to push things forward, so that you get some feedback and so that this functionality becomes available to users. At the moment, it seems that there are concerns to adding this to Atom core, so the best/fastest way to make this happen is to create a new package (or contribute to an existing one).

I believe some new events need to be emitted for that to be possible.

Could you clarify which events would need to be added? I think that listening for core:close, pane:item-removed, and pane:item-added, and keeping track of the number of opened items should do the trick. Have you already tried that approach and it didn't work?

@benogle

benogle commented Jun 3, 2014

Copy link
Copy Markdown
Contributor

I think for now, a package is the right way forward 👍

I agree with @izuzak that likely nothing will need to be added to support this. If you get into it, and you need something, ping us :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to have cmd-w close the window when there are no editors open

5 participants