Solved #3823 File annotation#4246
Conversation
tobiasdiez
left a comment
There was a problem hiding this comment.
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.
| 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 + ")"); |
There was a problem hiding this comment.
You can also use \R to match any line breaks, see https://docs.oracle.com/javase/9/docs/api/java/util/regex/Pattern.html.
| - 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. |
There was a problem hiding this comment.
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").
| 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"); |
There was a problem hiding this comment.
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).
| this.marking.set(annotationContent.isEmpty() ? illegibleTextMessage : annotationContent); | ||
| String markingContent = (annotationContent.isEmpty() ? illegibleTextMessage : annotationContent); | ||
| // remove newlines && hyphens before linebreaks | ||
| markingContent = new RemoveHyphenatedNewlinesFormatter().format(markingContent); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thank you for your advice, I have added a unit test!
|
@tobiasdiez Thanks for your review! I will fix them soon. |
|
All done~ 😃 |
Siedlerchr
left a comment
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Finally leaving original formatter and tests untouched.
In summary, Pattern.compile("...") changed from (\r?\n|\r) to \\R, but the effects are same.
|
Thanks for the quick follow-up! Looking forward to your next PR ;) |



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\nwill be replaced with a whitespace, and it is OK. However if we encounter.\r\n, the.\rwill be reserved and the\nwill be replaced by a whitespace. In this way, the.\rwill not be shown as new line int the field, and we don't need this whitespace. So instead we should change.\r\nto\r\ndirectly.So I use java's
%nto distinguish new line wisely.Font size of summary on the left changed to 10px
Summary text wrapped
The Final example: