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

Ensure active element is preserved when opening context menu #10852

Merged
merged 1 commit into from
Mar 14, 2022
Merged

Ensure active element is preserved when opening context menu #10852

merged 1 commit into from
Mar 14, 2022

Conversation

martin-fleck-at
Copy link
Contributor

@martin-fleck-at martin-fleck-at commented Mar 7, 2022

What it does

Fixes #10851

This change ensures that the active element from the document is preserved when opening the menu. If there is already another element that is preserved, this fix simply does nothing as the previous preserved element is kept.

Please note that the top menu is not affected by this since the aboutToShow is called through the DynamicMenuBarWidget.

How to test

  1. Start Theia (I used the Electron app but it might occur also in the Browser app)
  2. ensure that browser menus are used (window.titleBarStyle: custom)
  3. Select any file and open the context menu and hit 'Copy'
  4. Open the context menu and hit 'Paste'
  5. See that the file is copied as expected

copy-paste_after

Review checklist

Reminder for reviewers

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.

@martin-fleck-at do you have any additional details on how to reproduce the problem, the behavior as you described works fine for me on master. I thought perhaps that no file selection should be present when performing paste, which does not work on master, but the pull-request also does not fix it.

If there is no file selection however the paste does not work, but it is also true with this pull-request.

@martin-fleck-at
Copy link
Contributor Author

martin-fleck-at commented Mar 7, 2022

@vince-fugnitto Interesting. I just tested this as shown in the video. I am using the current master, building with yarn && yarn build and then starting the Launch Electron Backend launch config from the debug perspective. I am using Ubuntu with Chrome as a default browser. Simply selecting a file, hitting 'Copy' from the context menu and then hitting 'Paste' with right click on the same file does not work for me without the fix. I just double checked but there is nothing else I am doing.

This PR does not aim to fix the empty selection Paste (if that is even an issue), so that is fine.

@vince-fugnitto
Copy link
Member

@martin-fleck-at this is master for me, I opened the dev tools to show the sources of the method in question.
Perhaps I am not reproducing it properly:

copy-paste-explorer.mp4

@martin-fleck-at
Copy link
Contributor Author

@vince-fugnitto Seems like I was not 100% correct about the necessary steps to reproduce this bug BUT thanks to your video I know see it. The bug happens when you use a custom title bar (Preferences > Window: Title Bar Style). In that case, the context menu seems to be rendered slightly differently.

@vince-fugnitto vince-fugnitto added the menus issues related to the menu label Mar 7, 2022
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.

@martin-fleck-at thank you for the follow-up I was able to reproduce finally 👍
I confirm that the changes work correctly thanks to your updates.

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.

There is a note in the code about this phenomenon. It seems we should at least remove the comment, if we are now calling preserveFocusedElement for context menus, but it may warrant further investigation, since this bug may suggest that something about the command registry is not behaving as expected.

// Hint: this is not called from the context menu use-case, but is not required.
// For the context menu the command registry state is calculated by the factory before `open`.

@martin-fleck-at
Copy link
Contributor Author

@colin-grant-work I did not remove the comment because I do not actually trigger the aboutToShow method but instead only call the preserveFocusedElement. The comment was exactly the reason I did not want to do it since, as you mentioned, there seems to be something special going on. The preserveFocusedElement, however, is pretty safe since it does not override any existing preserved element and thus should not cause much harm (famous last words ;-)).

@colin-grant-work
Copy link
Contributor

@martin-fleck-at, the comment above aboutToShow is about why preserveFocusedElement is called there and not in the context menu context. Since we're now calling it in both contexts, the comment is no longer accurate (it is incorrect to say 'is not called from the context menu use-case'), so it would be better to remove the comment.

@martin-fleck-at
Copy link
Contributor Author

@colin-grant-work I see, I interpreted it as: The aboutToShow is not called in the context menu use case (since it is called from DynamicMenuBarWidget) as the command registry state is calculated by the factory before open (and therefore we do not need to clear items and re-populate the sub-menus). However, I removed the comment as you suggested, thank you!

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.

LGTM. 👍

@vince-fugnitto vince-fugnitto merged commit 66a7b8c into eclipse-theia:master Mar 14, 2022
@vince-fugnitto vince-fugnitto added this to the 1.24.0 milestone Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
menus issues related to the menu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using copy / paste in the context menu of the Explorer does not work
3 participants