fix fitToContent when cloning section
This commit is contained in:
parent
63ca5cdf3e
commit
be1c865d7a
11
edit/edit.js
11
edit/edit.js
|
@ -87,16 +87,19 @@ lazyInit();
|
||||||
|
|
||||||
$('#heading').textContent = t(style.id ? 'editStyleHeading' : 'addStyleTitle');
|
$('#heading').textContent = t(style.id ? 'editStyleHeading' : 'addStyleTitle');
|
||||||
$('#preview-label').classList.toggle('hidden', !style.id);
|
$('#preview-label').classList.toggle('hidden', !style.id);
|
||||||
|
|
||||||
const toc = [];
|
const toc = [];
|
||||||
const elToc = $('#toc');
|
const elToc = $('#toc');
|
||||||
elToc.onclick = e => editor.jumpToEditor([...elToc.children].indexOf(e.target));
|
elToc.onclick = e => editor.jumpToEditor([...elToc.children].indexOf(e.target));
|
||||||
|
if (editor.isUsercss) {
|
||||||
(editor.isUsercss ? SourceEditor : SectionsEditor)();
|
SourceEditor();
|
||||||
|
} else {
|
||||||
|
SectionsEditor();
|
||||||
|
}
|
||||||
prefs.subscribe('editor.toc.expanded', (k, val) => val && editor.updateToc(), {now: true});
|
prefs.subscribe('editor.toc.expanded', (k, val) => val && editor.updateToc(), {now: true});
|
||||||
dirty.onChange(updateDirty);
|
dirty.onChange(updateDirty);
|
||||||
|
|
||||||
await editor.ready;
|
await editor.ready;
|
||||||
|
editor.ready = true;
|
||||||
|
|
||||||
setTimeout(() => editor.getEditors().forEach(linter.enableForEditor));
|
setTimeout(() => editor.getEditors().forEach(linter.enableForEditor));
|
||||||
// enabling after init to prevent flash of validation failure on an empty name
|
// enabling after init to prevent flash of validation failure on an empty name
|
||||||
|
|
|
@ -29,7 +29,9 @@ function createSection(originalSection, genId, si) {
|
||||||
const elLabel = $('.code-label', el);
|
const elLabel = $('.code-label', el);
|
||||||
const cm = cmFactory.create(wrapper => {
|
const cm = cmFactory.create(wrapper => {
|
||||||
// making it tall during initial load so IntersectionObserver sees only one adjacent CM
|
// making it tall during initial load so IntersectionObserver sees only one adjacent CM
|
||||||
|
if (editor.ready !== true) {
|
||||||
wrapper.style.height = si ? si.height : '100vh';
|
wrapper.style.height = si ? si.height : '100vh';
|
||||||
|
}
|
||||||
elLabel.after(wrapper);
|
elLabel.after(wrapper);
|
||||||
}, {
|
}, {
|
||||||
value: originalSection.code,
|
value: originalSection.code,
|
||||||
|
|
|
@ -142,7 +142,7 @@ function SectionsEditor() {
|
||||||
|
|
||||||
/** @param {EditorSection} section */
|
/** @param {EditorSection} section */
|
||||||
function fitToContent(section) {
|
function fitToContent(section) {
|
||||||
const {el, cm, cm: {display: {wrapper, sizer}}} = section;
|
const {cm, cm: {display: {wrapper, sizer}}} = section;
|
||||||
if (cm.display.renderedView) {
|
if (cm.display.renderedView) {
|
||||||
resize();
|
resize();
|
||||||
} else {
|
} else {
|
||||||
|
@ -155,7 +155,7 @@ function SectionsEditor() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (headerOffset == null) {
|
if (headerOffset == null) {
|
||||||
headerOffset = el.getBoundingClientRect().top;
|
headerOffset = container.getBoundingClientRect().top;
|
||||||
}
|
}
|
||||||
contentHeight += 9; // border & resize grip
|
contentHeight += 9; // border & resize grip
|
||||||
cm.off('update', resize);
|
cm.off('update', resize);
|
||||||
|
@ -582,9 +582,10 @@ function SectionsEditor() {
|
||||||
}
|
}
|
||||||
const section = createSection(init, genId, si);
|
const section = createSection(init, genId, si);
|
||||||
const {cm} = section;
|
const {cm} = section;
|
||||||
sections.splice(base ? sections.indexOf(base) + 1 : sections.length, 0, section);
|
const index = base ? sections.indexOf(base) + 1 : sections.length;
|
||||||
|
sections.splice(index, 0, section);
|
||||||
container.insertBefore(section.el, base ? base.el.nextSibling : null);
|
container.insertBefore(section.el, base ? base.el.nextSibling : null);
|
||||||
refreshOnView(cm, forceRefresh);
|
refreshOnView(cm, base || forceRefresh);
|
||||||
registerEvents(section);
|
registerEvents(section);
|
||||||
if ((!si || !si.height) && (!base || init.code)) {
|
if ((!si || !si.height) && (!base || init.code)) {
|
||||||
// Fit a) during startup or b) when the clone button is clicked on a section with some code
|
// Fit a) during startup or b) when the clone button is clicked on a section with some code
|
||||||
|
@ -592,7 +593,7 @@ function SectionsEditor() {
|
||||||
}
|
}
|
||||||
if (base) {
|
if (base) {
|
||||||
cm.focus();
|
cm.focus();
|
||||||
setTimeout(editor.scrollToEditor, 0, cm);
|
editor.scrollToEditor(cm);
|
||||||
linter.enableForEditor(cm);
|
linter.enableForEditor(cm);
|
||||||
}
|
}
|
||||||
updateSectionOrder();
|
updateSectionOrder();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user