RED-6786: fix editor performance issues
This commit is contained in:
parent
e2619e9805
commit
c2753e6e10
@ -83,7 +83,6 @@
|
||||
[diffEditorText]="diffEditorText"
|
||||
[initialEntries]="initialEntries"
|
||||
[showDiffEditor]="compare && showDiffEditor"
|
||||
(enableSaveButton)="onEnableSaveButton($event)"
|
||||
></redaction-editor>
|
||||
|
||||
<div *ngIf="compare && optionNotSelected" class="no-dictionary-selected">
|
||||
@ -97,7 +96,6 @@
|
||||
(action)="saveDictionary.emit()"
|
||||
[label]="'dictionary-overview.save-changes' | translate"
|
||||
[type]="iconButtonTypes.primary"
|
||||
[disabled]="!(saveButtonEnabled$ | async)"
|
||||
icon="iqser:check"
|
||||
></iqser-icon-button>
|
||||
<div (click)="revert()" class="all-caps-label cancel" translate="dictionary-overview.revert-changes"></div>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewChild } from '@angular/core';
|
||||
import { Debounce, IconButtonTypes, List, LoadingService } from '@iqser/common-ui';
|
||||
import { BehaviorSubject, firstValueFrom, Observable, of } from 'rxjs';
|
||||
import { firstValueFrom, Observable, of } from 'rxjs';
|
||||
import { catchError, map, take, tap } from 'rxjs/operators';
|
||||
import { Dictionary, DICTIONARY_TYPE_KEY_MAP, DictionaryType, Dossier, DossierTemplate } from '@red/domain';
|
||||
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
||||
@ -27,7 +27,6 @@ const HELP_MODE_KEYS = {
|
||||
})
|
||||
export class DictionaryManagerComponent implements OnChanges {
|
||||
readonly iconButtonTypes = IconButtonTypes;
|
||||
readonly saveButtonEnabled$ = new BehaviorSubject(true);
|
||||
|
||||
@Input() type: DictionaryType = 'dictionary';
|
||||
@Input() entityType?: string;
|
||||
@ -212,10 +211,6 @@ export class DictionaryManagerComponent implements OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
onEnableSaveButton(value: boolean) {
|
||||
this.saveButtonEnabled$.next(value);
|
||||
}
|
||||
|
||||
private _applySearchDecorations() {
|
||||
this._searchDecorations = this.editor.codeEditor?.deltaDecorations(this._searchDecorations, []) || [];
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
|
||||
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
|
||||
import { Debounce, List, LoadingService, OnChange } from '@iqser/common-ui';
|
||||
import { EditorThemeService } from '@services/editor-theme.service';
|
||||
import IStandaloneEditorConstructionOptions = monaco.editor.IStandaloneEditorConstructionOptions;
|
||||
@ -30,7 +30,6 @@ export class EditorComponent implements OnInit, OnChanges {
|
||||
@Input() diffEditorText: string;
|
||||
@Input() @OnChange<List, EditorComponent>('revert') initialEntries: List;
|
||||
@Input() canEdit = false;
|
||||
@Output() enableSaveButton = new EventEmitter<boolean>();
|
||||
|
||||
/**
|
||||
* Used as [modified] input on diff editor
|
||||
@ -94,11 +93,27 @@ export class EditorComponent implements OnInit, OnChanges {
|
||||
|
||||
@Debounce()
|
||||
codeEditorTextChanged() {
|
||||
const newDecorations = this.currentEntries.filter(entry => this._isNew(entry)).map(entry => this._getDecoration(entry));
|
||||
const newDecorations = this._getDecorations();
|
||||
this._decorations = this.codeEditor.deltaDecorations(this._decorations, newDecorations);
|
||||
this.diffValue = this.value;
|
||||
this._loadingService.stop();
|
||||
this.enableSaveButton.emit(true);
|
||||
}
|
||||
|
||||
_getDecorations() {
|
||||
const currentEntries = this.currentEntries;
|
||||
const newDecorations: IModelDeltaDecoration[] = [];
|
||||
|
||||
for (let index = 0; index < currentEntries.length; ++index) {
|
||||
const entry = currentEntries.at(index);
|
||||
if (!this._isNew(entry)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const line = index + 1;
|
||||
newDecorations.push(this._getDecoration(entry, line));
|
||||
}
|
||||
|
||||
return newDecorations;
|
||||
}
|
||||
|
||||
revert() {
|
||||
@ -109,7 +124,6 @@ export class EditorComponent implements OnInit, OnChanges {
|
||||
|
||||
onPaste() {
|
||||
this._loadingService.start();
|
||||
this.enableSaveButton.emit(false);
|
||||
}
|
||||
|
||||
private _defineThemes(): void {
|
||||
@ -168,8 +182,7 @@ export class EditorComponent implements OnInit, OnChanges {
|
||||
return this.initialEntries.indexOf(entry) < 0 && entry?.trim().length > 0;
|
||||
}
|
||||
|
||||
private _getDecoration(entry: string): IModelDeltaDecoration {
|
||||
const line = this.currentEntries.indexOf(entry) + 1;
|
||||
private _getDecoration(entry: string, line: number): IModelDeltaDecoration {
|
||||
const cssClass = entry.length < MIN_WORD_LENGTH ? 'too-short-marker' : 'changed-row-marker';
|
||||
const range = new monaco.Range(line, 1, line, 1);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user