mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[Peek][PreviewPane]Show Copy entry in right-click copy menu (#33845)
## 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. ## 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.  
This commit is contained in:
@@ -43,6 +43,9 @@ namespace Peek.FilePreviewer.Previewers
|
||||
[ObservableProperty]
|
||||
private bool isDevFilePreview;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool customContextMenu;
|
||||
|
||||
private bool disposed;
|
||||
|
||||
public WebBrowserPreviewer(IFileSystemItem file, IPreviewSettings previewSettings)
|
||||
@@ -107,9 +110,14 @@ namespace Peek.FilePreviewer.Previewers
|
||||
{
|
||||
bool isHtml = File.Extension == ".html" || File.Extension == ".htm";
|
||||
bool isMarkdown = File.Extension == ".md";
|
||||
IsDevFilePreview = MonacoHelper.SupportedMonacoFileTypes.Contains(File.Extension);
|
||||
|
||||
if (IsDevFilePreview && !isHtml && !isMarkdown)
|
||||
bool supportedByMonaco = MonacoHelper.SupportedMonacoFileTypes.Contains(File.Extension);
|
||||
bool useMonaco = supportedByMonaco && !isHtml && !isMarkdown;
|
||||
|
||||
IsDevFilePreview = supportedByMonaco;
|
||||
CustomContextMenu = useMonaco;
|
||||
|
||||
if (useMonaco)
|
||||
{
|
||||
var raw = await ReadHelper.Read(File.Path.ToString());
|
||||
Preview = new Uri(MonacoHelper.PreviewTempFile(raw, File.Extension, TempFolderPath.Path, _previewSettings.SourceCodeTryFormat, _previewSettings.SourceCodeWrapText, _previewSettings.SourceCodeStickyScroll, _previewSettings.SourceCodeFontSize));
|
||||
|
||||
Reference in New Issue
Block a user