From 11d323d8b7a63a3348956cba3dd75fe4e7fe6eec Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Tue, 1 May 2018 21:13:17 +0100 Subject: [PATCH] Electron: Fixes #479: Currently loaded note was cleared when creating new note --- ElectronClient/app/gui/NoteText.jsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index 7e9f1b7827..e4c393b497 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -215,8 +215,17 @@ class NoteTextComponent extends React.Component { // 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 : ''); + // Note: calling undoManager.reset() doesn't work + try { + this.editor_.editor.getSession().setValue(note ? note.body : ''); + } catch (error) { + if (error.message === "Cannot read property 'match' of undefined") { + // The internals of Ace Editor throws an exception when creating a new note, + // but that can be ignored. + } else { + console.error(error); + } + } this.editor_.editor.clearSelection(); this.editor_.editor.moveCursorTo(0,0); }