From f21a5402610f5f06978a5984b02aeb563ac20deb Mon Sep 17 00:00:00 2001 From: calixtus Date: Tue, 26 May 2020 18:26:47 +0200 Subject: [PATCH 1/4] Added check for different value --- .../jabref/gui/fieldeditors/AbstractEditorViewModel.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java index 167392c8515..22306c2e40f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java @@ -64,9 +64,11 @@ public void bindToEntry(BibEntry entry) { newValue -> { if (newValue != null) { String oldValue = entry.getField(field).orElse(null); - entry.setField(field, newValue); - UndoManager undoManager = JabRefGUI.getMainFrame().getUndoManager(); - undoManager.addEdit(new UndoableFieldChange(entry, field, oldValue, newValue)); + if (!newValue.equals(oldValue)) { + entry.setField(field, newValue); + UndoManager undoManager = JabRefGUI.getMainFrame().getUndoManager(); + undoManager.addEdit(new UndoableFieldChange(entry, field, oldValue, newValue)); + } } }); } From 122b746e540b03b88a74759491c671ca70edbc46 Mon Sep 17 00:00:00 2001 From: calixtus Date: Thu, 28 May 2020 13:48:35 +0200 Subject: [PATCH 2/4] Added trim to check --- .../gui/fieldeditors/AbstractEditorViewModel.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java index 22306c2e40f..a8d1fb7632e 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java @@ -63,12 +63,13 @@ public void bindToEntry(BibEntry entry) { fieldBinding, newValue -> { if (newValue != null) { - String oldValue = entry.getField(field).orElse(null); - if (!newValue.equals(oldValue)) { - entry.setField(field, newValue); - UndoManager undoManager = JabRefGUI.getMainFrame().getUndoManager(); - undoManager.addEdit(new UndoableFieldChange(entry, field, oldValue, newValue)); - } + entry.getField(field).ifPresent(oldValue -> { + if (!(newValue.trim()).equals(oldValue.trim())) { + entry.setField(field, newValue); + UndoManager undoManager = JabRefGUI.getMainFrame().getUndoManager(); + undoManager.addEdit(new UndoableFieldChange(entry, field, oldValue, newValue)); + } + }); } }); } From 8bcc65b4979526cc762be4e054930099ddeee4d1 Mon Sep 17 00:00:00 2001 From: calixtus Date: Thu, 28 May 2020 14:48:31 +0200 Subject: [PATCH 3/4] Fixed trim, added comment --- .../fieldeditors/AbstractEditorViewModel.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java index a8d1fb7632e..e113c83c4c9 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java @@ -22,6 +22,7 @@ import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator; import de.saxsys.mvvmfx.utils.validation.ValidationMessage; import de.saxsys.mvvmfx.utils.validation.Validator; +import org.apache.commons.lang3.StringUtils; import org.controlsfx.control.textfield.AutoCompletionBinding; public class AbstractEditorViewModel extends AbstractViewModel { @@ -63,13 +64,15 @@ public void bindToEntry(BibEntry entry) { fieldBinding, newValue -> { if (newValue != null) { - entry.getField(field).ifPresent(oldValue -> { - if (!(newValue.trim()).equals(oldValue.trim())) { - entry.setField(field, newValue); - UndoManager undoManager = JabRefGUI.getMainFrame().getUndoManager(); - undoManager.addEdit(new UndoableFieldChange(entry, field, oldValue, newValue)); - } - }); + String oldValue = entry.getField(field).orElse(null); + + // Autosave and save action trigger the entry editor to reload the fields, so we have to + // check for changes here, otherwise the cursor position is annoyingly reset every few seconds + if (!(newValue.trim()).equals(StringUtils.trim(oldValue))) { + entry.setField(field, newValue); + UndoManager undoManager = JabRefGUI.getMainFrame().getUndoManager(); + undoManager.addEdit(new UndoableFieldChange(entry, field, oldValue, newValue)); + } } }); } From 5be3cbedab0194f0e9c0a16b808d46f50253f993 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 11 Jul 2020 19:34:16 +0200 Subject: [PATCH 4/4] Prevent cursor jumping and maybe also library changed by comparing without new lines --- .../org/jabref/gui/fieldeditors/AbstractEditorViewModel.java | 5 +++-- .../java/org/jabref/model/cleanup/FieldFormatterCleanup.java | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java index e113c83c4c9..064b8808bdf 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/AbstractEditorViewModel.java @@ -14,6 +14,7 @@ import org.jabref.gui.util.BindingsHelper; import org.jabref.logic.integrity.FieldCheckers; import org.jabref.logic.integrity.ValueChecker; +import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.Field; @@ -64,8 +65,8 @@ public void bindToEntry(BibEntry entry) { fieldBinding, newValue -> { if (newValue != null) { - String oldValue = entry.getField(field).orElse(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")).orElse(null); // Autosave and save action trigger the entry editor to reload the fields, so we have to // check for changes here, otherwise the cursor position is annoyingly reset every few seconds if (!(newValue.trim()).equals(StringUtils.trim(oldValue))) { diff --git a/src/main/java/org/jabref/model/cleanup/FieldFormatterCleanup.java b/src/main/java/org/jabref/model/cleanup/FieldFormatterCleanup.java index 61f26317501..9c1bb12493f 100644 --- a/src/main/java/org/jabref/model/cleanup/FieldFormatterCleanup.java +++ b/src/main/java/org/jabref/model/cleanup/FieldFormatterCleanup.java @@ -7,6 +7,7 @@ import java.util.Objects; import java.util.Set; +import org.jabref.logic.formatter.bibtexfields.NormalizeNewlinesFormatter; import org.jabref.model.FieldChange; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.event.EntriesEventSource; @@ -56,6 +57,9 @@ private List cleanupSingleField(Field fieldKey, BibEntry entry) { // Run formatter String newValue = formatter.format(oldValue); + if (formatter instanceof NormalizeNewlinesFormatter) { + newValue = oldValue; + } if (oldValue.equals(newValue)) { return Collections.emptyList();