Skip to content

Commit d2d6513

Browse files
committed
Add select_word.dtsi include
1 parent 0f88238 commit d2d6513

File tree

3 files changed

+157
-1
lines changed

3 files changed

+157
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ Define the `OPERATING_SYSTEM` variable with the operating system you intend to u
4949
Source the `init.h` header before using any of the features of the `zmk-keymap-utils` module on your `.keymap` file to provide the initial keycodes and shortcuts for the specified OS.
5050

5151
```c
52-
#include "zmk-keymap-utils/init.h"
52+
#include <zmk-keymap-utils/init.h>
53+
```
54+
55+
Then include any extra functionality you need:
56+
57+
```c
58+
// select-word macros based on the Sunaku's implementation of Pascal Getreuer's Select Word macro from QMK
59+
#include <zmk-keymap-utils/select_word.h>
5360
```
5461

5562
# License

docs/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,39 @@ The core definitions are provided by default by the intial setup (including the
7272
> The shortcuts might not work as expected if the `&caps_word` behavior is active.
7373

7474
Other definitons might be used on different behaviors and are not intended to be consumed by the user.
75+
76+
## Select Word
77+
78+
The `select_word.dtsi` include file provides support for extend/select behaviors for for the specified OS.
79+
They are based on the [Pascal Getreuer's Select Word macro from QMK](https://getreuer.info/posts/keyboards/select-word/index.html) implementation for ZMK by [Sunaku](https://github.com/sunaku/glove80-keymapd).
80+
81+
To use the default configuration, import with:
82+
83+
```c
84+
// select-word macros based on the Sunaku's implementation of Pascal Getreuer's Select Word macro from QMK
85+
#include "zmk-keymap-utils/select_word.h"
86+
```
87+
88+
To use a different delay, the `SELECT_WORD_DELAY` property can be used before import (default is `1`).
89+
This configuration defines how long the macro waits (in ms) after moving the cursor before it selects a word.
90+
A larger delay may allow th"macro to move to the next word upon each invocation.
91+
For example:
92+
93+
```c
94+
#define SELECT_WORD_DELAY 50
95+
#include "zmk-keymap-utils/select_word.h"
96+
```
97+
98+
The behaviors provided after import are the following:
99+
100+
| Behavior | Description |
101+
| -------------- | ----------------------------------------------------------------------- |
102+
| `&select_all` | Select the whole text |
103+
| `&select_none` | Remove current selection |
104+
| `&select_word` | Select current word (jump to next word upon each successive invocation) |
105+
| `&extend_word` | Extend current selection by one word |
106+
| `&select_line` | Select current line |
107+
| `&extend_line` | Extend current selection by one line |
108+
109+
> [!TIP]
110+
> The behaviors are implemented in such a way that using them with the shift modifier active selects/extends in the t
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/* Original code copied from Sunaku's Keymap modified to use zmk-helpers - https://github.com/sunaku/glove80-keymaps */
2+
3+
//////////////////////////////////////////////////////////////////////////
4+
//
5+
// Approximation of Pascal Getreuer's Select Word macro from QMK
6+
// - https://getreuer.info/posts/keyboards/select-word/index.html
7+
//
8+
//////////////////////////////////////////////////////////////////////////
9+
10+
//
11+
// SELECT_WORD_DELAY defines how long the macro waits (milliseconds)
12+
// after moving the cursor before it selects a word. A larger delay
13+
// may allow the macro to move to the next word upon each invocation.
14+
//
15+
#ifndef SELECT_WORD_DELAY
16+
#define SELECT_WORD_DELAY 1
17+
#endif
18+
19+
//////////////////////////////////////////////////////////////////////////
20+
//
21+
// Approximation of Pascal Getreuer's Select Word macro from QMK
22+
// - https://getreuer.info/posts/keyboards/select-word/index.html
23+
//
24+
//////////////////////////////////////////////////////////////////////////
25+
26+
//
27+
// SELECT_WORD_DELAY defines how long the macro waits (milliseconds)
28+
// after moving the cursor before it selects a word. A larger delay
29+
// may allow the macro to move to the next word upon each invocation.
30+
//
31+
#ifndef SELECT_WORD_DELAY
32+
#define SELECT_WORD_DELAY 1
33+
#endif
34+
35+
// select all alias for shortcut
36+
#define select_all kp _C(A)
37+
38+
ZMK_MACRO(select_none,
39+
wait-ms = <SELECT_WORD_DELAY>;
40+
tap-ms = <SELECT_WORD_DELAY>;
41+
bindings = <&kp DOWN &kp UP &kp RIGHT &kp LEFT>;
42+
)
43+
44+
//
45+
// select a word (jumps to next word upon each successive invocation)
46+
//
47+
ZMK_MOD_MORPH(select_word,
48+
bindings = <&select_word_right>, <&select_word_left>;
49+
mods = <(MOD_LSFT|MOD_RSFT)>;
50+
)
51+
ZMK_MACRO(select_word_right,
52+
wait-ms = <SELECT_WORD_DELAY>;
53+
tap-ms = <SELECT_WORD_DELAY>;
54+
bindings = <&kp _W(RIGHT) &kp _W(LEFT) &kp _W(LS(RIGHT))>;
55+
)
56+
ZMK_MACRO(select_word_left,
57+
wait-ms = <SELECT_WORD_DELAY>;
58+
tap-ms = <SELECT_WORD_DELAY>;
59+
bindings = <&kp _W(LEFT) &kp _W(RIGHT) &kp _W(LS(LEFT))>;
60+
)
61+
//
62+
// extend current selection by one word
63+
//
64+
ZMK_MOD_MORPH(extend_word,
65+
bindings = <&extend_word_right>, <&extend_word_left>;
66+
mods = <(MOD_LSFT|MOD_RSFT)>;
67+
)
68+
ZMK_MACRO(extend_word_right,
69+
wait-ms = <SELECT_WORD_DELAY>;
70+
tap-ms = <SELECT_WORD_DELAY>;
71+
bindings = <&kp _W(LS(RIGHT))>;
72+
)
73+
ZMK_MACRO(extend_word_left,
74+
wait-ms = <SELECT_WORD_DELAY>;
75+
tap-ms = <SELECT_WORD_DELAY>;
76+
bindings = <&kp _W(LS(LEFT))>;
77+
)
78+
79+
//
80+
// select current line
81+
//
82+
ZMK_MOD_MORPH(select_line,
83+
bindings = <&select_line_right>, <&select_line_left>;
84+
mods = <(MOD_LSFT|MOD_RSFT)>;
85+
)
86+
ZMK_MACRO(select_line_right,
87+
wait-ms = <SELECT_WORD_DELAY>;
88+
tap-ms = <SELECT_WORD_DELAY>;
89+
bindings = <&kp _HOME &kp LS(_END)>;
90+
)
91+
ZMK_MACRO(select_line_left,
92+
wait-ms = <SELECT_WORD_DELAY>;
93+
tap-ms = <SELECT_WORD_DELAY>;
94+
bindings = <&kp _END &kp LS(_HOME)>;
95+
)
96+
97+
//
98+
// extend current selection by one line
99+
//
100+
ZMK_MOD_MORPH(extend_line,
101+
bindings = <&extend_line_right>, <&extend_line_left>;
102+
mods = <(MOD_LSFT|MOD_RSFT)>;
103+
)
104+
ZMK_MACRO(extend_line_right,
105+
wait-ms = <SELECT_WORD_DELAY>;
106+
tap-ms = <SELECT_WORD_DELAY>;
107+
bindings = <&kp LS(DOWN) &kp LS(_END)>;
108+
)
109+
ZMK_MACRO(extend_line_left,
110+
wait-ms = <SELECT_WORD_DELAY>;
111+
tap-ms = <SELECT_WORD_DELAY>;
112+
bindings = <&kp LS(UP) &kp LS(_HOME)>;
113+
)

0 commit comments

Comments
 (0)