Skip to content

Commit

Permalink
Electron: Fixes #355: Set undo state properly when loading new note
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed May 1, 2018
1 parent 62e91c4 commit 4cf5525
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ElectronClient/app/gui/NoteText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,13 @@ class NoteTextComponent extends React.Component {
}

if (this.editor_) {
const session = this.editor_.editor.getSession();
const undoManager = session.getUndoManager();
undoManager.reset();
session.setUndoManager(undoManager);
// Calling setValue here does two things:
// 1. It sets the initial value as recorded by the undo manager. If we were to set it instead to "" and wait for the render
// phase to set the value, the initial value would still be "", which means pressing "undo" on a note that has just loaded
// would clear it.
// 2. It resets the undo manager - fixes https://github.com/laurent22/joplin/issues/355
// Note: calling undoManager.reset() doesn't work
this.editor_.editor.session.setValue(note ? note.body : '');
this.editor_.editor.clearSelection();
this.editor_.editor.moveCursorTo(0,0);
}
Expand Down

0 comments on commit 4cf5525

Please sign in to comment.