Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabbing behaviour under Gecko is faulty #11

Open
csarven opened this issue Jun 18, 2015 · 2 comments
Open

Tabbing behaviour under Gecko is faulty #11

csarven opened this issue Jun 18, 2015 · 2 comments
Labels

Comments

@csarven
Copy link

csarven commented Jun 18, 2015

Tabbing through cells under Gecko (tested in Ubuntu/Firefox 38) differs from WebKit (tested in ubuntu/Chromium). Chromium behaves as expected however Firefox's cursor position "gets stuck" when tabbed, i.e., after tabbing to the adjacent cell, it is not possible to type. The position of the cursor is at the top left corner of the cell. Only after clicking in the middle of the cell it becomes possible to type. Issue occurs in master and medium-editor-v5 branches.

@j0k3r j0k3r added the bug label Jun 18, 2015
@leotiger
Copy link

leotiger commented May 9, 2017

This can be solved improving the Table.prototype. The _onKeyDown function needs something like this:

    _onKeyDown: function (e) {
        var el = getSelectionStart(this._doc),
            table;
        if (e.which === TAB_KEY_CODE && isInsideElementOfTag(el, 'table')) {
            e.preventDefault();
            e.stopPropagation();
            table = this._getTableElements(el);
            if (e.shiftKey) {
                this._tabBackwards(el.previousSibling, table.row);
            } else {
                if (this._isLastCell(el, table.row, table.root)) {
                    this._insertRow(getParentOf(el, 'tbody'), table.row.cells.length);
                }
                if (el.nextSibling && el.nextSibling.tagName === 'TD') {
                    placeCaretAtNode(this._doc, el.nextSibling, true);
                } else {
                    var nextRow = el.parentElement.nextSibling;
                    if (typeof nextRow != 'undefined' && nextRow != null && nextRow.tagName === 'TR' && nextRow.firstChild != null && nextRow.firstChild.tagName === 'TD') {
                        placeCaretAtNode(this._doc, nextRow.firstChild, true);
                    }
                }                    
            }
        }
    },

combined with a slightly modified placeCaretAtNode function:

function placeCaretAtNode(doc, node, before) {
    if (doc.getSelection !== undefined && node) {
        var range = doc.createRange(),
            selection = doc.getSelection();
        if (before) {
            range.setStart(node, 0);
        } else {            
            range.setStartAfter(node);            
        }
        range.collapse(true);
        selection.removeAllRanges();
        selection.addRange(range);
    }
}

The solution works in Chrome, Safari and Firefox.

Thanks for this extension.

@csarven
Copy link
Author

csarven commented Jul 25, 2017

Perhaps a PR will nudge this forward :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants