From 8a3c260eb9a83e8bdc50598f92d32a109ed1bccf Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Sat, 8 Dec 2018 07:21:06 -0600 Subject: [PATCH] Fix save template. Closes #607 --- edit/source-editor.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/edit/source-editor.js b/edit/source-editor.js index 6a4658f5..afa7daf5 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -230,21 +230,25 @@ function createSourceEditor({style, onTitleChanged}) { .then(replaceStyle) .catch(err => { if (err.handled) return; - if (err.code === 'missingMandatory' && err.args.includes('name')) { - messageBox.confirm(t('usercssReplaceTemplateConfirmation')).then(ok => ok && - chromeSync.setLZValue('usercssTemplate', code) - .then(() => chromeSync.getLZValue('usercssTemplate')) - .then(saved => saved !== code && messageBox.alert(t('syncStorageErrorSaving')))); - return; - } const contents = Array.isArray(err) ? $create('pre', err.join('\n')) : [err.message || String(err)]; if (Number.isInteger(err.index)) { const pos = cm.posFromIndex(err.index); - contents[0] += ` (line ${pos.line + 1} col ${pos.ch + 1})`; - contents.push($create('pre', drawLinePointer(pos))); + const meta = drawLinePointer(pos); + + // save template + if (err.code === 'missingValue' && meta.includes('@name')) { + messageBox.confirm(t('usercssReplaceTemplateConfirmation')).then(ok => ok && + chromeSync.setLZValue('usercssTemplate', code) + .then(() => chromeSync.getLZValue('usercssTemplate')) + .then(saved => saved !== code && messageBox.alert(t('syncStorageErrorSaving')))); + return; + } } + + contents[0] += ` (line ${pos.line + 1} col ${pos.ch + 1})`; + contents.push($create('pre', meta)); messageBox.alert(contents, 'pre'); }); }