Skip to content

Commit

Permalink
Add basic search shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
Waguramu committed Aug 9, 2024
1 parent 63c800e commit c83fc2f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
1 change: 1 addition & 0 deletions erdblick_app/app/inspection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
45 changes: 23 additions & 22 deletions erdblick_app/app/search.panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
}

0 comments on commit c83fc2f

Please sign in to comment.