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 11import { css , html , LitElement } from 'lit' ;
22import { customElement , property } from 'lit/decorators.js' ;
33import { ElementPin } from './pin' ;
4- import { SPACE_KEYS } from './utils/keys' ;
4+ import { ctrlCmdPressed , SPACE_KEYS } from './utils/keys' ;
55
66@customElement ( 'wokwi-pushbutton' )
77export class PushbuttonElement extends LitElement {
@@ -74,11 +74,12 @@ export class PushbuttonElement extends LitElement {
7474 < button
7575 aria-label ="${ label } ${ color } pushbutton "
7676 @mousedown =${ this . down }
77- @mouseup =${ ( e : MouseEvent ) => ! e . ctrlKey && this . up ( ) }
77+ @mouseup =${ this . up }
7878 @touchstart=${ this . down }
7979 @touchend=${ this . up }
80+ @pointerleave=${ this . up }
8081 @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 ) }
8283 >
8384 < svg
8485 width ="17.802mm "
@@ -156,8 +157,8 @@ export class PushbuttonElement extends LitElement {
156157 }
157158 }
158159
159- private up ( ) {
160- if ( this . pressed ) {
160+ private up ( e : KeyboardEvent | MouseEvent ) {
161+ if ( this . pressed && ! ctrlCmdPressed ( e ) ) {
161162 this . pressed = false ;
162163 this . dispatchEvent ( new Event ( 'button-release' ) ) ;
163164 }
Original file line number Diff line number Diff line change 11export 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