Skip to content

Commit

Permalink
feat: added sub/unsub for resize observer
Browse files Browse the repository at this point in the history
  • Loading branch information
bhlynsky committed Jan 11, 2023
1 parent 1d888aa commit 84c657b
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/plugins/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ export class UIPEditor extends UIPPlugin {
protected connectedCallback() {
super.connectedCallback();
this.initEditor();
this.resizeObserver.observe(this);
}

protected disconnectedCallback() {
super.disconnectedCallback();
this.resizeObserver.unobserve(this);
}

/** Initialize [Ace]{@link https://ace.c9.io/} editor. */
Expand All @@ -76,8 +78,6 @@ export class UIPEditor extends UIPPlugin {
this.editor.setOption('useWorker', false);
this.editor.setOption('mode', 'ace/mode/html');
this.initEditorOptions();

this._handlePageResize();
}

protected initEditorOptions(): void {
Expand Down Expand Up @@ -108,11 +108,7 @@ export class UIPEditor extends UIPPlugin {
}

/* prevents editor content from overflowing when toggling settings section or sidebar */
protected _handlePageResize() {
const obs = new ResizeObserver(debounce(() => this.editor.resize(),500));

obs.observe(this);
}
protected resizeObserver = new ResizeObserver(debounce(() => this.editor.resize(), 500));


/** Callback to catch theme changes from {@link UIPRoot}. */
Expand Down

0 comments on commit 84c657b

Please sign in to comment.