From 4419c5dc1e584f420a3acd204b85fd0661442b27 Mon Sep 17 00:00:00 2001 From: eight Date: Wed, 10 Oct 2018 16:32:39 +0800 Subject: [PATCH] Change: kill editors, styleId --- edit/beautify.js | 2 +- edit/edit.css | 3 +++ edit/live-preview.js | 4 ++-- edit/sections-editor.js | 18 +++++++++++++----- edit/source-editor.js | 4 ---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/edit/beautify.js b/edit/beautify.js index 92de7509..617c98f4 100644 --- a/edit/beautify.js +++ b/edit/beautify.js @@ -1,6 +1,6 @@ /* global CodeMirror loadScript css_beautify -global editors getSectionForChild showHelp +global getSectionForChild showHelp */ 'use strict'; diff --git a/edit/edit.css b/edit/edit.css index cf18f632..46716642 100644 --- a/edit/edit.css +++ b/edit/edit.css @@ -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; diff --git a/edit/live-preview.js b/edit/live-preview.js index 81ab76c5..f02a5cbd 100644 --- a/edit/live-preview.js +++ b/edit/live-preview.js @@ -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'); diff --git a/edit/sections-editor.js b/edit/sections-editor.js index 6cb737d0..db2f2be1 100644 --- a/edit/sections-editor.js +++ b/edit/sections-editor.js @@ -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; diff --git a/edit/source-editor.js b/edit/source-editor.js index 6415ae38..baaa22b1 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -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));