Skip to content

Commit

Permalink
Add preventOnInput parameter to registerShortcut.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephbirkner committed Nov 4, 2024
1 parent 13a519b commit 8d4dc65
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion erdblick_app/app/inspection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class InspectionService {
private keyboardService: KeyboardService,
public parametersService: ParametersService) {

this.keyboardService.registerShortcuts(["Ctrl+j", "Ctrl+J"], this.zoomToFeature.bind(this));
this.keyboardService.registerShortcut("Ctrl+j", this.zoomToFeature.bind(this));

this.mapService.selectionTopic.pipe(distinctUntilChanged(selectedFeaturesEqualTo)).subscribe(selectedFeatures => {
if (!selectedFeatures?.length) {
Expand Down
12 changes: 6 additions & 6 deletions erdblick_app/app/keyboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class KeyboardService {
private renderer: Renderer2;
private dialogStack: Array<Dialog> = [];
private shortcuts = new Map<string, (event: KeyboardEvent) => void>();
private preventOnInputShortcuts: Set<string> = new Set<string>();

constructor(rendererFactory: RendererFactory2) {
this.renderer = rendererFactory.createRenderer(null, null);
Expand All @@ -45,7 +46,7 @@ export class KeyboardService {
// focusing another control/closing the enclosing dialog.

// Let non-ctrl key events or text editing shortcuts do their default things.
if (isInput && (!key.includes("Ctrl") || ["ctrl+x", "ctrl+c", "ctrl+v"].includes(key.toLowerCase()))) {
if (isInput && this.preventOnInputShortcuts.has(key)) {
return;
}

Expand All @@ -69,12 +70,11 @@ export class KeyboardService {
return key;
}

registerShortcuts(keys: string[], callback: (event: KeyboardEvent) => void) {
keys.forEach(keys_ => this.registerShortcut(keys_, callback));
}

registerShortcut(keys: string, callback: (event: KeyboardEvent) => void) {
registerShortcut(keys: string, callback: (event: KeyboardEvent) => void, preventOnInput: boolean=false) {
this.shortcuts.set(keys, callback);
if (preventOnInput) {
this.preventOnInputShortcuts.add(keys);
}
}

ngOnDestroy() {
Expand Down
2 changes: 1 addition & 1 deletion erdblick_app/app/map.panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class MapPanelComponent {
public editorService: EditorService,
public dsService: DataSourcesService,
private sidePanelService: SidePanelService) {
this.keyboardService.registerShortcuts(['m', 'M'], this.showLayerDialog.bind(this));
this.keyboardService.registerShortcut('m', this.showLayerDialog.bind(this), true);

this.parameterService.parameters.subscribe(parameters => {
this.osmEnabled = parameters.osm;
Expand Down
4 changes: 2 additions & 2 deletions erdblick_app/app/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ export class MapService {
this.visualizeHighlights(coreLib.HighlightMode.HOVER_HIGHLIGHT, hoveredFeatureWrappers);
});

this.keyboardService.registerShortcuts(["Ctrl+x", "Ctrl+X"], ()=>{
this.keyboardService.registerShortcut("Ctrl+x", ()=>{
this.statsDialogVisible = true;
this.statsDialogNeedsUpdate.next();
});
}, true);
}

private processTileStream() {
Expand Down
2 changes: 1 addition & 1 deletion erdblick_app/app/search.panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class SearchPanelComponent implements AfterViewInit {
private messageService: InfoMessageService,
private jumpToTargetService: JumpTargetService,
private sidePanelService: SidePanelService) {
this.keyboardService.registerShortcuts(["Ctrl+k", "Ctrl+K"], this.clickOnSearchToStart.bind(this));
this.keyboardService.registerShortcut("Ctrl+k", this.clickOnSearchToStart.bind(this));
this.clickListener = this.renderer.listen('document', 'click', this.handleClickOut.bind(this));

this.jumpToTargetService.targetValueSubject.subscribe((event: string) => {
Expand Down
14 changes: 7 additions & 7 deletions erdblick_app/app/view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,13 @@ export class ErdblickViewComponent implements AfterViewInit {
});
});

this.keyboardService.registerShortcuts(['q', 'Q'], this.zoomIn.bind(this));
this.keyboardService.registerShortcuts(['e', 'E'], this.zoomOut.bind(this));
this.keyboardService.registerShortcuts(['w', 'W'], this.moveUp.bind(this));
this.keyboardService.registerShortcuts(['a', 'A'], this.moveLeft.bind(this));
this.keyboardService.registerShortcuts(['s', 'S'], this.moveDown.bind(this));
this.keyboardService.registerShortcuts(['d', 'D'], this.moveRight.bind(this));
this.keyboardService.registerShortcuts(['r', 'R'], this.resetOrientation.bind(this));
this.keyboardService.registerShortcut('q', this.zoomIn.bind(this), true);
this.keyboardService.registerShortcut('e', this.zoomOut.bind(this), true);
this.keyboardService.registerShortcut('w', this.moveUp.bind(this), true);
this.keyboardService.registerShortcut('a', this.moveLeft.bind(this), true);
this.keyboardService.registerShortcut('s', this.moveDown.bind(this), true);
this.keyboardService.registerShortcut('d', this.moveRight.bind(this), true);
this.keyboardService.registerShortcut('r', this.resetOrientation.bind(this), true);

// Hide the global loading spinner.
const spinner = document.getElementById('global-spinner-container');
Expand Down

0 comments on commit 8d4dc65

Please sign in to comment.