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

terminal: add toggle terminal command #11193

Merged
merged 3 commits into from Aug 5, 2022
Merged

terminal: add toggle terminal command #11193

merged 3 commits into from Aug 5, 2022

Conversation

jaimemartinagui
Copy link
Contributor

What it does

Partial implementation of a new command and shortcut (keybinding) to toogle the integrated terminal in Theia. There are 4 cases for the command:

  • Case 1: if no terminal exists, a new one is created.
  • Case 2: if a terminal exists, but is hidden, expand the bottom panel and set the focus to it.
  • Case 3: if a terminal exists and is visible, but without the focus, set the focus to it.
  • Case 4: if a terminal exists, is visible and has the focus, collapse the bottom panel and set the focus back to the editor.

The part of managing the focus is still not implemented.

How to test

Try the shortcut ("ctrl+shift+.") in the different scenarios.

Review checklist

Reminder for reviewers

}

protected toogleTerminal(widget: Widget): void {
const allTerminals = this.widgetManager.getWidgets(TERMINAL_WIDGET_FACTORY_ID) as TerminalWidget[];
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to get all widgets and so on, you already should have access to the currentTerminal or lastUsedTerminal:

const currentTerminal = this.currentTerminal;
const lastUsedTerminal = this.lastUsedTerminal;

I believe this should be enough for all use-cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will try this option then and let you know. Thanks!

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 have modified this part and it is now using this._currentTerminal instead of retrieving all the widgets.

However, I am still having issues with the focus, to switch it between the terminal and the editor.

@vince-fugnitto vince-fugnitto added the terminal issues related to the terminal label May 24, 2022
@vince-fugnitto
Copy link
Member

@jaimemartinagui thank you for continuing to work on the pull-request 👍

I believe the following code should handle all use-cases:

protected toggleTerminal(): void {
    // Collect terminals from the bottom area.
    const terminals = this.shell.getWidgets('bottom').filter(w => w instanceof TerminalWidget);

    // If no terminal exists, open a new one.
    if (terminals.length === 0) {
        this.openTerminal();
        return;
    }

    // If the bottom panel is hidden, activate it and the first terminal found.
    if (this.shell.bottomPanel.isHidden) {
        this.shell.bottomPanel.setHidden(false);
        terminals[0].activate();
        return;
    }

    // If the bottom panel is visible, handle the visibility.
    if (this.shell.bottomPanel.isVisible) {
        const visibleTerminal = terminals.find(t => t.isVisible);
        if (!visibleTerminal) {
            this.shell.bottomPanel.activateWidget(terminals[0]);
        } else {
            this.shell.bottomPanel.setHidden(true);
        }
    }
}

@jaimemartinagui
Copy link
Contributor Author

Hi @vince-fugnitto,

I have tested the code you provided and I found a slight difference in the behavior with the one I would expect (as it works in VS Code).

When the terminal is not hidden and has the focus, the terminal should be hidden, and it is in fact. However, when the terminal is not hidden and does not have the focus, I would expect this command to set the focus to the terminal. Instead of this, the code you provided hides the terminal. In order to modify this, I have changed the code to the following:

  protected toggleTerminal(): void {
      // Collect terminals from the bottom area.
      const terminals = this.shell.getWidgets('bottom').filter(w => w instanceof TerminalWidget);

      // If no terminal exists, open a new one.
      if (terminals.length === 0) {
          this.openTerminal();
          return;
      }

      // If the bottom panel is hidden, activate it and the first terminal found.
      if (this.shell.bottomPanel.isHidden) {
          this.shell.bottomPanel.setHidden(false);
          terminals[0].activate();
          return;
      }

      // If the bottom panel is visible, handle the visibility.
      if (this.shell.bottomPanel.isVisible) {
          if (this.shell.activeWidget && this.shell.activeWidget.id === terminals[0].id)
              this.shell.bottomPanel.setHidden(true);
          else
              this.shell.bottomPanel.activateWidget(terminals[0]);
      }

  }

Please let me know what do you think about this or if the other behavior is the intended one.

Thanks!

@vince-fugnitto
Copy link
Member

However, when the terminal is not hidden and does not have the focus, I would expect this command to set the focus to the terminal.

@jaimemartinagui the behavior you identified is correct 👍 (I had not tested that use-case previously). However, I believe the code snippet you provided is problematic as it assumes that the first terminal is the visible one but not activated. Instead, you should check if there is a visible terminal in the bottom panel and compare it against the active widget.

Something like the following should work (it respects the visible terminal):

// If the bottom panel is visible, handle the visibility.
if (this.shell.bottomPanel.isVisible) {
    const visibleTerminal = terminals.find(t => t.isVisible);
    if (!visibleTerminal) {
        this.shell.bottomPanel.activateWidget(terminals[0]);
    } else if (this.shell.activeWidget !== visibleTerminal) {
        this.shell.bottomPanel.activateWidget(visibleTerminal);
    } else {
        this.shell.bottomPanel.setHidden(true);
    }
}

@jaimemartinagui
Copy link
Contributor Author

Thank you @vince-fugnitto. That was something I realized after posting the comment. I have implementen this last change and pushed it to the "toogle-terminal" branch.

@jaimemartinagui jaimemartinagui marked this pull request as ready for review June 16, 2022 21:00
@vince-fugnitto
Copy link
Member

@jaimemartinagui do you need any help to finish the pull-request, I believe the outstanding review is still #11193 (comment).

@jaimemartinagui
Copy link
Contributor Author

@jaimemartinagui do you need any help to finish the pull-request, I believe the outstanding review is still #11193 (comment).

Hello @vince-fugnitto. I have already modified the keybinding as suggested by @colin-grant-work. I am not sure if I have to do anything else for the PR to proceed.

@msujew
Copy link
Member

msujew commented Jul 11, 2022

@jaimemartinagui The ECA check still fails. The website shows that you've commited with multiple email adresses, of which at least one isn't covered by the ECA:

Anonymous (jaimemartinagui@****.com)
Anonymous (64321866+jaimemartinagui@****.noreply)

The second one is likely an email address which was automatically created by GitHub. It might be best to rebase and squash your changes, so that only one address remains.

@jaimemartinagui
Copy link
Contributor Author

@jaimemartinagui The ECA check still fails. The website shows that you've commited with multiple email adresses, of which at least one isn't covered by the ECA:

Anonymous (jaimemartinagui@****.com)
Anonymous (64321866+jaimemartinagui@****.noreply)

The second one is likely an email address which was automatically created by GitHub. It might be best to rebase and squash your changes, so that only one address remains.

So do you mean that I squash all the 14 commits of the branch in one by using interactive rebase?

@msujew
Copy link
Member

msujew commented Jul 12, 2022

So do you mean that I squash all the 14 commits of the branch in one by using interactive rebase?

Right, though there are other ways to accomplish this as well. You don't have to, but it might be the best way to resolve the ECA issue, especially since we don't allow noreply emails in our commits. We will squash your changes anyway when merging (we usually only perform one commit per PR), so you'll have more control over the final commit message/commit description if you just give us one commit to review.

Signed-off-by: jaimemartinagui@gmail.com

Toogle terminal feature (not completed). Signed-off-by: Jaime Martin Agui jaimemartinagui@gmail.com

Toogle terminal feature (not completed)

Update packages/terminal/src/browser/terminal-frontend-contribution.ts

Modify the id of the command for VS Code extensions.

Co-authored-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>

Update packages/terminal/src/browser/terminal-frontend-contribution.ts

Modify command label to fix typo ("toogle" when it should be "toggle").

Co-authored-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>

Update packages/terminal/src/browser/terminal-frontend-contribution.ts

Modify method name to fix typo ("toogle" when it should be "toggle").

Co-authored-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>

Update packages/terminal/src/browser/terminal-frontend-contribution.ts

Modify constant name to fix typo ("toogle" when it should be "toggle").

Co-authored-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>

Update packages/terminal/src/browser/terminal-frontend-contribution.ts

Simplify the registration of the command.

Co-authored-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>

Update packages/terminal/src/browser/terminal-frontend-contribution.ts

Using Strict Equals Operator instead of Equals Operator.

Co-authored-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>

Update packages/terminal/src/browser/terminal-frontend-contribution.ts

Missing ";"

Co-authored-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>

Modify command registration typo ("toogle" when it should be "toggle").

Using this._currentTerminal instead of getting all the widgets

Final implementation of toggle terminal functionality

Changing the keybinding for the terminal toogle feature
@jaimemartinagui
Copy link
Contributor Author

So do you mean that I squash all the 14 commits of the branch in one by using interactive rebase?

Right, though there are other ways to accomplish this as well. You don't have to, but it might be the best way to resolve the ECA issue, especially since we don't allow noreply emails in our commits. We will squash your changes anyway when merging (we usually only perform one commit per PR), so you'll have more control over the final commit message/commit description if you just give us one commit to review.

I have already squashed the commits into one single commit. Please let me know if it is now correct. Thanks!

@vince-fugnitto
Copy link
Member

I have already squashed the commits into one single commit. Please let me know if it is now correct. Thanks!

@jaimemartinagui almost! :) It looks like there is a file which is unrelated to your changes packages/core/i18n/nls.zh-cn.json.

