On Tue, Dec 28, 2010 at 01:38:42PM -0600, Benjamin Slade wrote:
> Emacs html-helper-mode is nice for editing rich formatted messages. However, I
> don't seem to be summon the external editor in my Gmail messages: I get the
> message "Element is not a text field".  Is there a way to add an exception for
> Gmail so that that rich formatted messages can be edited in the external
> editor? (I was used to be able to do this with Pentadactyl/Vimperator).


Give this a whirl.. Also, to anybody else reading this mailing list, help
in testing would be much appreciated.  If I succeeded in not breaking
anything, then I'll patch the program with this change after a short
period of testing.


///begin code
function edit_field_in_external_editor (buffer, elem, doc) {
    if (! doc) {
        if (elem instanceof Ci.nsIDOMHTMLInputElement) {
            var type = (elem.getAttribute("type") || "").toLowerCase();
            if (type == "hidden" || type == "checkbox" || type == "radio")
                throw interactive_error("Element is not a text field.");
        } else if (!(elem instanceof Ci.nsIDOMHTMLTextAreaElement))
            throw interactive_error("Element is not a text field.");
    }

    var name = get_filename_for_current_textfield(buffer.document, elem);
    var file = get_temporary_file(name);

    if (elem instanceof Ci.nsIDOMHTMLInputElement ||
        elem instanceof Ci.nsIDOMHTMLTextAreaElement)
    {
        var content = elem.value;
    } else {
        content = elem.innerHTML;
    }

    // Write to file
    try {
        write_text_file(file, content);
    } catch (e) {
        file.remove(false);
        throw e;
    }

    // FIXME: decide if we should do this
    var old_class = elem.className;
    elem.className = "__conkeror_textbox_edited_externally " + old_class;

    try {
        yield open_file_with_external_editor(file);
        content = read_text_file(file);
        if (elem instanceof Ci.nsIDOMHTMLInputElement ||
            elem instanceof Ci.nsIDOMHTMLTextAreaElement)
        {
            elem.value = content;
        } else {
            elem.innerHTML = content;
        }
    } finally {
        elem.className = old_class;

        file.remove(false);
    }
}

interactive("edit-current-field-in-external-editor",
    "Edit the contents of the currently-focused text field in an external 
editor.",
    function (I) {
        var b = I.buffer;
        var e = b.focused_element;
        var frame = b.focused_frame;
        var doc = null;
        if (e) {
            if (e.getAttribute("contenteditable") == 'true')
                doc = e.ownerDocument;
        } else if (frame && frame.document.designMode &&
                   frame.document.designMode == "on") {
            doc = frame.document;
            e = frame.document.body;
        }
        yield edit_field_in_external_editor(b, e, doc);
        e.blur();
    });
///end code

-- 
John Foerch
_______________________________________________
Conkeror mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/conkeror

Reply via email to