Skip to content

Commit cf6f37a

Browse files
committed
chore: respect user's shortcut settings
1 parent 2e10473 commit cf6f37a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/ability.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,24 @@ export class AbilityControl {
2929
inventoryIsInfinite = false;
3030
enabled: AbilityEnableOptions;
3131
focused: Coords | undefined;
32-
constructor(_cx: Context, options?: AbilityInit) {
32+
constructor(cx: Context, options?: AbilityInit) {
3333
this.enabled = options?.enabled ?? {
3434
copy: true,
3535
paste: true,
3636
cut: true,
3737
};
38+
document.addEventListener("copy", (e) => {
39+
e.preventDefault();
40+
if (this.enabled.copy) this.copy(cx);
41+
});
42+
document.addEventListener("cut", (e) => {
43+
e.preventDefault();
44+
if (this.enabled.cut) this.cut(cx);
45+
});
46+
document.addEventListener("paste", (e) => {
47+
e.preventDefault();
48+
if (this.enabled.paste) this.paste(cx);
49+
});
3850
}
3951
highlightCoord(playerAt: Coords, facing: Facing) {
4052
let dx: number;

src/player.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ export class Player {
8282
highlight.y = highlightCoords.y * cx.blockSize;
8383
return highlight;
8484
}
85-
handleInput(cx: Context, event: KeyboardEvent, eventIsKeyDown: boolean) {
86-
if (eventIsKeyDown) {
87-
this.ability.handleKeyDown(cx, event, this.onGround);
88-
}
85+
handleInput(_cx: Context, event: KeyboardEvent, eventIsKeyDown: boolean) {
8986
switch (event.key) {
9087
case "Control":
9188
this.holdingKeys[Inputs.Ctrl] = eventIsKeyDown;

0 commit comments

Comments
 (0)