Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pinned Tabs #10817

Merged

Conversation

colin-grant-work
Copy link
Contributor

@colin-grant-work colin-grant-work commented Feb 28, 2022

What it does

Commands for pinning and unpinning tabs. Fixes #9326. Closes #9614.

This is based on #9614 with a bug fix and a switch to codicons for pinned tab icons.

How to test

  1. Use the tabbar context menu or command palette to pin and unpin tabs.

    In the main or bottom areas, they should receive a pin icon.
    If dirty, an editor should receive pin-with-dot icon.

  2. Try to close pinned editors by clicking on the pin icon. They should not close, but should convert to unpinned editors.
  3. Reload the page / restart the application. Pinned state should be restored.

Review checklist

Reminder for reviewers

@colin-grant-work colin-grant-work added the shell issues related to the core shell label Feb 28, 2022
@msujew msujew self-requested a review March 1, 2022 10:45
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed some minor issues in this feature:

  1. Pinning a side bar tab prevents it from closing. Moving this pinned tab to the main area leaves it in an invalid state. The usual close icon is displayed and works as expected. However, the context menu entry for Pin is disabled and the one for Unpin is enabled.
  2. Pinning a focused tab removes the focus from the tab. VSCode refocuses the target tab of the context menu after it closes. This one might not have to do with your PR and is probably more of a general issue of how context menus and tab focus work.

