sunaku / glove80-keymaps

"Glorious Engrammer" keymap for Glove80 keyboard
https://sunaku.github.io/moergo-glove80-keyboard.html#layers
365 stars 113 forks source link

Select word and line doesn't work on macos #3

Closed darricheng closed 10 months ago

darricheng commented 10 months ago

In v32, the select word macro selects the entire line, while the select line macro selects the current line and everything below.

I'm still very new to the layout and the whole ZMK customisation, so I could use some advice on how to edit and test the macro.

sunaku commented 10 months ago

Please check whether manually typing out these ZMK macros' keystrokes has the intended effect:

If those worked successfully, the problem may be timing: I think the macros might be emitting their synthetic keystrokes too rapidly for your system, so you can try increasing the SELECT_WORD_DELAY setting's value to slow down their emission rate:

#define SELECT_WORD_DELAY 40
darricheng commented 10 months ago

Could you explain what the cursor is supposed to do when I do &kp LG(RIGHT)? I think it might be an issue with the modifier key being used, because on mac, doing &kp LG(RIGHT) sends the cursor to the end of the line. So for example the extend_word_right highlights from where the cursor currently is to the end of the line.

Mac also doesn't really use HOME or END, so the behaviour for those keys might be unexpected.

Maybe could you also help me understand how the macro works? Say for "select word":

//
// select a word (jumps to next word upon each successive invocation)
//
select_word: select_word {
    compatible = "zmk,behavior-mod-morph";
    label = "SELECT_WORD";
    #binding-cells = <0>;
    bindings = <&select_word_right>, <&select_word_left>;
    mods = <(MOD_LSFT|MOD_RSFT)>;
};
ZMK_MACRO(select_word_right,
    wait-ms = <SELECT_WORD_DELAY>;
    tap-ms = <SELECT_WORD_DELAY>;
    bindings = <&kp _C(RIGHT) &kp _C(LEFT) &kp _C(LS(RIGHT))>;
)
ZMK_MACRO(select_word_left,
    wait-ms = <SELECT_WORD_DELAY>;
    tap-ms = <SELECT_WORD_DELAY>;
    bindings = <&kp _C(LEFT) &kp _C(RIGHT) &kp _C(LS(LEFT))>;
)

I suppose select_word runs &select_word_right followed immediately by &select_word_left? And what is _C? I see it being used a lot for these macros.

sunaku commented 10 months ago

You are correct! ✅ Upon closer study of this listing, I see that "Go to next word" on macOS is Opt+Right instead of Cmd+Right. 😅 I naively assumed that, like Ctrl in Windows and Linux, a single modifier was used for both word-wise and line-wise motion in macOS too: that was the purpose of the _C definition -- to abstract Ctrl vs Cmd as _C so that the same underlying ZMK macro logic could be reused across operating systems.

As for understanding the select_word macro, it's just a custom shifted pair (like &parang which is a parenthesis by default or an angle bracket when Shift is held down) that defaults to select_word_right and alternates to select_word_left if Shift is held down -- see "mod-morph" in ZMK docs for details. Effectively, this lets us select a word by going rightward by default and, optionally, reverse direction by adding a Shift modifier to our select_word keystroke.

darricheng commented 10 months ago

Thanks for the explanation! I modified the files accordingly as per the linked PR and have tested it to work on my own mac.