fix findSections for {} + detect reusedEnd

This commit is contained in:
tophf 2020-11-27 13:26:15 +03:00
parent a87c49f0fc
commit 6847681ed3
2 changed files with 13 additions and 2 deletions

View File

@ -142,12 +142,16 @@ function MozSectionFinder(cm) {
} }
let op; let op;
let reusedAtStart = 0; let reusedAtStart = 0;
let reusedAtEnd = 0;
const removed = sections.slice(cutAt, cutTo); const removed = sections.slice(cutAt, cutTo);
for (const sec of added) { for (const sec of added) {
const i = removed.findIndex(isSameSection, sec); const i = removed.findIndex(isSameSection, sec);
if (i >= 0) { 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; removed[i] = null;
reusedAtEnd++;
if (!op) reusedAtStart++; if (!op) reusedAtStart++;
} else { } else {
if (!op) op = cm.curOp || (cm.startOperation(), true); if (!op) op = cm.curOp || (cm.startOperation(), true);
@ -156,8 +160,11 @@ function MozSectionFinder(cm) {
inclusiveRight: true, inclusiveRight: true,
[KEY]: sec, [KEY]: sec,
}); });
reusedAtEnd = 0;
} }
} }
added.length -= reusedAtEnd;
cutTo -= reusedAtEnd;
if (reusedAtStart) { if (reusedAtStart) {
cutAt += reusedAtStart; cutAt += reusedAtStart;
added.splice(0, reusedAtStart); added.splice(0, reusedAtStart);
@ -321,6 +328,10 @@ function MozSectionFinder(cm) {
valueEnd: url.end, valueEnd: url.end,
}); });
s = text.slice(ch, styles[j]).trim(); s = text.slice(ch, styles[j]).trim();
if (s.includes('}')) { // a single `null` token like ` { } `
goal = '';
break;
}
goal = s.startsWith(',') ? '_func' : goal = s.startsWith(',') ? '_func' :
s.startsWith('{') ? '_cmt' : s.startsWith('{') ? '_cmt' :
!s && '_,'; // non-space something at this place = syntax error !s && '_,'; // non-space something at this place = syntax error

View File

@ -277,7 +277,7 @@ function MozSectionWidget(
function renderWidget(sec, old) { function renderWidget(sec, old) {
let widget = old && old.widget; 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); const node = renderContainer(sec, widget);
if (widget) { if (widget) {
widget.node = node; widget.node = node;