Skip to content

Commit

Permalink
fix: editorMosaic.layout() called w/ wrong context (electron#752)
Browse files Browse the repository at this point in the history
Change EditorMosaic.layout to be an arrow function so that the proper
'this' context is baked in. Fixes electron#751
  • Loading branch information
ckerr authored Jun 30, 2021
1 parent 0289478 commit a6cb08d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/renderer/editor-mosaic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ export class EditorMosaic {
this.customMosaics = this.customMosaics.filter((mosaic) => mosaic !== id);
}


/** Wire up a newly-mounted Monaco editor */
@action public addEditor(id: EditorId, editor: Editor) {
const backup = this.backups.get(id);
Expand Down Expand Up @@ -247,15 +246,15 @@ export class EditorMosaic {

private layoutDebounce: ReturnType<typeof setTimeout> | undefined;

public layout() {
public layout = () => {
const DEBOUNCE_MSEC = 50;
if (!this.layoutDebounce) {
this.layoutDebounce = setTimeout(() => {
for (const editor of this.editors.values()) editor.layout();
delete this.layoutDebounce;
}, DEBOUNCE_MSEC);
}
}
};

public focusedEditor(): Editor | undefined {
return [...this.editors.values()].find((editor) => editor.hasTextFocus());
Expand Down

0 comments on commit a6cb08d

Please sign in to comment.