File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { css , html , LitElement } from 'lit' ;
2
2
import { customElement , property } from 'lit/decorators.js' ;
3
3
import { ElementPin } from './pin' ;
4
- import { SPACE_KEYS } from './utils/keys' ;
4
+ import { ctrlCmdPressed , SPACE_KEYS } from './utils/keys' ;
5
5
6
6
@customElement ( 'wokwi-pushbutton' )
7
7
export class PushbuttonElement extends LitElement {
@@ -74,11 +74,12 @@ export class PushbuttonElement extends LitElement {
74
74
< button
75
75
aria-label ="${ label } ${ color } pushbutton "
76
76
@mousedown =${ this . down }
77
- @mouseup =${ ( e : MouseEvent ) => ! e . ctrlKey && this . up ( ) }
77
+ @mouseup =${ this . up }
78
78
@touchstart=${ this . down }
79
79
@touchend=${ this . up }
80
+ @pointerleave=${ this . up }
80
81
@keydown=${ ( e : KeyboardEvent ) => SPACE_KEYS . includes ( e . key ) && this . down ( ) }
81
- @keyup=${ ( e : KeyboardEvent ) => SPACE_KEYS . includes ( e . key ) && ! e . ctrlKey && this . up ( ) }
82
+ @keyup=${ ( e : KeyboardEvent ) => SPACE_KEYS . includes ( e . key ) && this . up ( e ) }
82
83
>
83
84
< svg
84
85
width ="17.802mm "
@@ -156,8 +157,8 @@ export class PushbuttonElement extends LitElement {
156
157
}
157
158
}
158
159
159
- private up ( ) {
160
- if ( this . pressed ) {
160
+ private up ( e : KeyboardEvent | MouseEvent ) {
161
+ if ( this . pressed && ! ctrlCmdPressed ( e ) ) {
161
162
this . pressed = false ;
162
163
this . dispatchEvent ( new Event ( 'button-release' ) ) ;
163
164
}
Original file line number Diff line number Diff line change 1
1
export const SPACE_KEYS = [ ' ' , 'Spacebar' ] ;
2
+
3
+ export function getUserAgent ( ) {
4
+ return typeof navigator === 'object' ? navigator . userAgent : '' ;
5
+ }
6
+
7
+ function isMac ( ) {
8
+ return getUserAgent ( ) . indexOf ( 'Macintosh' ) >= 0 ;
9
+ }
10
+
11
+ export function ctrlCmdPressed ( e : KeyboardEvent | MouseEvent ) {
12
+ return isMac ( ) ? e . metaKey : e . ctrlKey ;
13
+ }
You can’t perform that action at this time.
0 commit comments