From c5f072f6b6073ac07e8d999c754e612225cd81a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 26 Sep 2024 15:11:00 +0300 Subject: [PATCH] RED-9757: Working find panel toggle --- .../edit-dossier-dictionary.component.html | 49 ++++--------------- .../edit-dossier-dictionary.component.scss | 33 ++----------- .../dictionary-manager.component.html | 4 +- .../dictionary-manager.component.ts | 14 +++++- .../components/editor/editor.component.ts | 23 +++++++-- 5 files changed, 50 insertions(+), 73 deletions(-) diff --git a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.html b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.html index 7d5b0684e..e3d988163 100644 --- a/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.html +++ b/apps/red-ui/src/app/modules/shared-dossiers/dialogs/edit-dossier-dialog/dictionary/edit-dossier-dictionary.component.html @@ -33,44 +33,15 @@
-
-
-
-
- {{ selectedDictionary?.label }} - -
-
-
- - - {{ - 'edit-dossier-dialog.dictionary.entries' - | translate: { length: entriesToDisplay.length, hint: selectedDictionary.hint } - }} - - - {{ - 'edit-dossier-dialog.dictionary.false-positive-entries' | translate: { length: entriesToDisplay.length } - }} - - - {{ - 'edit-dossier-dialog.dictionary.false-recommendation-entries' - | translate: { length: entriesToDisplay.length } - }} - -
-
-
-
+
+ {{ selectedDictionary?.label }} +
-
+
div { - font-weight: 600; - } - } - } + overflow: hidden; } } diff --git a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html index 4557166e6..c1429100c 100644 --- a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html +++ b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html @@ -13,7 +13,8 @@ > = this.#dictionaries; + protected readonly _isSearchOpen = signal(false); protected initialDossierTemplateId: string; readonly #currentTab = window.location.href.split('/').pop(); #dossierTemplate = this.dossierTemplatesService.all[0]; diff --git a/apps/red-ui/src/app/modules/shared/components/editor/editor.component.ts b/apps/red-ui/src/app/modules/shared/components/editor/editor.component.ts index 45a452d89..e2538f236 100644 --- a/apps/red-ui/src/app/modules/shared/components/editor/editor.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/editor/editor.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'; +import { Component, Input, model, OnChanges, OnInit, SimpleChanges, untracked } from '@angular/core'; import { LoadingService } from '@iqser/common-ui'; import { EditorThemeService } from '@services/editor-theme.service'; import { Subject } from 'rxjs'; @@ -39,6 +39,7 @@ export class EditorComponent implements OnInit, OnChanges { @Input() diffEditorText: string; @Input() @OnChange('revert') initialEntries: List; @Input() canEdit = false; + readonly isSearchOpen = model.required(); /** * Used as [modified] input on diff editor * Shouldn't be updated when editing in diff editor. @@ -84,9 +85,14 @@ export class EditorComponent implements OnInit, OnChanges { return this.currentEntries.length; } - async openFindPanel(): Promise { + async toggleFindPanel(): Promise { + const isFindPanelOpen = untracked(this.isSearchOpen); const editor = this.showDiffEditor ? this._diffEditor.getOriginalEditor() : this.codeEditor; - await editor.getAction('actions.find').run(); + if (isFindPanelOpen) { + await (editor.getContribution('editor.contrib.findController') as any).closeFindWidget(); + } else { + await editor.getAction('actions.find').run(); + } } onPaste(event: ClipboardEvent) { @@ -127,11 +133,13 @@ export class EditorComponent implements OnInit, OnChanges { this._diffEditor.getModifiedEditor().onDidChangeModelContent(() => { this.value = this._diffEditor.getModel().modified.getValue(); }); + this._initializeFindWidget(editor.getOriginalEditor()); this.#setTheme(); } onCodeEditorInit(editor: MonacoStandaloneCodeEditor): void { this.codeEditor = editor; + this._initializeFindWidget(editor); this.#setTheme(); } @@ -143,6 +151,15 @@ export class EditorComponent implements OnInit, OnChanges { this._editorTextChanged$.next(this.value); } + private _initializeFindWidget(editor: MonacoStandaloneCodeEditor): void { + this.isSearchOpen.set(false); + (editor.getContribution('editor.contrib.findController') as any).getState().onFindReplaceStateChange(event => { + if (event.isRevealed) { + this.isSearchOpen.update(v => !v); + } + }); + } + #getDecorations(newText: string) { const currentEntries = newText.split('\n'); const newDecorations: IModelDeltaDecoration[] = [];