From c83fc2ff0e69138288b0ba23aab6042cff554031 Mon Sep 17 00:00:00 2001 From: Wagram Airiian Date: Fri, 9 Aug 2024 08:43:22 +0200 Subject: [PATCH] Add basic search shortcut --- erdblick_app/app/inspection.service.ts | 1 + erdblick_app/app/search.panel.component.ts | 45 +++++++++++----------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/erdblick_app/app/inspection.service.ts b/erdblick_app/app/inspection.service.ts index 330dc03..665021d 100644 --- a/erdblick_app/app/inspection.service.ts +++ b/erdblick_app/app/inspection.service.ts @@ -46,6 +46,7 @@ export class InspectionService { public parametersService: ParametersService) { this.keyboardService.registerShortcut("Ctrl+j", this.zoomToFeature.bind(this)); + this.keyboardService.registerShortcut("Ctrl+J", this.zoomToFeature.bind(this)); this.mapService.selectionTopic.pipe(distinctUntilChanged()).subscribe(selectedFeature => { if (!selectedFeature) { diff --git a/erdblick_app/app/search.panel.component.ts b/erdblick_app/app/search.panel.component.ts index 2e9faa6..c755e17 100644 --- a/erdblick_app/app/search.panel.component.ts +++ b/erdblick_app/app/search.panel.component.ts @@ -7,6 +7,7 @@ import {coreLib} from "./wasm"; import {ParametersService} from "./parameters.service"; import {SidePanelService, SidePanelState} from "./sidepanel.service"; import {Dialog} from "primeng/dialog"; +import {KeyboardService} from "./keyboard.service"; @Directive({ @@ -165,10 +166,14 @@ export class SearchPanelComponent implements AfterViewInit { constructor(private renderer: Renderer2, public mapService: MapService, public parametersService: ParametersService, + private keyboardService: KeyboardService, private messageService: InfoMessageService, private jumpToTargetService: JumpTargetService, private sidePanelService: SidePanelService) { + this.keyboardService.registerShortcut("Ctrl+k", this.clickOnSearchToStart.bind(this)); + this.keyboardService.registerShortcut("Ctrl+K", this.clickOnSearchToStart.bind(this)); + this.jumpToTargetService.targetValueSubject.subscribe((event: string) => { this.validateMenuItems(); }); @@ -200,6 +205,20 @@ export class SearchPanelComponent implements AfterViewInit { this.reloadSearchHistory(); } + ngAfterViewInit() { + this.dialog.onShow.subscribe(() => { + setTimeout(() => { + this.expandTextarea(); + }, 0); + }); + + this.dialog.onHide.subscribe(() => { + setTimeout(() => { + this.shrinkTextarea(); + }, 0); + }); + } + private reloadSearchHistory() { const searchHistoryString = localStorage.getItem("searchHistory"); if (searchHistoryString) { @@ -448,7 +467,6 @@ export class SearchPanelComponent implements AfterViewInit { } expandTextarea() { - // const target = this.textarea.nativeElement as HTMLTextAreaElement; this.renderer.setAttribute(this.textarea.nativeElement, 'rows', '3'); this.renderer.removeClass(this.textarea.nativeElement, 'single-line'); this.textarea.nativeElement.focus(); @@ -458,31 +476,14 @@ export class SearchPanelComponent implements AfterViewInit { shrinkTextarea() { this.cursorPosition = this.textarea.nativeElement.selectionStart; - // const target = this.textarea.nativeElement as HTMLTextAreaElement; this.renderer.setAttribute(this.textarea.nativeElement, 'rows', '1'); this.renderer.addClass(this.textarea.nativeElement, 'single-line'); // this.renderer.removeClass(this.container, "multiline"); } - ngAfterViewInit() { - this.dialog.onShow.subscribe(() => { - setTimeout(() => { - this.expandTextarea(); - }, 0); - }); - - this.dialog.onHide.subscribe(() => { - setTimeout(() => { - this.shrinkTextarea(); - }, 0); - }); - } - - restoreCursorPosition() { - const textarea = this.textarea.nativeElement; - setTimeout(() => { - textarea.focus(); - textarea.setSelectionRange(this.cursorPosition, this.cursorPosition); - }, 0); + clickOnSearchToStart() { + this.setSearchValue(""); + this.cursorPosition = 0; + this.textarea.nativeElement.click(); } } \ No newline at end of file