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) {
|
||||
const {sections} = editor;
|
||||
const first = sections.indexOf(added[0]);
|
||||
let el = elToc.children[first];
|
||||
if (added.focus) {
|
||||
const cls = 'current';
|
||||
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 elFirst = elToc.children[first];
|
||||
if (first >= 0 && (!added.focus || !elFirst)) {
|
||||
for (let el = elFirst, i = first; i < sections.length; i++) {
|
||||
const entry = sections[i].tocEntry;
|
||||
if (!deepEqual(entry, toc[i])) {
|
||||
if (!el) el = elToc.appendChild($create('li', {tabIndex: 0}));
|
||||
|
@ -328,6 +321,13 @@ lazyInit();
|
|||
elToc.lastElementChild.remove();
|
||||
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