From aaf06fc7e97b68605037d843fdd96fa5bd94d0de Mon Sep 17 00:00:00 2001 From: Nicolas Badia Date: Sat, 4 Feb 2017 14:04:12 +0100 Subject: [PATCH 1/2] Insert at the end if there is no range at all --- views/wysiwyg_editor_view.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/views/wysiwyg_editor_view.js b/views/wysiwyg_editor_view.js index 18c759a..5f02c65 100644 --- a/views/wysiwyg_editor_view.js +++ b/views/wysiwyg_editor_view.js @@ -552,6 +552,12 @@ SC.WYSIWYGEditorView = SC.View.extend({ var sel = this.getSelection(), range; + // If there is no range, we add the html at the end of the editor. + // This may be usefull when inserting images. + if (!sel.rangeCount) { + this.setCaretAtEditorEnd(); + } + if (sel.getRangeAt && sel.rangeCount) { // If any text is selected, remove it. range = sel.getRangeAt(0); From f21249822727ed5ea53ed8c0b8a2bd748a6f684c Mon Sep 17 00:00:00 2001 From: Nicolas Badia Date: Sat, 4 Feb 2017 14:06:12 +0100 Subject: [PATCH 2/2] Prevent crashing the app if the HTML update fail --- views/wysiwyg_editor_view.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/views/wysiwyg_editor_view.js b/views/wysiwyg_editor_view.js index 5f02c65..9cb8d86 100644 --- a/views/wysiwyg_editor_view.js +++ b/views/wysiwyg_editor_view.js @@ -302,7 +302,12 @@ SC.WYSIWYGEditorView = SC.View.extend({ _doUpdateValue: function() { var value = this.get('value') || ''; - this.$inner.html(value); + try { + this.$inner.html(value); + } + catch(e) { + SC.Logger.error('Error while updating the rich text editor content: '+e.message); + } this.resetUndoStack(); this.updateFrameHeight(); },