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

fixed 4365 put html in clipboard #4519

Merged
merged 2 commits into from
Dec 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/main/java/org/jabref/gui/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
import com.google.common.eventbus.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
* Displays an BibEntry using the given layout format.
Expand Down Expand Up @@ -351,7 +354,14 @@ public void close() {
}

private void copyPreviewToClipBoard() {
String previewContent = (String) previewView.getEngine().executeScript("document.documentElement.outerHTML");
clipBoardManager.setContent(previewContent);
}
StringBuilder previewContent = new StringBuilder();
Copy link
Member

Choose a reason for hiding this comment

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

So the java documentation tells us

Because multiple representations of the same data may exist on the clipboard, and because different applications have different capabilities for handling different content types, it is important to place as many data representations on the clipboard as is practical to facilitate external applications.

Thus, I would propose to add the html as well as the cleaned text to the clipboard:

     ClipboardContent content = new ClipboardContent();
     content.putString(previewContent.toString());
     content.putHtml(the html content as it was before);
     clipBoardManager.setContent(content);

Document document = previewView.getEngine().getDocument();
NodeList nodeList = document.getElementsByTagName("*");

for (int i = 0; i < nodeList.getLength(); i++) {
Element element = (Element) nodeList.item(i);
previewContent.append(element.getNodeValue()).append("\n");
}

clipBoardManager.setContent(previewContent.toString()); }
}