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

Decode HTML entities when copying text to clipboard (fixes #1850) #1855

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Integral-Tech
Copy link
Contributor

Currently, when using Copy in the context menu, the text will be HTML escaped (e.g. " becomes "). Add a function to decode HTML entities when copying to clipboard.

This PR fixes issue #1850.

@Integral-Tech Integral-Tech changed the title fix: decode HTML entities when copying text to clipboard (fixes #1850) Decode HTML entities when copying text to clipboard (fixes #1850) Jan 9, 2025
…rn#1850)

Currently, when using `Copy` in the context menu, the text will be
HTML escaped (e.g. `"` becomes `"`). Add a function to decode
HTML entities when copying to clipboard.

This PR fixes issue Nheko-Reborn#1850.
void
Clipboard::setHtmlText(QString text)
{
setText(QTextDocumentFragment::fromHtml(text).toPlainText());
Copy link
Member

Choose a reason for hiding this comment

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

The proper solution probably uses setMimeData and QMimeData::setHtml? I also am not sure if we always pass html text as text to the menu. It could be that some of it is actual plain text. We also possibly need to deal with inline images not getting resolved well?

Copy link
Contributor Author

@Integral-Tech Integral-Tech Jan 19, 2025

Choose a reason for hiding this comment

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

I've just tried this code, but it doesn't work:

     QMimeData* mimeData = new QMimeData();
     mimeData->setHtml(text);
     QGuiApplication::clipboard()->setMimeData(mimeData);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants