Skip to content

Commit ccb107b

Browse files
committed
fix: check exact mods match
1 parent 44fdc00 commit ccb107b

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

main.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,13 @@ interface EditorScrollCommandsSettings {
1313
}
1414

1515
const DEFAULT_SETTINGS: EditorScrollCommandsSettings = {
16-
offset: 2,
17-
interval: 5,
16+
offset: 4,
17+
interval: 6,
1818
accelerate: true,
19-
accelRate: 0.024,
20-
maxAccel: 4,
19+
accelRate: 0.02,
20+
maxAccel: 8,
2121
}
2222

23-
const MODIFIER_TO_EVENT_PROP = {
24-
'Alt': 'altKey',
25-
'Shift': 'shiftKey',
26-
'Ctrl': 'ctrlKey',
27-
'Meta': 'metaKey',
28-
'Mod': Platform.isMacOS ? 'metaKey' : 'ctrlKey',
29-
};
30-
3123
export default class EditorScrollCommandsPlugin extends Plugin {
3224
settings: EditorScrollCommandsSettings;
3325
intervalId: number;
@@ -76,14 +68,18 @@ export default class EditorScrollCommandsPlugin extends Plugin {
7668
(hotkey.key == event.code) ||
7769
('Key' + hotkey.key == event.code);
7870

79-
let allModsMatched = hotkey.modifiers.every(m => {
80-
let modifierPressed = MODIFIER_TO_EVENT_PROP[m];
71+
if (!keyMatched) { return false; }
8172

82-
// @ts-expect-error
83-
return event[modifierPressed];
84-
});
73+
let mods = hotkey.modifiers;
74+
let modKeyState = Platform.isMacOS ? event.metaKey : event.ctrlKey;
75+
76+
if (event.altKey != mods.contains('Alt')) { return false; }
77+
if (event.ctrlKey != mods.contains('Ctrl')) { return false; }
78+
if (event.shiftKey != mods.contains('Shift')) { return false; }
79+
if (event.metaKey != mods.contains('Meta')) { return false; }
80+
if (modKeyState != mods.contains('Mod')) { return false; }
8581

86-
return keyMatched && allModsMatched;
82+
return true;
8783
});
8884
}
8985

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "editor-scroll-commands",
33
"name": "Editor Scroll Commands",
4-
"version": "1.1.1",
4+
"version": "1.1.2",
55
"minAppVersion": "0.15.0",
66
"description": "Add scroll commands for editor, so you can assign hotkeys.",
77
"author": "Andrey Sorokin <[email protected]>",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "editor-scroll-commands",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Add scroll commands for editor, so you can assign hotkeys.",
55
"main": "main.js",
66
"scripts": {

versions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"1.0.0": "0.15.0",
33
"1.0.3": "0.15.0",
44
"1.1.0": "0.15.0",
5-
"1.1.1": "0.15.0"
5+
"1.1.1": "0.15.0",
6+
"1.1.2": "0.15.0"
67
}

0 commit comments

Comments
 (0)