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

add selection copy to preview window #7421

Merged
merged 3 commits into from
Feb 5, 2021
Merged

add selection copy to preview window #7421

merged 3 commits into from
Feb 5, 2021

Conversation

tmrd993
Copy link
Contributor

@tmrd993 tmrd993 commented Feb 4, 2021

Fixes #6962
Added a feature that allows users to copy highlighted text in the preview window

Screenshot:

100c67ff4e73c1cb3ea8e4385da41cdd

  • Change in CHANGELOG.md described (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked documentation: Is the information available and up to date? If not created an issue at https://github.com/JabRef/user-documentation/issues or, even better, submitted a pull request to the documentation repository.

@@ -224,6 +224,13 @@ public void copyPreviewToClipBoard() {
clipBoardManager.setContent(content);
}

public void copySelectionToClipBoard() {
ClipboardContent content = new ClipboardContent();
content.putString(getSelectionHtmlContent());
Copy link
Member

Choose a reason for hiding this comment

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

We had some problems in the past with rich-text copy & past, i.e. if you copy bold text and past it into say Word.

For this to work you also need to use putHtml as the other methods above. Moreover, the method getSelectionHtmlContent seems to only return the text, not the html, so a better name would be getSelectionTextContent. Getting the html might be a bit more difficult, https://stackoverflow.com/questions/4176923/html-of-selected-text/4177234#4177234 is a starting point but maybe there are also simpler ways in the meantime.

Copy link
Contributor Author

@tmrd993 tmrd993 Feb 5, 2021

Choose a reason for hiding this comment

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

We had some problems in the past with rich-text copy & past, i.e. if you copy bold text and past it into say Word.

For this to work you also need to use putHtml as the other methods above. Moreover, the method getSelectionHtmlContent seems to only return the text, not the html, so a better name would be getSelectionTextContent. Getting the html might be a bit more difficult, https://stackoverflow.com/questions/4176923/html-of-selected-text/4177234#4177234 is a starting point but maybe there are also simpler ways in the meantime.

The JS script above seems to work quite nicely, there is however a downside to it. I don't know if it's intended but it's not extracting html of substrings. For example, if we highlight and copy the title InProceedings (Salm2020), we get <i>InProceedings</i><a name="Salm2020"> (Salm2020)</a>, which is correct. However if we only highlight and copy the part Proceedings we simply get the plaintext Proceedings.

I played around copy & pasting into open office and apart from the limitation above, it works as intended.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for trying it out! That's not perfect, but I would say good enough for most purposes.

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to me.

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Feb 5, 2021
Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

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

Works fine, just tested it! Thanks for adding this very useful feature!

@Siedlerchr Siedlerchr merged commit 00894a3 into JabRef:master Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding simple "Copy" in addition to "Copy preview" to right-click menu of preview
3 participants