Typed text duplicated when selecting username from auto-suggest menu with Firefox on Android

Kirby

Well-known member
Affected version
2.2.9
When typing @use to start mentioning a user, an auto-complete menu does appear.

If a username from that list is selected by tapping the entry on Firefox Android @username use appears in the editor, eg. the already typed text is duplicated (it should be only @username).
 
After spending way too much time on this, it seems that this is either a new issue in Firefox on Android - or it has been present for ages without anbody noticing it (also happens with 2.1).

I've tracked this down to XF.AutoCompleter

Code:
insertResult: function(result)
{
    this.hide();

    var matchInfo = this.getCurrentMatchInfo();
    if (!matchInfo)
    {
        return;
    }

    var afterAtPos = matchInfo.start + 1,
        range = matchInfo.range;

    if (this.ed)
    {
        this.ed.selection.save();

        XF.EditorHelpers.focus(this.ed);

        var node = matchInfo.textNode,
            text = node.nodeValue,
            suffix = '\u00a0',
            insert;

        var insertRef = node.splitText(this.options.keepAt ? afterAtPos : afterAtPos - 1);
        insertRef.textContent = text.substr(afterAtPos + matchInfo.query.length);

        if (this.options.insertMode === 'html')
        {
            insert = $.parseHTML(result + suffix);
        }
        else
        {
            insert = document.createTextNode(result + suffix);
        }

        $(insertRef).before(insert);

        node.parentNode.normalize();

        this.ed.selection.restore();
    }
    else
    {
        var $input = this.$input;
        $input.autofocus();

        if (afterAtPos !== -1)
        {
            $input.setSelection(matchInfo.start, range.end);
            $input.replaceSelectedText((this.options.keepAt ? this.options.at : '') + result + ' ', 'collapseToEnd');
        }
    }
},
 
Top Bottom