Add: refresh on view
This commit is contained in:
parent
3e38810a49
commit
fd5eeb4b81
|
@ -44,7 +44,6 @@ const styleManager = (() => {
|
|||
}
|
||||
let id;
|
||||
port.onMessage.addListener(data => {
|
||||
console.log(data);
|
||||
if (!id) {
|
||||
id = data.id;
|
||||
}
|
||||
|
|
|
@ -93,6 +93,7 @@
|
|||
<script src="edit/colorpicker-helper.js"></script>
|
||||
<script src="edit/beautify.js"></script>
|
||||
<script src="edit/show-keymap-help.js"></script>
|
||||
<script src="edit/refresh-on-view.js"></script>
|
||||
|
||||
<script src="edit/source-editor.js"></script>
|
||||
<script src="edit/sections-editor.js"></script>
|
||||
|
|
27
edit/refresh-on-view.js
Normal file
27
edit/refresh-on-view.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* global CodeMirror */
|
||||
/*
|
||||
Initialization of the multi-sections editor is slow if there are many editors
|
||||
e.g. https://github.com/openstyles/stylus/issues/178. So we only refresh the
|
||||
editor when they were scroll into view.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
CodeMirror.defineExtension('refreshOnView', function () {
|
||||
const cm = this;
|
||||
if (typeof IntersectionObserver === 'undefined') {
|
||||
// uh
|
||||
cm.refresh();
|
||||
return;
|
||||
}
|
||||
const wrapper = cm.display.wrapper;
|
||||
const observer = new IntersectionObserver(entries => {
|
||||
for (const entry of entries) {
|
||||
if (entry.isIntersecting) {
|
||||
// wrapper.style.visibility = 'visible';
|
||||
cm.refresh();
|
||||
observer.disconnect();
|
||||
}
|
||||
}
|
||||
});
|
||||
observer.observe(wrapper);
|
||||
});
|
|
@ -547,24 +547,32 @@ function createSectionsEditor(style) {
|
|||
focusOn = 0,
|
||||
done
|
||||
}) {
|
||||
if (!originalSections.length) {
|
||||
setGlobalProgress();
|
||||
if (focusOn !== false) {
|
||||
sections[focusOn].cm.focus();
|
||||
let renderIndex = sections.length;
|
||||
container.classList.add('hidden');
|
||||
chunk();
|
||||
|
||||
function chunk() {
|
||||
if (!originalSections.length) {
|
||||
setGlobalProgress();
|
||||
if (focusOn !== false) {
|
||||
sections[focusOn].cm.focus();
|
||||
}
|
||||
container.classList.remove('hidden');
|
||||
for (; renderIndex < sections.length; renderIndex++) {
|
||||
sections[renderIndex].cm.refreshOnView();
|
||||
}
|
||||
if (done) {
|
||||
done();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (done) {
|
||||
done();
|
||||
const t0 = performance.now();
|
||||
while (originalSections.length && performance.now() - t0 < 100) {
|
||||
insertSectionAfter(originalSections.shift());
|
||||
}
|
||||
return;
|
||||
setGlobalProgress(total - originalSections.length, total);
|
||||
setTimeout(chunk);
|
||||
}
|
||||
insertSectionAfter(originalSections.shift());
|
||||
setGlobalProgress(total - originalSections.length, total);
|
||||
setTimeout(initSection, 0, {
|
||||
sections: originalSections,
|
||||
total,
|
||||
focusOn,
|
||||
done
|
||||
});
|
||||
}
|
||||
|
||||
function removeSection(section) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user