Hi

First, the usual stuff: running Firefox off branch MOZILLA_1_8_0, i.e. somewhere between 1.5.0.3 and 1.5.0.4 for the debug build. Same result on precompiled 1.5.0.4.

My problem is that I always get a NS_ERROR_NOT_INITIALIZED exception when I try to add text to a dynamically generated <editor> (for the test case, see below). Alas, this is what my debug build tells me after I click the button which triggers the text insertion:

###!!! ASSERTION: bad action nesting!: 'mActionNesting>0', file /Users/awuest-devel/Documents/devel/src/mozilla/trees/MOZILLA_1_8_0_BRANCH/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp, line 386 Break: at file /Users/awuest-devel/Documents/devel/src/mozilla/trees/MOZILLA_1_8_0_BRANCH/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp, line 386 ###!!! ASSERTION: zero or negative placeholder batch count when ending batch!: 'mPlaceHolderBatch > 0', file /Users/awuest-devel/Documents/devel/src/mozilla/trees/MOZILLA_1_8_0_BRANCH/mozilla/editor/libeditor/base/nsEditor.cpp, line 919 Break: at file /Users/awuest-devel/Documents/devel/src/mozilla/trees/MOZILLA_1_8_0_BRANCH/mozilla/editor/libeditor/base/nsEditor.cpp, line 919 JavaScript error: , line 0: uncaught exception: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIPlaintextEditor.insertText]" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: chrome://test/content/controller-test.js :: addText :: line 58" data: no]


Now, to the test case. If I embed the editor directly in my XUL file, everything works flawlessly:

editor-test.xul:
----------------

<window id="uiEditorWindow"
        orient="horizontal"
        align="stretch"
        onload="initEditor()"

xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";>

<script type="application/x-javascript" src="chrome://test/content/controller-test.js"/>

  <button label="Add Text" oncommand="addText()"/>
<editor id="uiEditor" type="content" flex="1" style="border: 2px solid black; margin: 2px 2px 2px 2px;" onload="event.stopPropagation();"/>
</window>


controller-test.js:
-------------------
var gEditor = null;

function initEditor() {
    var editorElem               = null;

    // set up
    editorElem = document.getElementById("uiEditor");
    editorElem.makeEditable("text", false);

    gEditor = editorElem.getEditor(editorElem.contentWindow);
    gEditor.QueryInterface(Components.interfaces.nsIPlaintextEditor);

editorElem.contentWindow.addEventListener("keypress", function (event) { event.preventBubble(); }, true);

dump("editorElem status = \"" + editorElem.editingSession.editorStatus + "\"\n");
}

function addText() {
    gEditor.insertText("Hello?");
}

As soon as I generate the editor dynamically, the error mentioned above occurrs, and no text is inserted (nor is it possible to add text via typing).

editor-test.xul:
----------------

<window id="uiEditorWindow"
        orient="horizontal"
        align="stretch"
        onload="initEditor()"

xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";>

<script type="application/x-javascript" src="chrome://test/content/controller-test.js"/>

  <button label="Add Text" oncommand="addText()"/>
</window>


controller-test.js:
-------------------

var gEditor = null;

function initEditor() {
    // test dynamic tab insertion
    var editorWindow             = null;
    var editorElem               = null;

editorElem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";, "editor");
    editorElem.setAttribute("type", "content");
    editorElem.setAttribute("flex", "1");
editorElem.setAttribute("style", "border: 2px solid black; margin: 2px 2px 2px 2px;");
    editorElem.setAttribute("onload", "event.stopPropagation()");

    editorWindow = document.getElementById("uiEditorWindow");
    editorWindow.appendChild(editorElem);

    // set up
    editorElem.makeEditable("text", false);

    gEditor = editorElem.getEditor(editorElem.contentWindow);
    gEditor.QueryInterface(Components.interfaces.nsIPlaintextEditor);

editorElem.contentWindow.addEventListener("keypress", function (event) { event.preventBubble(); }, true);

dump("editorElem status = \"" + editorElem.editingSession.editorStatus + "\"\n");
}

function addText() {
    gEditor.insertText("Hello?");
}

I hope somebody could give me a pointer on what I am doing wrong. I have a suspicion it might be related to a command controller, but I am not sure (nor how I would add one which implements insertText, because, with what exactly should I implement it, and anyway, with a static editor, it all works fine!).

--
Kind regards,
Andi
_______________________________________________
dev-tech-editor mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-editor

Reply via email to