Commit b459d75fb6c0f9d12af8a634c602f67f06159bd8

Authored by Vladyslav
Committed by GitHub
1 parent c654f1ad

Improvement resize (#2654)

... ... @@ -65,7 +65,7 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl
65 65
66 66 aceEditors: ace.Ace.Editor[] = [];
67 67 editorsResizeCafs: {[editorId: string]: CancelAnimationFrame} = {};
68   - aceResizeObservers: ResizeObserver[] = [];
  68 + aceResize$: ResizeObserver;
69 69 htmlEditor: ace.Ace.Editor;
70 70 cssEditor: ace.Ace.Editor;
71 71 setValuesPending = false;
... ... @@ -85,9 +85,7 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl
85 85 }
86 86
87 87 ngOnDestroy(): void {
88   - this.aceResizeObservers.forEach((resize$) => {
89   - resize$.disconnect();
90   - });
  88 + this.aceResize$.disconnect();
91 89 }
92 90
93 91 ngOnChanges(changes: SimpleChanges): void {
... ... @@ -153,6 +151,12 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl
153 151 }
154 152
155 153 private initAceEditors() {
  154 + this.aceResize$ = new ResizeObserver((enteris) => {
  155 + enteris.forEach((entry) => {
  156 + const editor = this.aceEditors.find(aceEditor => aceEditor.container === entry.target);
  157 + this.onAceEditorResize(editor);
  158 + })
  159 + });
156 160 this.htmlEditor = this.createAceEditor(this.htmlInputElmRef, 'html');
157 161 this.htmlEditor.on('input', () => {
158 162 const editorValue = this.htmlEditor.getValue();
... ... @@ -187,12 +191,7 @@ export class CustomActionPrettyResourcesTabsComponent extends PageComponent impl
187 191 const aceEditor = ace.edit(editorElement, editorOptions);
188 192 aceEditor.session.setUseWrapMode(true);
189 193 this.aceEditors.push(aceEditor);
190   -
191   - const resize$ = new ResizeObserver(() => {
192   - this.onAceEditorResize(aceEditor);
193   - });
194   - resize$.observe(editorElement);
195   - this.aceResizeObservers.push(resize$);
  194 + this.aceResize$.observe(editorElement);
196 195 return aceEditor;
197 196 }
198 197
... ...
... ... @@ -125,7 +125,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
125 125 jsonSettingsEditor: ace.Ace.Editor;
126 126 dataKeyJsonSettingsEditor: ace.Ace.Editor;
127 127 jsEditor: ace.Ace.Editor;
128   - aceResizeObservers: ResizeObserver[] = [];
  128 + aceResize$: ResizeObserver;
129 129
130 130 onWindowMessageListener = this.onWindowMessage.bind(this);
131 131
... ... @@ -194,9 +194,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
194 194
195 195 ngOnDestroy(): void {
196 196 this.window.removeEventListener('message', this.onWindowMessageListener);
197   - this.aceResizeObservers.forEach((resize$) => {
198   - resize$.disconnect();
199   - });
  197 + this.aceResize$.disconnect();
200 198 this.rxSubscriptions.forEach((subscription) => {
201 199 subscription.unsubscribe();
202 200 });
... ... @@ -272,6 +270,12 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
272 270 }
273 271
274 272 private initAceEditors() {
  273 + this.aceResize$ = new ResizeObserver((enteris) => {
  274 + enteris.forEach((entry) => {
  275 + const editor = this.aceEditors.find(aceEditor => aceEditor.container === entry.target);
  276 + this.onAceEditorResize(editor);
  277 + })
  278 + });
275 279 this.htmlEditor = this.createAceEditor(this.htmlInputElmRef, 'html');
276 280 this.htmlEditor.on('input', () => {
277 281 const editorValue = this.htmlEditor.getValue();
... ... @@ -342,12 +346,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
342 346 const aceEditor = ace.edit(editorElement, editorOptions);
343 347 aceEditor.session.setUseWrapMode(true);
344 348 this.aceEditors.push(aceEditor);
345   -
346   - const resize$ = new ResizeObserver(() => {
347   - this.onAceEditorResize(aceEditor);
348   - });
349   - resize$.observe(editorElement);
350   - this.aceResizeObservers.push(resize$);
  349 + this.aceResize$.observe(editorElement);
351 350 return aceEditor;
352 351 }
353 352
... ...