cursedbelt-core 2.13.0 → 2.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,7 +15,10 @@ export interface ParsedHotkey extends HotkeyMods {
|
|
|
15
15
|
* returns `false` when there's no `navigator`.
|
|
16
16
|
*/
|
|
17
17
|
export declare function isApplePlatform(): boolean;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Split a `'+'`-separated binding into its required modifiers + final key. `+` is itself a
|
|
20
|
+
* key — a bare `'+'` or `'$mod++'` splits into empty parts, and the key is the `+`.
|
|
21
|
+
*/
|
|
19
22
|
export declare function parseHotkey(binding: string, isApple?: boolean): ParsedHotkey;
|
|
20
23
|
/** Does a keyboard event satisfy `binding` — exact modifier set + the key? */
|
|
21
24
|
export declare function matchHotkey(e: KeyboardEvent, binding: string, isApple?: boolean): boolean;
|
|
@@ -21,14 +21,18 @@ export function isApplePlatform() {
|
|
|
21
21
|
const probe = `${navigator.platform ?? ''} ${navigator.userAgent ?? ''}`;
|
|
22
22
|
return /mac|iphone|ipad|ipod/i.test(probe);
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Split a `'+'`-separated binding into its required modifiers + final key. `+` is itself a
|
|
26
|
+
* key — a bare `'+'` or `'$mod++'` splits into empty parts, and the key is the `+`.
|
|
27
|
+
*/
|
|
25
28
|
export function parseHotkey(binding, isApple = isApplePlatform()) {
|
|
26
|
-
const
|
|
29
|
+
const split = binding
|
|
27
30
|
.toLowerCase()
|
|
28
31
|
.split('+')
|
|
29
|
-
.map((p) => p.trim())
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
+
.map((p) => p.trim());
|
|
33
|
+
const plusKey = split.length > 1 && split[split.length - 1] === '';
|
|
34
|
+
const parts = split.filter(Boolean);
|
|
35
|
+
const key = plusKey ? '+' : (parts.pop() ?? '');
|
|
32
36
|
const tokens = new Set(parts);
|
|
33
37
|
const mod = tokens.has('$mod');
|
|
34
38
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursedbelt-core",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.1",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Framework-agnostic core of the cursedbelt split — isomorphic domain logic. cwip below it, cursedbelt-server and cursedbelt (react) above it.",
|
|
@@ -35,14 +35,18 @@ export function isApplePlatform(): boolean {
|
|
|
35
35
|
return /mac|iphone|ipad|ipod/i.test(probe);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Split a `'+'`-separated binding into its required modifiers + final key. `+` is itself a
|
|
40
|
+
* key — a bare `'+'` or `'$mod++'` splits into empty parts, and the key is the `+`.
|
|
41
|
+
*/
|
|
39
42
|
export function parseHotkey(binding: string, isApple = isApplePlatform()): ParsedHotkey {
|
|
40
|
-
const
|
|
43
|
+
const split = binding
|
|
41
44
|
.toLowerCase()
|
|
42
45
|
.split('+')
|
|
43
|
-
.map((p) => p.trim())
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
+
.map((p) => p.trim());
|
|
47
|
+
const plusKey = split.length > 1 && split[split.length - 1] === '';
|
|
48
|
+
const parts = split.filter(Boolean);
|
|
49
|
+
const key = plusKey ? '+' : (parts.pop() ?? '');
|
|
46
50
|
const tokens = new Set(parts);
|
|
47
51
|
const mod = tokens.has('$mod');
|
|
48
52
|
return {
|
|
@@ -133,6 +133,14 @@ describe('formatHotkey', () => {
|
|
|
133
133
|
test('multiple modifiers order Apple-style (⌃⌥⇧⌘)', () => {
|
|
134
134
|
expect(formatHotkey('$mod+shift+p', true)).toBe('⇧⌘P');
|
|
135
135
|
});
|
|
136
|
+
test('`+` is a key too — a bare `+` or `shift++` draws a + cap, never an empty one', () => {
|
|
137
|
+
expect(formatHotkey('+', true)).toBe('+');
|
|
138
|
+
expect(formatHotkey('+', false)).toBe('+');
|
|
139
|
+
expect(formatHotkey('$mod++', true)).toBe('⌘+');
|
|
140
|
+
expect(formatHotkey('$mod++', false)).toBe('Ctrl +');
|
|
141
|
+
expect(parseHotkey('shift++')).toMatchObject({ shift: true, key: '+' });
|
|
142
|
+
expect(matchHotkey(kd({ key: '+' }), '+', true)).toBe(true);
|
|
143
|
+
});
|
|
136
144
|
});
|
|
137
145
|
|
|
138
146
|
// ── ShortcutRegistry ──────────────────────────────────────────────────────────
|