From 20972a67c3c4cf6c794e2a52cf6d1028712bbc8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Sat, 2 Jan 2016 23:14:54 -0800 Subject: [PATCH] Skip non-editable editors Fixes #163. --- content/frame.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/content/frame.js b/content/frame.js index 7e19f45..654beb2 100644 --- a/content/frame.js +++ b/content/frame.js @@ -209,27 +209,29 @@ function Sandbox(principal) { * @returns {object} The associated nsIEditor instance. */ function getEditor(el) { - if (!el) return undefined; + if (!el) return null; + let editor; try { - return el.QueryInterface(Ci.nsIDOMNSEditableElement).editor; + editor = el.QueryInterface(Ci.nsIDOMNSEditableElement).editor; } catch (e) {} try { - return el.QueryInterface(Ci.nsIEditor).editor; + editor = editor || el.QueryInterface(Ci.nsIEditor).editor; } catch (e) {} try { - // http://osdir.com/ml/mozilla.devel.editor/2004-10/msg00017.html - let webNavigation = el.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation); - let editingSession = webNavigation - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIEditingSession); - return editingSession.getEditorForWindow(el); + if (!editor) { + // http://osdir.com/ml/mozilla.devel.editor/2004-10/msg00017.html + let webNavigation = el.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation); + let editingSession = webNavigation + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIEditingSession); + return editingSession.getEditorForWindow(el); + } } catch (e) {} -// dump("AVIM.getEditor -- couldn't get editor: " + e + "\n"); // debug - return undefined; + return editor.isDocumentEditable ? editor : null; } /** @@ -267,7 +269,7 @@ function SpliceTxn(outer, node, pos, len, repl) { this.shiftSelection = function(numChars) { let editor = getEditor(outer); let sel = editor && editor.selection; - sel.collapse(this.node, this.startOffset + numChars); + if (sel) sel.collapse(this.node, this.startOffset + numChars); }; /**