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

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

Closed
darricheng opened this issue Dec 19, 2023 · 4 comments · Fixed by #4
Closed

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

darricheng opened this issue Dec 19, 2023 · 4 comments · Fixed by #4

Comments

@darricheng
Copy link
Contributor

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
Copy link
Owner

sunaku commented Dec 19, 2023

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

  • select_word_right: &kp LG(RIGHT) &kp LG(LEFT) &kp LG(LS(RIGHT))
  • select_word_left: &kp LG(LEFT) &kp LG(RIGHT) &kp LG(LS(LEFT))
  • extend_word_right: &kp LG(LS(RIGHT))
  • extend_word_left: &kp LG(LS(LEFT))
  • select_line_right: &kp HOME &kp LS(END)
  • select_line_left: &kp END &kp LS(HOME)
  • extend_line_right: &kp LS(DOWN) &kp LS(END)
  • extend_line_left: &kp LS(UP) &kp LS(HOME)

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
Copy link
Contributor Author

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
Copy link
Owner

sunaku commented Dec 22, 2023

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
Copy link
Contributor Author

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

@sunaku sunaku closed this as completed in #4 Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants