Skip to content

Commit 9558368

Browse files
committed
fix(pushbutton): sticky buttons are released when the mouse cursor moves over them
wokwi/wokwi-features#686
1 parent c48bd97 commit 9558368

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/pushbutton-element.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class PushbuttonElement extends LitElement {
1111

1212
private static pushbuttonCounter = 0;
1313
private uniqueId;
14+
private sticky = false;
1415

1516
readonly pinInfo: ElementPin[] = [
1617
{ name: '1.l', x: 0, y: 13, signals: [] },
@@ -77,7 +78,7 @@ export class PushbuttonElement extends LitElement {
7778
@mouseup=${this.up}
7879
@touchstart=${this.down}
7980
@touchend=${this.up}
80-
@pointerleave=${this.up}
81+
@pointerleave=${this.leave}
8182
@keydown=${(e: KeyboardEvent) => SPACE_KEYS.includes(e.key) && this.down()}
8283
@keyup=${(e: KeyboardEvent) => SPACE_KEYS.includes(e.key) && this.up(e)}
8384
>
@@ -158,9 +159,21 @@ export class PushbuttonElement extends LitElement {
158159
}
159160

160161
private up(e: KeyboardEvent | MouseEvent) {
161-
if (this.pressed && !ctrlCmdPressed(e)) {
162+
if (!this.pressed) {
163+
return;
164+
}
165+
if (ctrlCmdPressed(e)) {
166+
this.sticky = true;
167+
} else {
168+
this.sticky = false;
162169
this.pressed = false;
163170
this.dispatchEvent(new Event('button-release'));
164171
}
165172
}
173+
174+
private leave(e: MouseEvent) {
175+
if (!this.sticky) {
176+
this.up(e);
177+
}
178+
}
166179
}

0 commit comments

Comments
 (0)