@jaimemartinagui
Copy link
Contributor Author

I have already squashed the commits into one single commit. Please let me know if it is now correct. Thanks!

@jaimemartinagui almost! :) It looks like there is a file which is unrelated to your changes packages/core/i18n/nls.zh-cn.json.

Yes, I don't know why it appeared as modified that other file. I have solved the conflicts.

@vince-fugnitto vince-fugnitto changed the title Toogle terminal feature (not completed) terminal: add toggle terminal command Jul 13, 2022
@jaimemartinagui
Copy link
Contributor Author

I don't know why the build failed for macOS-10.15, note 16.

@vince-fugnitto
Copy link
Member

I don't know why the build failed for macOS-10.15, note 16.

@jaimemartinagui no problem we can always re-trigger CI but there is a linting problem:

@jaimemartinagui
Copy link
Contributor Author

There was ;; instead of ; in one line. Thank you!

@jaimemartinagui
Copy link
Contributor Author

Hi @vince-fugnitto, could it be that the sign is missing, so the PR cannot be merced? or is there anything else blocking it?

@msujew
Copy link
Member

msujew commented Jul 22, 2022

@jaimemartinagui It seems like you didn't actually sign the ECA that's necessary for us to accept your changes. Signing the commit isn't necessary anymore (the documentation is a bit outdated).

@jaimemartinagui
Copy link
Contributor Author

@jaimemartinagui It seems like you didn't actually sign the ECA that's necessary for us to accept your changes. Signing the commit isn't necessary anymore (the documentation is a bit outdated).

Thank you @msujew! I was not aware of it. I have already done it.

Copy link
Contributor

@colin-grant-work colin-grant-work left a comment

Choose a reason for hiding this comment

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

The cases described in the PR all work well for me, and the code looks correct. Thanks for the contribution!

@colin-grant-work colin-grant-work merged commit 2a7341d into eclipse-theia:master Aug 5, 2022
@jaimemartinagui jaimemartinagui deleted the toogle-terminal branch August 8, 2022 16:29
@vince-fugnitto vince-fugnitto added this to the 1.29.0 milestone Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
terminal issues related to the terminal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants