Don't recreate editors after save
This commit is contained in:
parent
1dde91ea85
commit
8c7f7b81f8
26
edit.js
26
edit.js
|
@ -1088,15 +1088,23 @@ function init() {
|
||||||
// This is an edit
|
// This is an edit
|
||||||
tE("heading", "editStyleHeading", null, false);
|
tE("heading", "editStyleHeading", null, false);
|
||||||
getStylesSafe({id: params.id}).then(styles => {
|
getStylesSafe({id: params.id}).then(styles => {
|
||||||
styleId = styles[0].id;
|
const style = styles[0];
|
||||||
initWithStyle(styles[0]);
|
styleId = style.id;
|
||||||
|
initWithStyle({style});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initWithStyle(style) {
|
function initWithStyle({style, codeIsUpdated}) {
|
||||||
document.getElementById("name").value = style.name;
|
document.getElementById("name").value = style.name;
|
||||||
document.getElementById("enabled").checked = style.enabled;
|
document.getElementById("enabled").checked = style.enabled;
|
||||||
document.getElementById("url").href = style.url;
|
document.getElementById("url").href = style.url;
|
||||||
|
|
||||||
|
if (codeIsUpdated === false) {
|
||||||
|
setCleanGlobal();
|
||||||
|
updateTitle();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if this was done in response to an update, we need to clear existing sections
|
// if this was done in response to an update, we need to clear existing sections
|
||||||
getSections().forEach(function(div) { div.remove(); });
|
getSections().forEach(function(div) { div.remove(); });
|
||||||
var queue = style.sections.length ? style.sections.slice() : [{code: ""}];
|
var queue = style.sections.length ? style.sections.slice() : [{code: ""}];
|
||||||
|
@ -1247,14 +1255,14 @@ function save() {
|
||||||
}
|
}
|
||||||
var name = document.getElementById("name").value;
|
var name = document.getElementById("name").value;
|
||||||
var enabled = document.getElementById("enabled").checked;
|
var enabled = document.getElementById("enabled").checked;
|
||||||
var request = {
|
saveStyle({
|
||||||
method: "saveStyle",
|
|
||||||
id: styleId,
|
id: styleId,
|
||||||
name: name,
|
name: name,
|
||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
|
reason: 'editSave',
|
||||||
sections: getSectionsHashes()
|
sections: getSectionsHashes()
|
||||||
};
|
})
|
||||||
chrome.runtime.sendMessage(request, saveComplete);
|
.then(saveComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSectionsHashes() {
|
function getSectionsHashes() {
|
||||||
|
@ -1621,8 +1629,8 @@ function getParams() {
|
||||||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||||
switch (request.method) {
|
switch (request.method) {
|
||||||
case "styleUpdated":
|
case "styleUpdated":
|
||||||
if (styleId && styleId == request.id) {
|
if (styleId && styleId == request.style.id && request.reason != 'editSave') {
|
||||||
initWithStyle(request.style);
|
initWithStyle(request);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "styleDeleted":
|
case "styleDeleted":
|
||||||
|
|
|
@ -213,7 +213,9 @@ function saveStyle(style, {notify = true} = {}) {
|
||||||
const tx = db.transaction(['styles'], 'readwrite');
|
const tx = db.transaction(['styles'], 'readwrite');
|
||||||
const os = tx.objectStore('styles');
|
const os = tx.objectStore('styles');
|
||||||
|
|
||||||
|
const reason = style.reason;
|
||||||
delete style.method;
|
delete style.method;
|
||||||
|
delete style.reason;
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
if (style.id) {
|
if (style.id) {
|
||||||
|
@ -227,7 +229,7 @@ function saveStyle(style, {notify = true} = {}) {
|
||||||
style.id = style.id || eventPut.target.result;
|
style.id = style.id || eventPut.target.result;
|
||||||
invalidateCache(notify, {updated: style});
|
invalidateCache(notify, {updated: style});
|
||||||
if (notify) {
|
if (notify) {
|
||||||
notifyAllTabs({method: 'styleUpdated', style, codeIsUpdated});
|
notifyAllTabs({method: 'styleUpdated', style, codeIsUpdated, reason});
|
||||||
}
|
}
|
||||||
resolve(style);
|
resolve(style);
|
||||||
};
|
};
|
||||||
|
@ -250,7 +252,7 @@ function saveStyle(style, {notify = true} = {}) {
|
||||||
// Give it the ID that was generated
|
// Give it the ID that was generated
|
||||||
style.id = event.target.result;
|
style.id = event.target.result;
|
||||||
invalidateCache(true, {added: style});
|
invalidateCache(true, {added: style});
|
||||||
notifyAllTabs({method: 'styleAdded', style});
|
notifyAllTabs({method: 'styleAdded', style, reason});
|
||||||
resolve(style);
|
resolve(style);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user