Skip to content

Add Command for navigating around visible editors/viewlets/repl#22005

Merged
bpasero merged 14 commits intomicrosoft:masterfrom
misoguy:feature/navigation
Mar 14, 2017
Merged

Add Command for navigating around visible editors/viewlets/repl#22005
bpasero merged 14 commits intomicrosoft:masterfrom
misoguy:feature/navigation

Conversation

@misoguy
Copy link
Contributor

@misoguy misoguy commented Mar 5, 2017

Fix #21669

@mention-bot
Copy link

@misoguy, thanks for your PR! By analyzing the history of the files in this pull request, we identified @bpasero and @egamma to be potential reviewers.

@msftclas
Copy link

msftclas commented Mar 5, 2017

@misoguy,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by Microsoft. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

@bpasero bpasero self-assigned this Mar 6, 2017
@misoguy
Copy link
Contributor Author

misoguy commented Mar 9, 2017

@bpasero I've added an abstract class BaseNavigationAction and planning to implement up/down/left/right navigation based on this abstract class. It would be nice if you could take a brief look on this code.
By the way, hygenie seems to fail with no reason...

@jtheoof
Copy link

jtheoof commented Mar 10, 2017

The code seems good even though I don't know much of the vscode codebase. I tested it and it works as expected. I was wondering, there is nothing extra to do to be able to bind those commands to custom keybindings right?

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

Seems to work very nicely, some feedback added.

}

public next(jumpGroups: boolean): IEditorIdentifier {
public next(jumpGroups: boolean, cycleAtEnd = true): IEditorIdentifier {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a test for this in editorStacksModel.test.ts

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'll definitely add this test!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test added.

if (isWindows || isLinux) {
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMenuBarAction, ToggleMenuBarAction.ID, ToggleMenuBarAction.LABEL), 'View: Toggle Menu Bar', viewCategory);
}
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(NavigateUpAction, NavigateUpAction.ID, NavigateUpAction.LABEL, null), 'View: Navigate Up', viewCategory);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if the command name is verbose enough to understand the intent. Can we see how others (VIM?) name this command? Maybe "Navigate to next View to the Left" etc?

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 understand that the command name might not be verbose enough.
Do you mean that the View: Navigate Up should be renamed as Navigate to next View to the top or to change the class name itself? Something like class NavigateUp to class NavigateViewToTheTop?

Copy link
Member

Choose a reason for hiding this comment

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

No I was just thinking of the label for users when they find this command in the command palette for example.

Copy link
Member

Choose a reason for hiding this comment

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

Here are Vim's descriptions:

	CTRL-W h	move to the window on the left
	CTRL-W j	move to the window below
	CTRL-W k	move to the window above
	CTRL-W l	move to the window on the right

	CTRL-W t	move to the TOP window
	CTRL-W b	move to the BOTTOM window

We may want to replace window with View or View Part or similar.

Copy link
Contributor Author

@misoguy misoguy Mar 12, 2017

Choose a reason for hiding this comment

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

I'll change the label to
'View: Move to the View Part on the left'(right/below/above)
and leave the ID as workbench.action.navigateLeft (as currently implemented)
By the way, is move to the TOP window and move to the BOTTOM window required as well? Since it is currently not implemented...

Copy link
Member

Choose a reason for hiding this comment

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

I would think we should handle those commands in a separate PR if we ever needed them.

return this.navigateToLastActiveEditor();
}

private navigateLeftFromEditor(jumpGroups: boolean, isSidebarPositionLeft: boolean): TPromise<boolean> {
Copy link
Member

Choose a reason for hiding this comment

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

Why would we ever not jump groups? I am in a state where I have 2 editors open in one group and navigating left and right jumps between those tabs. My understanding is that this is entirely not about navigating between tabs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We would not jump groups in 2 situations

  • When the sidebar is on the left and the current active editor is the first editor in the first group, we would have to go to the sidebar
  • When the sidebar is on the right, it's the opposite

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I was not clear: I found a situation where invoking the action was jumping from tab A to tab B in the same single editor group. I suppose that might just be a bug?

Copy link
Member

Choose a reason for hiding this comment

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

As we are just navigating between visible UI parts, we should just navigate between editor groups instead of activating tabs. Otherwise if users open a dozen of files, navigation commands are useless somehow.

If I understand correctly, IEditorGroupService.focusGroup is enough for editor navigation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bpasero @rebornix So is it agreed that the navigation should only occur between the View Parts?(ex: sidebar, panel, and 1-3 editor groups)
This means that navigating left and right will not move to the left/right editor of the current group, but will move to the left/right group of the current editor group instead.

Copy link
Member

Choose a reason for hiding this comment

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

@misoguy yes, navigation only between view parts. If there is only one group opened with many editors and no other view part, then basically you cannot navigate anywhere else at all. If more than one group is opened, you can start to navigate between groups.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood, this means that the code has to be changed a little bit. I'll get on it when I get the time :)

}
}

export class NavigateDownAction extends BaseNavigationAction {
Copy link
Member

Choose a reason for hiding this comment

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

Should we navigate down to the panel when focus is in the sidebar? Currently that is not happening.

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's my understanding that we will not move down or up when the focus is in the sidebar.
However, if we should navigate down to the panel when focus is in the sidebar, it can be implemented.
Should it be implemented?

Copy link
Member

Choose a reason for hiding this comment

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

Best to talk back to issue creator + VIM guys :)

Copy link
Member

Choose a reason for hiding this comment

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

I'll suggest not to do that at this moment :)

@misoguy
Copy link
Contributor Author

misoguy commented Mar 10, 2017

@jtheoof Thanks for testing it out :) However, I didn't really understand what you meant by "I was wondering, there is nothing extra to do to be able to bind those commands to custom keybindings right?". Do you mean is it possible to bind it in a plugin?

@misoguy
Copy link
Contributor Author

misoguy commented Mar 14, 2017

Made all changes as requested, and cleared up some unused codes.
I'll remove the [WIP] header in this PR :)
All comments about the PR is welcome!

@misoguy misoguy changed the title [WIP] Add Command for navigating around visible editors/viewlets/repl Add Command for navigating around visible editors/viewlets/repl Mar 14, 2017
@jtheoof
Copy link

jtheoof commented Mar 14, 2017

@misoguy No I meant if there was anything special to do to have custom keymaps. I do not see the new "commands"

{ "key": "cmd+up",  "command": "navigateUpAction", "when": "editorHasSelection && editorTextFocus" }

would work? (Forgive my noobs question, it's the first time I review a PR in code).

@misoguy
Copy link
Contributor Author

misoguy commented Mar 14, 2017

@jtheoof The command you are looking for is workbench.action.navigateUp (or down, right, left depending what you want)
In conclusion, the key mapping you need will be something like below.
{ "key": "cmd+up", "command": "workbench.action.navigateUp" }
("when" is optional)

@rebornix
Copy link
Member

rebornix commented Mar 14, 2017

LGTM, just two tiny comments.

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

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

@misoguy some more feedback

@Tyriar do we need to whitelist these commands to run them from the integrated terminal? I assigned Cmd+Up to navigate to the view to the top but pressing this in the console did not work but rather printed some weird control characters to the terminal.

if (isWindows || isLinux) {
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleMenuBarAction, ToggleMenuBarAction.ID, ToggleMenuBarAction.LABEL), 'View: Toggle Menu Bar', viewCategory);
}
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(NavigateUpAction, NavigateUpAction.ID, NavigateUpAction.LABEL, null), 'View: Move to the View Part above', viewCategory);
Copy link
Member

Choose a reason for hiding this comment

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

@misoguy please use capital casing here, e.g. View: Move to the View Part Above

export class NavigateLeftAction extends BaseNavigationAction {

public static ID = 'workbench.action.navigateLeft';
public static LABEL = nls.localize('navigateLeft', "Navigate Left");
Copy link
Member

Choose a reason for hiding this comment

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

@misoguy please make sure that these labels are in sync with where you register them (e.g. this one should be View: Move to the View Part on the Left).


export abstract class BaseNavigationAction extends Action {

protected NEXT = 'next';
Copy link
Member

Choose a reason for hiding this comment

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

@misoguy a bit weird, why not use an enum outside of the action?

enum Direction {
   Next,
   Previous
}

@misoguy
Copy link
Contributor Author

misoguy commented Mar 14, 2017

@bpasero Changed as requested 👍

@bpasero
Copy link
Member

bpasero commented Mar 14, 2017

Awesome, thanks 👍

@Tyriar
Copy link
Member

Tyriar commented Mar 14, 2017

@bpasero yes the whitelist is here: https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts#L145 (messy I know #19770).

cmd+up/down actually seem to be used in Terminal.app to jump to the previous/next command which we may want to implement in the future. The cmd+left/right printing escape sequences may actually be a bug here, opened xtermjs/xterm.js#597

super(id, label, groupService, panelService, partService, viewletService);
}

protected navigateOnEditorFocus(isEditorGroupVertical, isSidebarPositionLeft): TPromise<boolean> {
Copy link
Member

Choose a reason for hiding this comment

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

If isEditorGroupVertical is false, navigate left will navigate to the sidebar, whether the sidebar is on the left or right. However, if isEditorGroupVertical is true and isSidebarPositionLeft is false, it won't navigate to the sidebar on the right. The behavior is not consistent.

}

protected navigateOnEditorFocus(isEditorGroupVertical, isSidebarPositionLeft): TPromise<boolean> {
if (!isEditorGroupVertical) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@bpasero
Copy link
Member

bpasero commented Mar 16, 2017

@rebornix I cannot reproduce, I am in this setup and Cmd+Left (for navigating left) does not bring me to the sidebar:

image

@misoguy
Copy link
Contributor Author

misoguy commented Mar 17, 2017

@bpasero There was a bug like @rebornix mentioned but I had it fixed before being merged :)

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
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.

VIM: Command for navigating around visible editors/viewlets/repl

7 participants