Open nmorduch opened 6 years ago
As you may have guessed this issue is closely related to #20. And similarly to that issue it is kind of hard to resolve this issue without https://github.com/atom/atom/pull/13812 being merged first...
However, I would imagine it is possible to implement a little script specifically for cmd + W that prevents it from closing pinned tabs 🤔 I will look into this as soon as possible 🙂
I've got a quick script working for you, but it is by no means ideal 😢 For now it reopens the tab you closed, but cursors, selections and foldings (and others) are lost. Anyway, you can add the following script to your init file.
document.body.addEventListener 'keydown', (e) ->
if e.key.toLowerCase() == 'w' && e.ctrlKey
pane = atom.workspace.getActivePane()
tab = pane.element.querySelector '.active'
if tab.classList.contains 'pinned-tab'
activeItem = pane.activeItem
itemIndex = pane.getItems().indexOf activeItem
setTimeout ->
atom.workspace.open(activeItem.getURI()).then (newItem) ->
atom.commands.dispatch document.querySelector('atom-workspace'), 'pinned-tabs:pin-active'
pane.moveItem newItem, itemIndex
, 1
+1
Further to this, it would be useful for this use case to enforce that a non-pinned tab is focused after a non-pinned tab is closed.
It seems that you use cmd + W to close all unpinned tabs? You can use the "Close unpinned tabs" configuration option to enable it as a context menu option or use this command (Pinned Tabs:Close Unpinned
) from the command pallet.
It seems like a bad idea to me to mess with what tab will be focused after the active tab has been closed. Do you have another reason then the one I mentioned for your request @rzjnzk? If so, it may be better to fix it some other way 🙂
@ericcornelissen
I personally tend to close multiple tabs in quick succession, though not necessarily all unpinned tabs. I will update you after using this plugin more if my views change. I see your point in that It may not be the best idea to alter core tab functionality, though in this case, I think it might be useful to have as a configuration option, though I do not know of the implications admittedly, perhaps mention them in a warning. Though, in my opinion, protecting pinned tabs from being exited with cmd+w would certainly ba a useful feature.
Edit:
I just tested the following script.
document.body.addEventListener 'keydown', (e) -> if e.key.toLowerCase() == 'w' && e.ctrlKey pane = atom.workspace.getActivePane() tab = pane.element.querySelector '.active' if tab.classList.contains 'pinned-tab' activeItem = pane.activeItem itemIndex = pane.getItems().indexOf activeItem setTimeout -> atom.workspace.open(activeItem.getURI()).then (newItem) -> atom.commands.dispatch document.querySelector('atom-workspace'), 'pinned-tabs:pin-active' pane.moveItem newItem, itemIndex , 1
It seemed to be ineffective with the terminal-tab
package which I have set to center by default, just thought I should mention that. Error: Uncaught Error: Pty seems to have been killed already
.
@rzjnzk Just to clarify, I am in favor of protecting pinned tabs from being closed with cmd + W (although admittedly it should be optional), however there is currently no way of supporting that. What I do not plan to support is changing what tab will be focused when a tab is closed as you suggested originally.
When I try to close the terminal-tab
it closes the active text editor instead. However, the error makes some sense as the script does not actually prevent the tab from being closed, it just reopens it immediately if it was a pinned tab.
I like the feature in Firefox where I cannot close pinned tabs using
cmd+W
. The use case for me is that I often close a number of tabs by repeatedly using that key command, but I don't want to close my pinned tabs. (I know I can use "close unpinned tabs" but it's not the easiest or most natural thing for me.)I would make an option in the settings to turn on this feature, since I imagine a number of people would not want it.