Disable phpMyAdmin's Overriding of Ctrl+Arrow Keys

Viewed 182

In phpMyAdmin, using the Control key in conjunction with the arrows keys (such as ctrl+right, ctrl+left, ctrl+shift+right, and ctrl+shift+left) causes the cursor to move to another cell.

This behavior can be extremely annoying if one instinctively uses these key combinations to move between and/or select words in a text.

Older versions of phpMyAdmin, had a configuration setting, $cfg['CtrlArrowsMoving']=false, that would disable it, but that setting is no longer supported and there doesn't seem to be a way to disable it through the settings or configuration anymore.

The Alt key does exactly the same thing when you're editing a table, and the tab key allows you to move from one cell to another as you would expect, so there's no reason for the ctrl key to be used this way unless the user actually wants to.

I love phpMyAdmin, but after years of instinctively pressing ctrl+shift+left to select a word only to remember it doesn't work, I decided to search the code and figure out how to disable it.

I'm using phpMyAdmin version 5.0.2 and don't know if other versions use the same code for this, but hopefully they're similar enough that this information will help people modify the behavior if they want to.

1 Answers

There are two different functions that control this behavior.

The function that controls the behavior when you're editing a table is in the PHPMyAdmin directory under /js/makegrid.js

function handleCtrlNavigation (e) {
    if ((e.ctrlKey && e.which === 38) || (e.altKey && e.which === 38)) {
        g.moveUp(e);
    } else if ((e.ctrlKey && e.which === 40)  || (e.altKey && e.which === 40)) {
        g.moveDown(e);
    } else if ((e.ctrlKey && e.which === 37) || (e.altKey && e.which === 37))
        g.moveLeft(e);
    } else if ((e.ctrlKey && e.which === 39)  || (e.altKey && e.which === 39)) {
        g.moveRight(e);
    }
}

Just remove the parts that refer to the ctrl key, or replace the entire function with this:

function handleCtrlNavigation (e) {
    if ((e.altKey && e.which === 38)) {
        g.moveUp(e);
    } else if ((e.altKey && e.which === 40)) {
        g.moveDown(e);
    } else if ((e.altKey && e.which === 37)) {
        g.moveLeft(e);
    } else if ((e.altKey && e.which === 39)) {
        g.moveRight(e);
    }
}

This will preserve the alt-key functionality. If you don't care about that you can also just add a return statement after the function declaration:

function handleCtrlNavigation (e) {
    return;
    ((e.ctrlKey && e.which === 38) || (e.altKey && e.which === 38)) {...

The function that controls the behavior in other areas (like when you're inserting a new entry) is in the file /js/keyhandler.js under the function onKeyDownArrowsHandler, which is described as "Allows moving around inputs/select by Ctrl+arrows". Here, you can just put a return statement at the top of the function to bypass it:

function onKeyDownArrowsHandler (event) {
    return;
Related