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 CodeMirror loadScript css_beautify
global editors getSectionForChild showHelp global getSectionForChild showHelp
*/ */
'use strict'; 'use strict';

View File

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

View File

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

View File

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

View File

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