Comment on lines 166 to 170
h.div({
className: 'p-TabBar-tabCloseIcon',
onclick: this.handleCloseClickEvent
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: This item is missing its hovering effect. You can simply add the action-item class to enable it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think the original PR predated your work in that area.

Comment on lines 245 to 254
export const PIN_TAB = Command.toDefaultLocalizedCommand({
id: 'workbench.action.pinEditor',
category: VIEW_CATEGORY,
label: 'Pin Tab'
});
export const UNPIN_TAB = Command.toDefaultLocalizedCommand({
id: 'workbench.action.unpinEditor',
category: VIEW_CATEGORY,
label: 'Unpin Tab'
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The eslint rule doesn't really work for toDefaultLocalizedCommand (I should fix this perhaps)

Pin and Unpin are the labels used by VSCode and can both be found in the nls.metadata.json file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did wonder about whether the linting would catch it for the other NLS utilities. I'll update the text.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually just noticed that VSCode is using Pin editor/Unpin editor. Since we do not only allow pinning on editors, we should maybe introduce new translations here? Or is Pin editor accurate enough for the command label?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think editors are going to be the most common targets, in any case, so I'll use '(un)pin editor' for now.

@colin-grant-work
Copy link
Contributor Author

I noticed some minor issues in this feature:

  1. Pinning a side bar tab prevents it from closing. Moving this pinned tab to the main area leaves it in an invalid state. The usual close icon is displayed and works as expected. However, the context menu entry for Pin is disabled and the one for Unpin is enabled.
  2. Pinning a focused tab removes the focus from the tab. VSCode refocuses the target tab of the context menu after it closes. This one might not have to do with your PR and is probably more of a general issue of how context menus and tab focus work.

@msujew, thanks for the review. Do you remember which views had problems in this scenario? It seems some widgets are OK (e.g. editors) and others unpin themselves (e.g. extensions). If you remember which ones you had trouble with, I'll be sure to test them and figure out what's going wrong.

@colin-grant-work colin-grant-work force-pushed the finish-up/pinned-tabs branch 2 times, most recently from 4e6dc30 to 8e1fdaa Compare March 1, 2022 17:30
@colin-grant-work
Copy link
Contributor Author

@msujew, I think the problem was probably code in ViewContainer, and I've adjusted that, and adjusted the code checking enablement of the commands to consistently check the closeable field, as well, so that closeable: true is always treated as pinned: false even if the classname is present.

@colin-grant-work colin-grant-work force-pushed the finish-up/pinned-tabs branch 2 times, most recently from f39b1f7 to c17ac0e Compare March 1, 2022 19:24
packages/core/src/browser/common-frontend-contribution.ts Outdated Show resolved Hide resolved
packages/core/src/browser/common-frontend-contribution.ts Outdated Show resolved Hide resolved
},
{
command: CommonCommands.UNPIN_TAB.id,
keybinding: 'ctrlcmd+k shift+enter',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that pinning does work using the specified keyboard shortcut. However, unpinning does not work for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out this was also a consequence of the 'editor' vs. 'widget' question. An earlier version of the PR had either had two context keys or only activeWidgetIsPinned and it was switched to editor to agree with VSCode, but the keybindings still referred to widget.

dsseng and others added 5 commits March 7, 2022 09:39
Add icons for pinned tabs
Add keybindings for pinning and unpinning tabs
Add a TODO notice for icons
Add activeEditorIsPinned context key
Add activeWidgetIsPinned context key while keeping vscode compatibility
Change pin/unpin commands to use activeWidgetIsPinned
Use VS Code command IDs for pin/unpin
Create TheiaTitle type
Refactor checks for pinning
Make preview editor non-preview when pinned
Unpin tab by clicking on icon
Fix reordering when unpinning
Do not rearrange tabs when pinned/unpinned
Make TheiaTitle a generic type

Co-authored-by: Colin Grant <[email protected]>
Co-authored-by: Dmitry Sharshakov <[email protected]>
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I noticed a minor issue with the keyboard shortcut: When an editor is unfocused (for example by clicking on the tab-bar), using the shortcut to pin works, but using it to unpin does not. It works in every other case that I've tested. Since this is quite minor, I will approve this PR nonetheless, as everything else is working.

  • Pinning/Unpinning editors using the Command/Context Menu works correctly
  • Also works mostly correctly with the shortcut
  • It also works as expected for other widgets, like Search and Debug, even when the widget is on the sidebar
  • The context menu entries related to closing files are correctly disabled depending on which widgets are pinned.

@colin-grant-work
Copy link
Contributor Author

Alright, I noticed a minor issue with the keyboard shortcut: When an editor is unfocused (for example by clicking on the tab-bar), using the shortcut to pin works, but using it to unpin does not. It works in every other case that I've tested. Since this is quite minor, I will approve this PR nonetheless, as everything else is working.

I appreciate the thorough testing! I will check on this scenario.

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed the following 👍

  • pinning/unpinning works
  • pinning/unpinning tabs in the main-area properly decorate the tab with the pin icon
  • pinning a editor-preview works, the editor becomes persistent
  • pinning dirty editors works, the tab is decorated with the dirty pin icon
  • pinning tabs in the sidepanels work well
  • pinned tabs are uncloseable unless unpinned first
  • pinned tabs are persistent on reloads
  • pinning with the keyboard shortcut works well
  • unpinning with the keyboard shortcut does not seem to work for some widgets (ex: reproducible with search-in-workspace) (likely what Mark noticed too)

@colin-grant-work
Copy link
Contributor Author

@msujew, @vince-fugnitto, thanks again for the thorough reviews. I believe I tracked down the problem with unpinning unfocused widgets: the context key setting and the command enablement were looking at different conditions. I have adjusted the code so that the context key is always looking at the same widget as the command will act on.

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that the outstanding issue regarding the keyboard shortcut has been fixed, the last issue in #10817 (review) now works 👍

Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Colin, that last change seems to have done it 👍

@colin-grant-work colin-grant-work merged commit 334b92e into eclipse-theia:master Mar 8, 2022
@colin-grant-work colin-grant-work deleted the finish-up/pinned-tabs branch March 8, 2022 22:09
@colin-grant-work colin-grant-work added this to the 1.24.0 milestone Mar 8, 2022
@msujew msujew mentioned this pull request Jun 9, 2022
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shell issues related to the core shell
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pin editor in tab-bar
4 participants