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 'copy key and link' #6871

Merged
merged 8 commits into from Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS
Expand Up @@ -119,6 +119,7 @@ Ethan Harris
Fabian Bauer
Fabian Bieker
Fabiani Giovanni
Fabio Marcos
Fabrice Dessaint
Fancy Zhang
Fedor Bezrukov
Expand Down Expand Up @@ -278,6 +279,7 @@ Nikita Borovikov
Niklas Schmitt
nikmilpv
NikodemKch
Nikolaus Koopmann
Nils Streijffert
Niv Ierushalmi
Nivedha Sunderraj
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -30,6 +30,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where the `.sav` file was not deleted upon exiting JabRef. [#6109](https://github.com/JabRef/jabref/issues/6109)
- We fixed a linked identifier icon inconsistency. [#6705](https://github.com/JabRef/jabref/issues/6705)
- We fixed the wrong behavior that font size changes are not reflected in dialogs. [#6039](https://github.com/JabRef/jabref/issues/6039)
- We fixed the failure to Copy citation key and link. [#5835](https://github.com/JabRef/jabref/issues/5835)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/edit/CopyMoreAction.java
Expand Up @@ -224,7 +224,7 @@ private void copyKeyAndLink() {
keyAndLink.append(OS.NEWLINE);
}

clipBoardManager.setHtmlContent(keyAndLink.toString());
clipBoardManager.setContent(keyAndLink.toString());
Copy link
Member

Choose a reason for hiding this comment

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

This really puts the html string into the clipboard, so if you paste it into say notepad you get <a href="url">key</a>. Instead, its better to add the html, and in addition also a fallback string of the format key - url. In this way, you get the desired behavior also when you paste in applications that do understand html (e.g onenote).

In order for this to work, you probably need to add a second fallback argument to

public void setHtmlContent(String html) {
final ClipboardContent content = new ClipboardContent();
content.putHtml(html);
clipboard.setContent(content);
setPrimaryClipboardContent(content);
}

which is then added to the ClipboardContent via putString.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @tobiasdiez !
Ah ok that makes sense.. I guess I should have looked deeper into what setHtmlContent() actually does.. I assumed it would be applicable for url's on their own only. So that means, both, setContent() and setHtmlContent() should be called?
Sorry for my noobness! This was my first open-source contribution ever :D
Can I fix the issue tonight (German time) and commit the changes?
thanks,
Niko

Copy link
Member

Choose a reason for hiding this comment

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

No worries, you were on the right track. Calling setContent and setHtmlContent is the right idea, but I suspect that this will push two different clipboard items. Instead, the setHtmlContent should be modified as follows:

public void setHtmlContent(String html, String fallbackPlain) { 
     final ClipboardContent content = new ClipboardContent(); 
     content.putHtml(html);
     content.putString(fallbackPlain);
     clipboard.setContent(content); 
     setPrimaryClipboardContent(content); 
 }

This should add one clipboard item, containing both the html as well as the normal string. (I hope)

Let me know if you encounter any further questions. There is not such a thing as noobness. We all can learn more. And learning in a relaxed environment is one of the main points of open source, so don't worry. Happy coding!

Copy link
Contributor Author

@PremKolar PremKolar Sep 5, 2020

Choose a reason for hiding this comment

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

but I suspect that this will push two different clipboard items.

That was exactly my next thought :)
Ok, I will try..
Thanks for the kind words!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alright, i hope i did what you meant. I have to say, I still don't understand why copyKeyAndLink() creates html content for the clipboard, but e.g. copyKeyAndTitle() does not?
cheers,
Niko


if (entriesWithKey.size() == entries.size()) {
// All entries had keys.
Expand Down