Fixed In firefox; Insert code block doesn't select editor text

Xon

Well-known member
Licensed customer
Affected version
xenforo.com
With Froala v4.0.14 on xenforo.com, selecting an entire line text and then inserting a code block triggers this error:
Code:
Uncaught TypeError: d.parentNode.getAttribute is not a function
    d https://xenforo.com/community/js/xf/editor-compiled.js?_v=1c27fdf4:263
    getSelected https://xenforo.com/community/js/xf/editor-compiled.js?_v=1c27fdf4:265
    _afterShow https://xenforo.com/community/js/xf/editor-compiled.js?_v=1c27fdf4:1050
    afterShow https://xenforo.com/community/js/xf/editor-compiled.js?_v=1c27fdf4:1047
    proxy https://xenforo.com/community/js/xf/core-compiled.js?_v=1c27fdf4:72
    f https://xenforo.com/community/js/xf/core-compiled.js?_v=1c27fdf4:118
    e https://xenforo.com/community/js/xf/core-compiled.js?_v=1c27fdf4:119
    setupHtmlInsert https://xenforo.com/community/js/xf/core-compiled.js?_v=1c27fdf4:47
    p https://xenforo.com/community/js/xf/core-compiled.js?_v=1c27fdf4:87
    c https://xenforo.com/community/js/xf/core-compiled.js?_v=1c27fdf4:88
    c https://xenforo.com/community/js/xf/core-compiled.js?_v=1c27fdf4:37
    loadScripts https://xenforo.com/community/js/xf/core-compiled.js?_v=1c27fdf4:37
    jQuery 2
 
The problem appears to be this code in ed.html.getSelected():
JavaScript:
                a.browser.mozilla && (a.selection.save(),
                1 < a.$el.find('.fr-marker[data-type="false"]').length && (a.$el.find('.fr-marker[data-type="false"][data-id="0"]').remove(),
                    a.$el.find('.fr-marker[data-type="false"]:last').attr("data-id", "0"),
                    a.$el.find(".fr-marker").not('[data-id="0"]').remove()),
                    a.selection.restore());
This somehow changes the selected text which then causes the function to escape text box and just try building the copy-paste range right up to the document root.

Disabling the mozilla spesific bits works fine from what I can see.
JavaScript:
$(document).on('editor:init', function(event, ed, xfEditor)
if (ed.browser.mozilla){
    var oldGetSelected = ed.html.getSelected;
    ed.html.getSelected = function() {
        var oldMozilla = ed.browser.mozilla;
        ed.browser.mozilla = 0;
        try {
            return oldGetSelected();
        } finally {
            ed.browser.mozilla = oldMozilla;
        }
    };
});

Debugging this has been a pain as repeated the insert spoiler action in the ssame session will fail on the first few times then work later when retried. Mostly.
 
As discussed, this is fixed in the next release by virtue of bypassing whatever they're doing specific to Mozilla
 
Back
Top Bottom