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

Fix using copy/paste from a menu in electron. #13220

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

tsmaeder
Copy link
Contributor

What it does

The fix is to replace a old test for whether we run on electron with on that works on current electron.

Fixes #12487

Contributed on behalf of STMicroelectronics

How to test

Start Theia Electron and make sure that copy/pasting from a menu actually works (for example in the terminal or in the editor)

Follow-ups

Review checklist

Reminder for reviewers

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
Copy link
Contributor

@martin-fleck-at martin-fleck-at left a comment

Choose a reason for hiding this comment

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

Changes look good to me and solve the original problem, thank you Thomas! From what I understand the isNative flag was really just introduced for the copy/paste scenario to distinguish between the Electron and the Browser case (see here) but who can say for sure ;-) Anyway, great work and I just left two comments regarding the browser API that we can probably skip for now.

// Chrome incorrectly returns true for document.queryCommandSupported('paste')
// when the paste feature is available but the calling script has insufficient
// privileges to actually perform the action
export const supportPaste = browser.isNative || (!browser.isChrome && document.queryCommandSupported('paste'));
export const supportPaste = environment.electron.is() || (!browser.isChrome && document.queryCommandSupported('paste'));
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -351,12 +351,12 @@ export namespace CommonCommands {
});
}

export const supportCut = browser.isNative || document.queryCommandSupported('cut');
export const supportCopy = browser.isNative || document.queryCommandSupported('copy');
export const supportCut = environment.electron.is() || document.queryCommandSupported('cut');
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to note it down somewhere cause I quickly looked into it: queryCommandSupported is officially deprecated but still supported in all major browsers. From what I gather, we could use the Clipboard API as an alternative.

@tsmaeder tsmaeder merged commit aeee293 into eclipse-theia:master Jan 4, 2024
14 checks passed
@tsmaeder
Copy link
Contributor Author

tsmaeder commented Jan 4, 2024

Using the browser copy/paste commands is not really what we want: we want to react differently depending on the source/target of the paste: for example, "paste" will always paste into the widget with keyboard focus even though the active widget might be the Navigator, for example. There is a related issue talking about the Terminal, for example: #10724

@jfaltermeier jfaltermeier added this to the 1.46.0 milestone Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
3 participants