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

Restore focus to the last focused side in a diff editor #69922

Closed
RMacfarlane opened this issue Mar 7, 2019 · 9 comments
Closed

Restore focus to the last focused side in a diff editor #69922

RMacfarlane opened this issue Mar 7, 2019 · 9 comments
Assignees
Labels
diff-editor Diff editor issues *duplicate Issue identified as a duplicate of another issue(s) quick-pick Quick-pick widget issues under-discussion Issue is under discussion for relevance, priority, approach

Comments

@RMacfarlane
Copy link
Contributor

Issue Type: Bug

Similar to #22403

  1. Open a diff view
  2. Put cursor in left side editor
  3. Open the command palette, and either run a command or close it

Instead of focus returning to the left side, it is shifted to the right. When the quick open hides, it's trying to focus back on the old editor
https://github.com/Microsoft/vscode/blob/d315d18deec4b9ece7f3cbb9d74a6916bb9718e8/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts#L281

but the diff editor always focuses the modified side:
https://github.com/Microsoft/vscode/blob/d315d18deec4b9ece7f3cbb9d74a6916bb9718e8/src/vs/editor/browser/widget/diffEditorWidget.ts#L758

I'm trying to write a command for starting a new comment thread, so I need to be able to get the focused editor. But the focus is always changed before the command runs, so there's no way to tell which editor to use

VS Code version: Code - Insiders 1.32.0-insider (507312a, 2019-03-06T11:10:01.691Z)
OS version: Darwin x64 18.2.0

@alexdima
Copy link
Member

The diff editor is considered to be a single editor by our workbench and when .focus() is called, it focuses the right side. The same bug exists, for example, when invoking the quick open from the find widget... focus is not returned to the find widget... Another instance of the same issue is invoking it from an embedded editor like the one in peek definition.

I suggest the quick open checks where focus is before it is invoked and then restores focus when it is dismissed.

@alexdima alexdima assigned bpasero and chrmarti and unassigned alexdima Mar 27, 2019
@bpasero bpasero changed the title Focus switches from left to right side of diff view when using quickpick Restore focus to the last focused side in a diff editor Mar 27, 2019
@bpasero bpasero added feature-request Request for new features or functionality diff-editor Diff editor issues labels Mar 27, 2019
@bpasero
Copy link
Member

bpasero commented Mar 27, 2019

I acknowledge the problem but would not want to change the default here simply because the left hand editor very often is not writable and this could cause frustration.

Having an option for the focus() method to consider diff editors as opt-in could work though. Feel free to spin up a PR for that. I would however not blindly use that for each command from the command palette for these reasons.

@alexdima
Copy link
Member

alexdima commented Mar 27, 2019

@bpasero Please check my suggestion:

I suggest the quick open checks where focus is before it is invoked and then restores focus when it is dismissed

i.e. record document.activeElement when quick open is shown and return focus there when it finishes, like the custom menus.

@bpasero bpasero removed the feature-request Request for new features or functionality label Mar 28, 2019
@bpasero
Copy link
Member

bpasero commented Mar 28, 2019

@alexandrudima quick open was never tracking document.activeElement so far but would always try to restore focus to the active editor by calling editor.focus(). I got a lot of complaints in the past that after using quick open, focus was not in the editor (e.g. because focus was somewhere else) so we changed this a long time ago and I think we should keep that behaviour.

Thus, to make this work properly, you would need to change diffEditorWidget.ts#focus() to restore focus to the left or right hand side based on what was the last active side:

image

@chrmarti
Copy link
Collaborator

This is a more general problem. We could track the focus for the entire workbench and when QuickOpen closes, we would just return to the previous active element.

The current solution appears to be to always return focus to the editor, which is not always correct, but has worked surprisingly well so far.

@alexdima
Copy link
Member

alexdima commented Mar 28, 2019

@bpasero My recommendation is to read document.activeElement when quick open is shown and focus back to that element when quick open is hidden. This is completely unrelated to the diff editor. This would cover the case when focus is in the find widget and quick open is invoked, focus would return to the find widget. Similar to how the custom menus work.

@bpasero
Copy link
Member

bpasero commented Mar 28, 2019

@alexandrudima we can do that, just worried that this is changing a pattern people might have gotten used to. Today we give the editor some extra treatment by always moving focus into it when any quick picker closes. We also have to make 100% sure that the command that executes from quick open does not require the editor to be focused. I remember in the past we had some issues with that where focus was not back in the editor but the command assumed that.

@chrmarti btw you are doing the same for quickInput:

https://github.com/Microsoft/vscode/blob/3e2e048b9a3d65c8c47b309e01186bbf788ee6d8/src/vs/workbench/browser/parts/quickinput/quickInput.ts#L1386

I do not see myself doing a lot of changes for old quick open given I want quick open to move over to your widget (via #69955)

@bpasero bpasero added quick-pick Quick-pick widget issues under-discussion Issue is under discussion for relevance, priority, approach labels Mar 28, 2019
@chrmarti
Copy link
Collaborator

/duplicate #44722

@vscodebot vscodebot bot added the *duplicate Issue identified as a duplicate of another issue(s) label Aug 23, 2019
@vscodebot
Copy link

vscodebot bot commented Aug 23, 2019

Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for existing issues here. See also our issue reporting guidelines.

Happy Coding!

@vscodebot vscodebot bot closed this as completed Aug 23, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
diff-editor Diff editor issues *duplicate Issue identified as a duplicate of another issue(s) quick-pick Quick-pick widget issues under-discussion Issue is under discussion for relevance, priority, approach
Projects
None yet
Development

No branches or pull requests

5 participants