fix: stop event propagation when capturing keypress action (#817)

* fix: stop event propagation when capturing keypress action

* fix: save to keyboard shortcut allowed when keypress not capturing
This commit is contained in:
Róbert Kiss
2018-10-14 20:43:35 +02:00
committed by László Monda
parent e333022043
commit 2b963993d2
6 changed files with 55 additions and 6 deletions

View File

@@ -1,6 +1,10 @@
import { ChangeDetectionStrategy, Component, EventEmitter, HostListener, Input, Output } from '@angular/core';
import { Store } from '@ngrx/store';
import { CaptureService } from '../../../../services/capture.service';
import { KeyModifierModel } from '../../../../models/key-modifier-model';
import { AppState } from '../../../../store';
import { StartKeypressCapturingAction, StopKeypressCapturingAction } from '../../../../store/actions/app';
@Component({
selector: 'capture-keystroke-button',
@@ -17,7 +21,8 @@ export class CaptureKeystrokeButtonComponent {
private first: boolean; // enable usage of Enter to start capturing
private scanCodePressed: boolean;
constructor(private captureService: CaptureService) {
constructor(private captureService: CaptureService,
private store: Store<AppState>) {
this.record = false;
this.captureService.initModifiers();
this.captureService.populateMapping();
@@ -28,9 +33,11 @@ export class CaptureKeystrokeButtonComponent {
onKeyUp(e: KeyboardEvent) {
if (this.scanCodePressed) {
e.preventDefault();
e.stopPropagation();
this.scanCodePressed = false;
} else if (this.record && !this.first) {
e.preventDefault();
e.stopPropagation();
this.saveScanCode();
}
}
@@ -54,6 +61,7 @@ export class CaptureKeystrokeButtonComponent {
} else if (code === enter) {
this.record = true;
this.first = true;
this.store.dispatch(new StartKeypressCapturingAction());
}
}
@@ -65,6 +73,7 @@ export class CaptureKeystrokeButtonComponent {
start(): void {
this.record = true;
this.store.dispatch(new StartKeypressCapturingAction());
}
private saveScanCode(code?: number) {
@@ -84,5 +93,6 @@ export class CaptureKeystrokeButtonComponent {
private reset() {
this.first = false;
this.captureService.initModifiers();
this.store.dispatch(new StopKeypressCapturingAction());
}
}

View File

@@ -29,6 +29,7 @@ import { getMacros } from '../../../../store/reducers/user-configuration';
import { SvgKeyCaptureEvent, SvgKeyClickEvent } from '../../../../models/svg-key-events';
import { OperatingSystem } from '../../../../models/operating-system';
import { KeyModifierModel } from '../../../../models/key-modifier-model';
import { StartKeypressCapturingAction, StopKeypressCapturingAction } from '../../../../store/actions/app';
enum LabelTypes {
KeystrokeKey,
@@ -107,7 +108,7 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
constructor(
private mapper: MapperService,
store: Store<AppState>,
private store: Store<AppState>,
private element: ElementRef,
private captureService: CaptureService,
private renderer: Renderer
@@ -145,6 +146,7 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
this.recordAnimation = 'active';
this.shiftPressed = e.shiftKey;
this.altPressed = e.altKey;
this.store.dispatch(new StartKeypressCapturingAction());
}
}
}
@@ -242,6 +244,7 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
this.captureService.initModifiers();
this.shiftPressed = false;
this.altPressed = false;
this.store.dispatch(new StopKeypressCapturingAction());
}
private saveScanCode(code = 0) {