Skip to content

add selection copy to preview window#7421

Merged
Siedlerchr merged 3 commits into
JabRef:masterfrom
tmrd993:add-selection-copy-to-preview
Feb 5, 2021
Merged

add selection copy to preview window#7421
Siedlerchr merged 3 commits into
JabRef:masterfrom
tmrd993:add-selection-copy-to-preview

Conversation

@tmrd993

@tmrd993 tmrd993 commented Feb 4, 2021

Copy link
Copy Markdown
Contributor

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.


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

Copy link
Copy Markdown
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.

@tmrd993 tmrd993 Feb 5, 2021

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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.

@tobiasdiez tobiasdiez left a comment

Copy link
Copy Markdown
Member

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

@Siedlerchr Siedlerchr left a comment

Copy link
Copy Markdown
Member

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