Skip to content

Commit 8e9fdb4

Browse files
committed
feat: show the modifier key that is the opposite of the main key
1 parent 8c8f298 commit 8e9fdb4

File tree

4 files changed

+29
-44
lines changed

4 files changed

+29
-44
lines changed

packages/keybr-keyboard-ui/lib/PointersLayer.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ test.serial("with modifiers", async (t) => {
7575
await TestRenderer.act(() => {});
7676
await fake.timers.run();
7777

78-
t.is(renderer.root.findAllByType("circle").length, 3);
78+
t.is(renderer.root.findAllByType("circle").length, 2);
7979

8080
t.snapshot(renderer.toJSON());
8181
});

packages/keybr-keyboard-ui/lib/PointersLayer.test.tsx.md

-35
Original file line numberDiff line numberDiff line change
@@ -85,41 +85,6 @@ Generated by [AVA](https://avajs.dev).
8585
8686
{
8787
children: [
88-
{
89-
children: [
90-
{
91-
children: null,
92-
props: {
93-
attributeName: 'opacity',
94-
dur: '0.5s',
95-
from: 0,
96-
repeatCount: '1',
97-
restart: 'always',
98-
to: 1,
99-
},
100-
type: 'animate',
101-
},
102-
{
103-
children: null,
104-
props: {
105-
attributeName: 'r',
106-
dur: '0.5s',
107-
from: 0,
108-
repeatCount: '1',
109-
restart: 'always',
110-
to: 30,
111-
},
112-
type: 'animate',
113-
},
114-
],
115-
props: {
116-
className: 'modifierPointer',
117-
cx: 45,
118-
cy: 140,
119-
r: 30,
120-
},
121-
type: 'circle',
122-
},
12388
{
12489
children: [
12590
{
Binary file not shown.

packages/keybr-keyboard-ui/lib/PointersLayer.tsx

+28-8
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,38 @@ function pointers(keyboard: Keyboard, combo: KeyCombo | null): ReactNode[] {
5858
if (combo.modifier.shift) {
5959
const l = keyboard.getShape("ShiftLeft");
6060
const r = keyboard.getShape("ShiftRight");
61-
children.unshift(
62-
pointer(l, styles.modifierPointer),
63-
pointer(r, styles.modifierPointer),
64-
);
61+
switch (shape.hand) {
62+
case "left":
63+
children.unshift(pointer(r, styles.modifierPointer));
64+
break;
65+
case "right":
66+
children.unshift(pointer(l, styles.modifierPointer));
67+
break;
68+
default:
69+
children.unshift(
70+
pointer(l, styles.modifierPointer),
71+
pointer(r, styles.modifierPointer),
72+
);
73+
break;
74+
}
6575
}
6676
if (combo.modifier.alt) {
6777
const l = keyboard.getShape("AltLeft");
6878
const r = keyboard.getShape("AltRight");
69-
children.unshift(
70-
pointer(l, styles.modifierPointer),
71-
pointer(r, styles.modifierPointer),
72-
);
79+
switch (shape.hand) {
80+
case "left":
81+
children.unshift(pointer(r, styles.modifierPointer));
82+
break;
83+
case "right":
84+
children.unshift(pointer(l, styles.modifierPointer));
85+
break;
86+
default:
87+
children.unshift(
88+
pointer(l, styles.modifierPointer),
89+
pointer(r, styles.modifierPointer),
90+
);
91+
break;
92+
}
7393
}
7494
}
7595
combo = combo.prefix;

0 commit comments

Comments
 (0)