-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Test case for ioob (and some code cleanup) #10399
Conversation
Comment was NOT matching the code (it was the other way round)
Co-authored-by: Christoph <siedlerkiller@gmail.com>
package org.jabref.gui.maintable; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck> reported by reviewdog 🐶
Unused import - java.util.stream.Collectors.
import java.util.stream.Collectors; | ||
|
||
import javafx.beans.InvalidationListener; | ||
import javafx.beans.Observable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck> reported by reviewdog 🐶
Unused import - javafx.beans.Observable.
import javafx.beans.property.IntegerProperty; | ||
import javafx.beans.property.SimpleIntegerProperty; | ||
import javafx.beans.property.SimpleObjectProperty; | ||
import javafx.beans.value.ObservableValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck> reported by reviewdog 🐶
Unused import - javafx.beans.value.ObservableValue.
import com.tobiasdiez.easybind.EasyBind; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck> reported by reviewdog 🐶
Using the '.' form of import should be avoided - org.junit.jupiter.api.Assertions..
Your code currently does not meet JabRef's code guidelines. The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR. Please carefully follow the setup guide for the codestyle. Afterwards, please run checkstyle locally and fix the issues. More information on code quality in JabRef is available at https://devdocs.jabref.org/getting-into-the-code/development-strategy.html. |
@@ -65,8 +65,7 @@ public void bindToEntry(BibEntry entry) { | |||
fieldBinding, | |||
newValue -> { | |||
if (newValue != null) { | |||
// Controlsfx uses hardcoded \n for multiline fields, but JabRef stores them in OS Newlines format | |||
String oldValue = entry.getField(field).map(value -> value.replace(OS.NEWLINE, "\n").trim()).orElse(null); | |||
String oldValue = entry.getField(field).map(String::trim).orElse(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source field always uses \n as separator internally. We need this check to prevent the change detection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source field always uses \n as separator internally.
I saw it in the debugger.
Therefore
value.replace(OS.NEWLINE, "\n")
is a no-op.
Reason:
Let's split up the cases.
- OS.NEWLINE is
\r\n
. Since "**always uses \n **" is true,\r\n
is never matched. So no replacement is made - OS.NEWLINE is
\n
. Since "**always uses \n **" is true,\n
is replaced by\n
. It is replaced by the same character. The identity. Thus, no change.
Did I miss something?
Side note: During the file write, the newlines are now normalized. The whole file does have the same newline separator. It came in with #8238.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we have to compare old entry and new Entry.
New entry is what controlsfx uses.
Old Entry however is what comes from the stored bib file, might have had OS.Newline -> Replaced with \n and compare with new entry from source tab so that we don't create a diff "database changed"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I kept the trim
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but that does not unify OS.newline
- If I have a bib file with OS.newline chars e.-g \r\n and now I change the bibtex source -> This will trigger a change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG. Thus, if you open the attached file (CRLF terminators), go into the comment field, the cursor will jump?
I now hard-coded CRLF in the code (instead of relying on OS.Newline)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why we replace the chars.
// A file may be loaded using CRLF. ControlsFX uses hardcoded \n for multiline fields. | ||
// Normalizing is done during writing of the .bib file (see org.jabref.logic.exporter.BibWriter.BibWriter). | ||
// Thus, we need to normalize the line endings. | ||
String oldValue = entry.getField(field).map(value -> value.replace("\r\n", "\n").trim()).orElse(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OS.Newline please as mac only uses \r
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought, that was Mac OS 9 and earlier: Source https://stackoverflow.com/a/13295575/873282. Mac OS 9 was EOL in 2001.
More sources: https://de.wikipedia.org/wiki/Zeilenvorschub#Computer links to https://de.wikipedia.org/wiki/Mac_OS_(Classic) for \r
as line separator.
Please double check if we really need to support \r
. I would really consider it being outdated!
My case illustrated by crlf.bib
is as follows:
- A Windows user edits a file using their favourit editor.
- The editor stores CRLF
- The file is sent to a Linux user
- The Linux user opens the file and positions the cursor in the comment field
- Autosave triggers
- Cursor moves (this is described in the comments why we need these checks)
If I do not overlook something: OS.Newline
does not help: OS.Newline is \n
on Linux. The file uses \r\n
(because it was created on Windows). - In other words: OS.Newline is dependent on the current operating system and not on the operating system the .bib file was created.
I could route through org.jabref.model.database.BibDatabase#getNewLineSeparator
to org.jabref.gui.fieldeditors.AbstractEditorViewModel#bindToEntry
. This seems to be too much effort for the gain that \r\n
is supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but Excel export to CSV still uses CR. :-P
W.T.F...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: https://answers.microsoft.com/en-us/msoffice/forum/all/csv-line-endings/2b4eedaf-22ef-4091-b7dc-3317303d2f71
In case we ever encounter this, we can use git magic to auto-fix: https://nicercode.github.io/blog/2013-04-30-excel-and-line-endings/
|
The build for this PR is no longer available. Please visit https://builds.jabref.org/main/ for the latest build. |
Co-authored-by: Christoph <siedlerkiller@gmail.com>
This adds
src/test/java/org/jabref/gui/maintable/MainTableDataModelTest
for checking that in a "controlled" environment, all listeners are installed correctly. - It is a copy of the UI code. However, in JabRef, the UI does not behave the same.While I was on it, some minor code improvements were made.
Follow up to #10389
More things added
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)