From 6847681ed3b6b59265393adf3e3ce2bd30c6a6ae Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 27 Nov 2020 13:26:15 +0300 Subject: [PATCH] fix findSections for `{}` + detect reusedEnd --- edit/moz-section-finder.js | 13 ++++++++++++- edit/moz-section-widget.js | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/edit/moz-section-finder.js b/edit/moz-section-finder.js index 9d143993..8b3afe72 100644 --- a/edit/moz-section-finder.js +++ b/edit/moz-section-finder.js @@ -142,12 +142,16 @@ function MozSectionFinder(cm) { } let op; let reusedAtStart = 0; + let reusedAtEnd = 0; const removed = sections.slice(cutAt, cutTo); for (const sec of added) { const i = removed.findIndex(isSameSection, sec); if (i >= 0) { - removed[i].funcs = sec.funcs; // use the new valueStart, valueEnd + const r = removed[i]; + r.funcs = sec.funcs; // use the new valueStart, valueEnd + sec.mark = r.mark; removed[i] = null; + reusedAtEnd++; if (!op) reusedAtStart++; } else { if (!op) op = cm.curOp || (cm.startOperation(), true); @@ -156,8 +160,11 @@ function MozSectionFinder(cm) { inclusiveRight: true, [KEY]: sec, }); + reusedAtEnd = 0; } } + added.length -= reusedAtEnd; + cutTo -= reusedAtEnd; if (reusedAtStart) { cutAt += reusedAtStart; added.splice(0, reusedAtStart); @@ -321,6 +328,10 @@ function MozSectionFinder(cm) { valueEnd: url.end, }); s = text.slice(ch, styles[j]).trim(); + if (s.includes('}')) { // a single `null` token like ` { } ` + goal = ''; + break; + } goal = s.startsWith(',') ? '_func' : s.startsWith('{') ? '_cmt' : !s && '_,'; // non-space something at this place = syntax error diff --git a/edit/moz-section-widget.js b/edit/moz-section-widget.js index fcb6fce5..f3a0b2fe 100644 --- a/edit/moz-section-widget.js +++ b/edit/moz-section-widget.js @@ -277,7 +277,7 @@ function MozSectionWidget( function renderWidget(sec, old) { let widget = old && old.widget; - const height = funcHeight * (sec.funcs.length || 1) || undefined; + const height = Math.round(funcHeight * (sec.funcs.length || 1)) || undefined; const node = renderContainer(sec, widget); if (widget) { widget.node = node;