Skip to content

Commit

Permalink
Fixed trim, added comment
Browse files Browse the repository at this point in the history
  • Loading branch information
calixtus committed May 28, 2020
1 parent 122b746 commit 8bcc65b
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
}
}
});
}
Expand Down

0 comments on commit 8bcc65b

Please sign in to comment.