From dbba33822933e47d29e37a72c3b815bc093876ec Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 11 Mar 2018 16:47:27 +0300 Subject: [PATCH] report line:ch in live-preview errors for usercss --- edit/codemirror-editing-hooks.js | 4 ++++ js/usercss.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/edit/codemirror-editing-hooks.js b/edit/codemirror-editing-hooks.js index f2923894..3a8d436f 100644 --- a/edit/codemirror-editing-hooks.js +++ b/edit/codemirror-editing-hooks.js @@ -623,6 +623,10 @@ onDOMscriptReady('/codemirror.js').then(() => { }).then(() => { errors.classList.add('hidden'); }).catch(err => { + if (err && editor && !Number.isNaN(err.index)) { + const pos = editors[0].posFromIndex(err.index); + err = `${pos.line}:${pos.ch} ${err}`; + } errors.classList.remove('hidden'); errors.onclick = () => messageBox.alert(String(err), 'pre'); }); diff --git a/js/usercss.js b/js/usercss.js index cffa2204..46e213c7 100644 --- a/js/usercss.js +++ b/js/usercss.js @@ -450,8 +450,8 @@ var usercss = (() => { try { doParse(); } catch (e) { - // grab additional info - e.index = metaIndex; + // the source code string offset + e.index = metaIndex + state.re.lastIndex; throw e; }