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

[Peek][PreviewPane] Fix missing Copy menu-item #33845

Merged
merged 7 commits into from
Jul 25, 2024

Conversation

drawbyperpetual
Copy link
Collaborator

@drawbyperpetual drawbyperpetual commented Jul 15, 2024

Summary of the Pull Request

Fixes two bugs:

  • Peek: Missing "Copy" menu-item for all WebView2 previewers.
  • PreviewPane: Missing "Copy" menu-item for markdown files only.

PR Checklist

Detailed Description of the Pull Request / Additional comments

The issues are:

  • Peek:
    • When not using Monaco (markdown, html) - the default WebView2 context menu has been disabled. I have enabled it and then disabled ALL menu-items other than "Copy" (such as "Back").
    • When using Monaco + Release (other code files) - current code tries to use the Monaco context menu, but it is somehow disabled at runtime. I spent MANY hours trying to find out why but without success. It works fine when I view the generated html + js files in a browser or in a Debug build or in PreviewPane. But I couldn't find the root cause. Trying to fix it by enabling the WebView2 context menu instead doesn't work as for whatever reason, WebView2 doesn't generate a "Copy" menu-item (it thinks there's no selected text when there is). So in this case, the only thing I could get to work was generating context menu-items via WebView2 callbacks that call JS functions. As a bonus, this way of doing it also allows "Toggle text wrapping" to work.
  • PreviewPane:
    • Markdown - the default WebView2 context menu has been disabled. Like for Peek, I have enabled it and then disabled ALL menu-items other than "Copy" (such as "Back").
    • Monaco (other code files) - this already just works fine, so I've left it as is. I could make it work the same way as I've done for Peek for consistency, but I've chosen to leave it as is since it works.

image
image

Validation Steps Performed

  • Tested copy (via menu-item and CTRL+C) for text formats on Peek/PreviewPane. Also tested "Toggle text wrapping" where appropriate.
  • Sanity check of Peek and PreviewPane.

@htcfreek
Copy link
Collaborator

@drawbyperpetual
A screenshot of the new menu content would be great.

Not sure how it looks. But for the layout a separator line between the copy command and the setting toggle entries would be good, I think.

@drawbyperpetual
Copy link
Collaborator Author

@drawbyperpetual A screenshot of the new menu content would be great.

Not sure how it looks. But for the layout a separator line between the copy command and the setting toggle entries would be good, I think.

@htcfreek : I've added a separator between the commands and also updated the PR description with screenshots. Let me know what you think!

@htcfreek
Copy link
Collaborator

@drawbyperpetual A screenshot of the new menu content would be great.

Not sure how it looks. But for the layout a separator line between the copy command and the setting toggle entries would be good, I think.

@htcfreek : I've added a separator between the commands and also updated the PR description with screenshots. Let me know what you think!

Looks good.

@htcfreek
Copy link
Collaborator

Btw, merging this should be synced with merging #33742.

Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

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

Thanks for the feature.
LGTM. Only quirk I've found is that if I use Peek on either Markdown or Monaco files, make the context menu show and then move the Peek window between monitors, it will make the context menu start appearing on random spots. Like sometimes it even shows on a different monitor than what the Peek window is in.

@drawbyperpetual
Copy link
Collaborator Author

Thanks for the feature. LGTM. Only quirk I've found is that if I use Peek on either Markdown or Monaco files, make the context menu show and then move the Peek window between monitors, it will make the context menu start appearing on random spots. Like sometimes it even shows on a different monitor than what the Peek window is in.

@jaimecbernardo : I've fixed that context menu location issue for Peek. The way I did it was to not rely on the WebView2 context menu at all but instead draw a WPF context menu instead. The only downside is I couldn't find a way to replicate the pretty Copy icon from the WebView2 context menu. But I think that's a small issue as Monaco doesn't have it either.

BTW, the PreviewPane context menu doesn't seem to have to that context menu location issue for whatever reason. So I've kept the WebView2 context menu for the PreviewPane + Markdown previewer instead of drawing a WPF context menu.

@crutkas crutkas added the Needs-Review This Pull Request awaits the review of a maintainer. label Jul 24, 2024
Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@jaimecbernardo jaimecbernardo merged commit 84def18 into main Jul 25, 2024
14 checks passed
@jaimecbernardo jaimecbernardo removed the Needs-Review This Pull Request awaits the review of a maintainer. label Jul 25, 2024
@drawbyperpetual drawbyperpetual deleted the dev/ani/peek-fix-copy branch July 31, 2024 15:24
PesBandi added a commit to PesBandi/PowerToys that referenced this pull request Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

4 participants