fix updateToc focus on a newly added section
This commit is contained in:
parent
044907fa35
commit
ac174f61cb
20
edit/edit.js
20
edit/edit.js
|
@ -300,16 +300,9 @@ lazyInit();
|
||||||
function updateToc(added = editor.sections) {
|
function updateToc(added = editor.sections) {
|
||||||
const {sections} = editor;
|
const {sections} = editor;
|
||||||
const first = sections.indexOf(added[0]);
|
const first = sections.indexOf(added[0]);
|
||||||
let el = elToc.children[first];
|
const elFirst = elToc.children[first];
|
||||||
if (added.focus) {
|
if (first >= 0 && (!added.focus || !elFirst)) {
|
||||||
const cls = 'current';
|
for (let el = elFirst, i = first; i < sections.length; i++) {
|
||||||
const old = $('.' + cls, elToc);
|
|
||||||
if (old && old !== el) old.classList.remove(cls);
|
|
||||||
el.classList.add(cls);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (first >= 0) {
|
|
||||||
for (let i = first; i < sections.length; i++) {
|
|
||||||
const entry = sections[i].tocEntry;
|
const entry = sections[i].tocEntry;
|
||||||
if (!deepEqual(entry, toc[i])) {
|
if (!deepEqual(entry, toc[i])) {
|
||||||
if (!el) el = elToc.appendChild($create('li', {tabIndex: 0}));
|
if (!el) el = elToc.appendChild($create('li', {tabIndex: 0}));
|
||||||
|
@ -328,6 +321,13 @@ lazyInit();
|
||||||
elToc.lastElementChild.remove();
|
elToc.lastElementChild.remove();
|
||||||
toc.length--;
|
toc.length--;
|
||||||
}
|
}
|
||||||
|
if (added.focus) {
|
||||||
|
const cls = 'current';
|
||||||
|
const old = $('.' + cls, elToc);
|
||||||
|
const el = elFirst || elToc.children[first];
|
||||||
|
if (old && old !== el) old.classList.remove(cls);
|
||||||
|
el.classList.add(cls);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user