UNPKG

@nteract/monaco-editor

Version:

A React component for the monaco editor, tailored for nteract

41 lines 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.scheduleEditorForLayout = void 0; const editorsInSchedule = new Map(); let layoutTimer = null; function executeLayout() { layoutTimer = null; const editorsToLayout = []; // do the first loop to collect editors and their dimensions for layouting, so we can read the DOM once to avoid layout thrashing for (const [editor, scheduledDimention] of editorsInSchedule) { if (editor.shouldLayout()) { let dim = scheduledDimention; if (!dim) { dim = editor.getLayoutDimension(); } // skip layout if dimension is not available if (dim) { editorsToLayout.push([editor, dim]); } } } // the second loop to execute the layouts for (const [editor, dim] of editorsToLayout) { editor.layout(dim); } editorsInSchedule.clear(); } /** * For monaco editors, we need to call layout() on any editors that might have changed size otherwise the view will look off. * These updates often happen together with other editors, such as when the window resizes. * In order to avoid layout thrashing, we batch these layout calls together and perform them all at once in a RAF timeout. */ function scheduleEditorForLayout(editor, layout) { editorsInSchedule.set(editor, layout); if (!layoutTimer) { // Using RAF here ensures that the layout will happen on the next frame. layoutTimer = requestAnimationFrame(executeLayout); } } exports.scheduleEditorForLayout = scheduleEditorForLayout; //# sourceMappingURL=layoutSchedule.js.map