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

Solved #3823 File annotation #4246

Merged
merged 7 commits into from
Aug 3, 2018
Merged

Solved #3823 File annotation #4246

merged 7 commits into from
Aug 3, 2018

Conversation

upupming
Copy link
Contributor

@upupming upupming commented Aug 2, 2018

This pull request solved #3823, and improved the new line remover.

Removed hyphens and newlines of highlighted text

I removed all new lines which don't have preceded . or : becaues I think . or : is often used to start a new paragraph.

Test text:

Test result:

There is another problem with the regular expression (\r?\n|\r) when I try to use (?<![.|:])(\r?\n|\r) for excluding the new line end with . or :.

If it's on Windows, the \r\n will be replaced with a whitespace, and it is OK. However if we encounter .\r\n, the .\r will be reserved and the \n will be replaced by a whitespace. In this way, the .\r will not be shown as new line int the field, and we don't need this whitespace. So instead we should change .\r\n to \r\n directly.

So I use java's %n to distinguish new line wisely.

Font size of summary on the left changed to 10px

Summary text wrapped

The Final example:


  • Change in CHANGELOG.md described
  • Tests created for changes
  • Manually tested changed features in running JabRef
  • Screenshots added in PR description (for bigger UI changes)
  • Ensured that the git commit message is a good one
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)

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 a lot for your contribution. It is a real joy to review a PR that is so well documented and explained! The code is also fine and I've only a few minor comments. It would be nice if you could add a unit test, too.

@@ -10,7 +10,8 @@
* Removes all hyphenated line breaks in the string.
*/
public class RemoveHyphenatedNewlinesFormatter extends Formatter {
private static final Pattern HYPHENATED_WORDS = Pattern.compile("(-\r\n|-\n|-\r)");
private static final String newLine = String.format("%n");
private static final Pattern HYPHENATED_WORDS = Pattern.compile("(-" + newLine + ")");
Copy link
Member

Choose a reason for hiding this comment

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

You can also use \R to match any line breaks, see https://docs.oracle.com/javase/9/docs/api/java/util/regex/Pattern.html.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, it is what I didn't know before. But it seems \R will match any of \r, \n and \r\n.
image
In this example, you can see \r is matched on Windows. But we need only match \r\n on Windows, so I think %n is the right choice.

CHANGELOG.md Outdated
@@ -27,6 +27,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Window state is saved on close and restored on start.
- Files without a defined external file type are now directly opened with the default aplication of the operating system
- We streamlined the process to rename and move files by removing the confirmation dialogs.
- We removed the redundant new lines of marking and wrapped the summary in File annotation tab.
Copy link
Member

Choose a reason for hiding this comment

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

Slightly better: We removed the redundant new lines of markings and wrapped the summary in the File annotation tab.

Please also add a reference to the issue #3823 (cf. e.g. some of the changelog entries under "fixed").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -94,12 +94,14 @@ private Node createFileAnnotationNode(FileAnnotationViewModel annotation) {
Label date = new Label(annotation.getDate());
Label page = new Label(Localization.lang("Page") + ": " + annotation.getPage());

marking.setStyle("-fx-font-weight: bold");
marking.setStyle("-fx-font-size: 10px; -fx-font-weight: bold");
Copy link
Member

Choose a reason for hiding this comment

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

Please specify the font-size in em so that it scales properly if the base font size is changed (e.g. on high res displays).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to 0.75em

this.marking.set(annotationContent.isEmpty() ? illegibleTextMessage : annotationContent);
String markingContent = (annotationContent.isEmpty() ? illegibleTextMessage : annotationContent);
// remove newlines && hyphens before linebreaks
markingContent = new RemoveHyphenatedNewlinesFormatter().format(markingContent);
Copy link
Member

Choose a reason for hiding this comment

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

It is good that you try to reuse existing logic, i.e. the existing formatters. However, these are also used to generate the bibtex key (and file name). For these use cases, it is still desired to remove all line breaks. Thus, I would prefer if you define the modified regex pattern to remove the linebreaks here in this class and leave the RemoveNewlinesFormatter untouched (except changing the pattern to use \R).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I leave the two formatter untouched and only use the pattern in this scope.

// remove newlines && hyphens before linebreaks
markingContent = new RemoveHyphenatedNewlinesFormatter().format(markingContent);
markingContent = new RemoveNewlinesFormatter().format(markingContent);
this.marking.set(markingContent);
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if you could add some tests verifying the new behavior: create a FileAnnotion object by hand (not by parsing a pdf) which contains such problematic hyphens/newlines and check that they are removed, indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your advice, I have added a unit test!

@upupming
Copy link
Contributor Author

upupming commented Aug 2, 2018

@tobiasdiez Thanks for your review! I will fix them soon.

@upupming
Copy link
Contributor Author

upupming commented Aug 3, 2018

Hi, I reverted the change for RemoveHyphenatedNewlinesFormatter and RemoveNewlinesFormatter. I have also fixed the tooltip for marking summary.

Before

After

Now I'm going to add some unit tests!

@upupming
Copy link
Contributor Author

upupming commented Aug 3, 2018

All done~ 😃

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.

Thank you very much for your contribution! It's really nice to see such a wonderful documented PR. Code wise lgtm!

assertEquals("water", formatter.format("wa-\nter"));
assertEquals("water", formatter.format("wa-\r\nter"));
assertEquals("water", formatter.format("wa-\rter"));
String newLine = String.format("%n");
Copy link
Member

@tobiasdiez tobiasdiez Aug 3, 2018

Choose a reason for hiding this comment

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

Please keep these tests (here and below). The text that we want to format might contain linux line endings on Windows and vice versa. But you can of course also add a tests for ̀%n.
Please change also all regex patterns to use \R instead of %n for newlines.

Copy link
Contributor Author

@upupming upupming Aug 3, 2018

Choose a reason for hiding this comment

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

Finally leaving original formatter and tests untouched.

In summary, Pattern.compile("...") changed from (\r?\n|\r) to \\R, but the effects are same.

@tobiasdiez tobiasdiez merged commit 611ac55 into JabRef:master Aug 3, 2018
@tobiasdiez
Copy link
Member

Thanks for the quick follow-up! Looking forward to your next PR ;)

Siedlerchr added a commit that referenced this pull request Aug 8, 2018
…tive

* upstream/master:
  Update dependencies (#4251)
  Fix author list parser (#4169) (#4248)
  Solved #3823 File annotation (#4246)
  Fix importer vulnerability (#4240)
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.

None yet

3 participants