Skip to content

fix(desktop): fix can not past content on monaco editor #1917

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

Merged
merged 1 commit into from
Apr 2, 2025
Merged

Conversation

ysfscream
Copy link
Member

@ysfscream ysfscream commented Apr 1, 2025

What is the current behavior?

Monaco Editor's clipboard functionality, especially paste, doesn't work properly in Electron environments. The issue occurs because Monaco checks for platform.isWeb before using the clipboard service as a fallback when document.execCommand('paste') fails. Since Electron isn't detected as a web platform (despite running in a Chromium environment), the clipboard functionality fails.

This issue became more critical with Electron, where execCommand('paste') support was dropped entirely, making paste functionality unusable in the Monaco Editor.

Issue Number

Related to microsoft/monaco-editor#4855

What is the new behavior?

This PR adds a patch script that removes the platform.isWeb check in Monaco Editor's clipboard implementation, allowing the clipboard service to be used in Electron environments. The patch is applied automatically after dependency installation.

Specifically:

  • Created a patch-monaco-clipboard.js script that modifies the Monaco clipboard code
  • Updated the postinstall script to run this patch after dependencies are installed
  • Added detailed documentation in the README about the patch and its purpose
  • Added comments in the patched code referencing the original issue

Monaco Editor's paste functionality works properly in MQTTX when running in Electron with this patch.

Does this PR introduce a breaking change?

  • Yes
  • No

Specific Instructions

After merging this PR, anyone who installs dependencies will automatically get the patched version of Monaco Editor. If anyone is experiencing clipboard issues with Monaco Editor in the application, they should run:

yarn

This will reapply the patch and fix the issue.

@ysfscream ysfscream added fix Fix bug or issues dependencies Pull requests that update a dependency file desktop MQTTX Desktop labels Apr 1, 2025
@ysfscream ysfscream added this to the v1.12.0 milestone Apr 1, 2025
@ysfscream ysfscream requested review from Red-Asuka and Copilot April 1, 2025 17:28
@ysfscream ysfscream self-assigned this Apr 1, 2025
@ysfscream ysfscream added this to MQTTX Apr 1, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the clipboard paste functionality in Monaco Editor on Electron by patching the editor's clipboard code. Key changes include:

  • Adding a patch script (patch-monaco-clipboard.js) that removes the platform.isWeb check.
  • Updating the postinstall script to run the patch automatically.
  • Extending the documentation in README.md with details about the patch.

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
scripts/patch-monaco-clipboard.js Removes the platform.isWeb check in Monaco's clipboard code and adds patch comments.
scripts/README.md Documents the patch scripts and their usage for improving clipboard behavior in Electron.
Files not reviewed (1)
  • package.json: Language not supported
Comments suppressed due to low confidence (2)

scripts/patch-monaco-clipboard.js:22

  • [nitpick] The regular expression used for replacing the platform.isWeb check is very strict. Consider using a more flexible pattern (e.g., accommodating variable whitespace) to ensure that changes in formatting do not break the patch.
if (!result && platform.isWeb) {

scripts/patch-monaco-clipboard.js:6

  • [nitpick] The comment references multiple GitHub issues, including an outdated one (1046); consider consolidating the references to focus on the primary relevant issue (microsoft/monaco-editor#4855) to avoid confusion.
 *  - https://github.com/microsoft/monaco-editor/issues/1046

@ysfscream ysfscream moved this to In Progress in MQTTX Apr 1, 2025
@Red-Asuka Red-Asuka merged commit 176719a into main Apr 2, 2025
4 checks passed
@Red-Asuka Red-Asuka deleted the ysf/desktop branch April 2, 2025 01:48
@github-project-automation github-project-automation bot moved this from In Progress to Done in MQTTX Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file desktop MQTTX Desktop fix Fix bug or issues
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants