rbreaves / kinto

Mac-style shortcut keys for Linux & Windows.
http://kinto.sh
GNU General Public License v2.0
4.25k stars 213 forks source link

[Win] Wordwise shortcuts interfere with Excel "extend selection" shortcuts #737

Open RedBearAK opened 1 year ago

RedBearAK commented 1 year ago

Describe the bug

Microsoft Excel uses Ctrl+Shift+Arrow to extend the selection range from the current cell to the "last" used cell in a row or column, depending on which arrow key is used.

These shortcuts are redirected by the "wordwise" shortcuts into Ctrl+Shift+Home/End for Mac-style text selection, causing a completely different selected range (to the top-left or bottom-right "used" cell in the entire sheet).

Expected behavior

In Excel, Ctrl+Shift+Down should select from current cell to last used cell in the same column.

Install Type: Bare Metal Distro: Windows 11 2202-07 update Branch: master

Potential fix

There are probably several different ways of fixing the issue. The block below seems to be a relatively benign method, using the ClassNN of the focused control (EXCEL71) as reported by AHK's Window Spy app. This "bypass" could also be easily extended for other named window controls from any app as a comma-separated list of the ClassNN labels.

The nice thing about this method instead of blocking all the wordwise shortcuts in the whole Excel window, like the commented-out part of the first line would do, is that when you're actually editing some text in Excel the focused control label is different (like EXCEL61 or EXCEL<1) and the wordwise selection shortcuts will still work.

#If !WinActive("ahk_group remote") ; && !WinActive("ahk_class XLMAIN ahk_exe EXCEL.EXE")
    ; wordwise support
    ^Up::Send ^{Home}
    ^+Up:: ; Send ^+{Home}
    ControlGetFocus, fc, A
    If fc contains EXCEL71
        Send ^+{Up}
    Else Send ^+{Home}
    Return
    ^Down::Send ^{End}
    ^+Down:: ; Send ^+{End}
    ControlGetFocus, fc, A
    If fc contains EXCEL71
        Send ^+{Down}
    Else Send ^+{End}
    Return
    $^Backspace::Send +{Home}{Delete}
    !Backspace::Send ^{Backspace}
    !Left::Send ^{Left}
    !+Left::Send ^+{Left}
    !Right::Send ^{Right}
    !+Right::Send ^+{Right}
    $^Left::Send {Home}
    $^+Left:: ; Send +{Home}
    ControlGetFocus, fc, A
    If fc contains EXCEL71
        Send ^+{Left}
    Else Send +{Home}
    Return
    $^Right::Send {End}
    $^+Right:: ; Send +{End}
    ControlGetFocus, fc, A
    If fc contains EXCEL71
        Send ^+{Right}
    Else Send +{End}
    Return
#If