Fix: separate toggle
This commit is contained in:
parent
7e61ea9691
commit
7a0d00a4ba
11
edit/edit.js
11
edit/edit.js
|
@ -1,5 +1,5 @@
|
|||
/* global $ $create messageBoxProxy waitForSheet */// dom.js
|
||||
/* global msg */// msg.js
|
||||
/* global msg API */// msg.js
|
||||
/* global CodeMirror */
|
||||
/* global SectionsEditor */
|
||||
/* global SourceEditor */
|
||||
|
@ -70,7 +70,14 @@ msg.onExtension(request => {
|
|||
switch (request.method) {
|
||||
case 'styleUpdated':
|
||||
if (editor.style.id === style.id && !IGNORE_UPDATE_REASONS.includes(request.reason)) {
|
||||
editor.emit('styleChange', request.style, request.reason, request.codeIsUpdated);
|
||||
if (request.reason === 'toggle') {
|
||||
editor.emit('styleToggled', request.style);
|
||||
} else {
|
||||
API.styles.get(request.style.id)
|
||||
.then(style => {
|
||||
editor.emit('styleChange', style, request.reason);
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'styleDeleted':
|
||||
|
|
|
@ -128,18 +128,18 @@ function SectionsEditor() {
|
|||
|
||||
editor.ready = initSections(style.sections);
|
||||
|
||||
editor.on('styleChange', async (newStyle, reason) => {
|
||||
if (reason === 'new') return; // nothing is new for us
|
||||
if (reason === 'toggle') {
|
||||
if (!dirty.isDirty()) {
|
||||
Object.assign(style, newStyle);
|
||||
updateHeader();
|
||||
}
|
||||
updateLivePreview();
|
||||
return;
|
||||
editor.on('styleToggled', newStyle => {
|
||||
if (!dirty.isDirty()) {
|
||||
Object.assign(style, newStyle);
|
||||
} else {
|
||||
editor.toggleStyle(newStyle.enabled);
|
||||
}
|
||||
updateHeader();
|
||||
updateLivePreview();
|
||||
});
|
||||
editor.on('styleChange', (newStyle, reason) => {
|
||||
if (reason === 'new') return; // nothing is new for us
|
||||
if (reason === 'config') {
|
||||
newStyle = await API.styles.get(newStyle.id);
|
||||
delete newStyle.sections;
|
||||
delete newStyle.name;
|
||||
delete newStyle.enabled;
|
||||
|
@ -147,7 +147,7 @@ function SectionsEditor() {
|
|||
updateLivePreview();
|
||||
return;
|
||||
}
|
||||
editor.replaceStyle(await API.styles.get(newStyle.id));
|
||||
editor.replaceStyle(newStyle);
|
||||
});
|
||||
|
||||
/** @param {EditorSection} section */
|
||||
|
|
|
@ -116,27 +116,25 @@ function SourceEditor() {
|
|||
if (!$isTextInput(document.activeElement)) {
|
||||
cm.focus();
|
||||
}
|
||||
editor.on('styleChange', async (newStyle, reason) => {
|
||||
editor.on('styleToggled', newStyle => {
|
||||
if (dirty.isDirty()) {
|
||||
editor.toggleStyle(newStyle.enabled);
|
||||
} else {
|
||||
style.enabled = newStyle.enabled;
|
||||
}
|
||||
updateMeta();
|
||||
updateLivePreview();
|
||||
});
|
||||
editor.on('styleChange', (newStyle, reason) => {
|
||||
if (reason === 'new') return;
|
||||
if (reason === 'config') {
|
||||
newStyle = await API.styles.get(newStyle.id);
|
||||
delete newStyle.sourceCode;
|
||||
delete newStyle.name;
|
||||
Object.assign(style, newStyle);
|
||||
updateLivePreview();
|
||||
return;
|
||||
}
|
||||
if (reason === 'toggle') {
|
||||
if (dirty.isDirty()) {
|
||||
editor.toggleStyle(newStyle.enabled);
|
||||
} else {
|
||||
style.enabled = newStyle.enabled;
|
||||
}
|
||||
updateMeta();
|
||||
updateLivePreview();
|
||||
return;
|
||||
}
|
||||
replaceStyle(await API.styles.get(newStyle.id));
|
||||
replaceStyle(newStyle);
|
||||
});
|
||||
|
||||
async function preprocess(style) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user