Change: kill editors, styleId

This commit is contained in:
eight 2018-10-10 16:32:39 +08:00
parent 6494985b50
commit 4419c5dc1e
5 changed files with 19 additions and 12 deletions

View File

@ -1,6 +1,6 @@
/*
global CodeMirror loadScript css_beautify
global editors getSectionForChild showHelp
global getSectionForChild showHelp
*/
'use strict';

View File

@ -349,6 +349,9 @@ input:invalid {
.section:only-of-type .move-section-down {
display: none;
}
.section .CodeMirror {
margin: .5rem 0;
}
/* deleted section */
.section .deleted-section {
display: none;

View File

@ -1,4 +1,4 @@
/* global editors messageBox */
/* global messageBox editor */
'use strict';
function createLivePreview(preprocess) {
@ -56,7 +56,7 @@ function createLivePreview(preprocess) {
err = err.join('\n');
} else if (err && err.index !== undefined) {
// FIXME: this would fail if editors[0].getValue() !== data.sourceCode
const pos = editors[0].posFromIndex(err.index);
const pos = editor.getEditors()[0].posFromIndex(err.index);
err.message = `${pos.line}:${pos.ch} ${err.message || String(err)}`;
}
errorContainer.classList.remove('hidden');

View File

@ -96,7 +96,7 @@ function createSectionsEditor(style) {
$('#to-mozilla').addEventListener('click', showMozillaFormat);
$('#to-mozilla-help').addEventListener('click', showToMozillaHelp);
$('#from-mozilla').addEventListener('click', fromMozillaFormat);
$('#from-mozilla').addEventListener('click', () => fromMozillaFormat());
$('#save-button').addEventListener('click', saveStyle);
$('#sections-help').addEventListener('click', showSectionHelp);
@ -262,7 +262,7 @@ function createSectionsEditor(style) {
}
function scrollToEditor(cm) {
const section = sections.find(s => s.cm === cm);
const section = sections.find(s => s.cm === cm).el;
const bounds = section.getBoundingClientRect();
if (
(bounds.bottom > window.innerHeight && bounds.top > 0) ||
@ -462,6 +462,9 @@ function createSectionsEditor(style) {
}
function saveStyle() {
if (!dirty.isDirty()) {
return;
}
const newStyle = getModel();
if (!validate(newStyle)) {
return;
@ -844,10 +847,15 @@ function createSectionsEditor(style) {
const removeButton = $('.remove-applies-to', el);
if (removeButton) {
removeButton.addEventListener('click', () => removeApply(apply));
removeButton.addEventListener('click', e => {
e.preventDefault();
removeApply(apply);
});
}
$('.add-applies-to', el).addEventListener('click', () =>
insertApplyAfter({type, value: ''}, apply));
$('.add-applies-to', el).addEventListener('click', e => {
e.preventDefault();
insertApplyAfter({type, value: ''}, apply);
});
return apply;

View File

@ -1,5 +1,4 @@
/*
global editors styleId: true
global CodeMirror dirtyReporter
global createAppliesToLineWidget messageBox
global sectionsToMozFormat
@ -34,8 +33,6 @@ function createSourceEditor(style) {
});
let savedGeneration = cm.changeGeneration();
editors.push(cm);
const livePreview = createLivePreview(preprocess);
livePreview.show(Boolean(style.id));
@ -222,7 +219,6 @@ function createSourceEditor(style) {
}
sessionStorage.justEditedStyleId = newStyle.id;
style = newStyle;
styleId = style.id;
$('#preview-label').classList.remove('hidden');
updateMeta();
livePreview.show(Boolean(style.id));