Skip to content

Commit

Permalink
fix: fix #4 by update method
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangeX4 committed Feb 4, 2024
1 parent 1cf0511 commit a6791b8
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions utils/states.typ
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
#let sections-state = state("touying-sections-state", ((kind: "section", title: none, short-title: none, loc: none, count: 0, children: ()),))

#let _new-section(short-title: auto, id: auto, title) = locate(loc => {
// to avoid multiple sections with the same title
let sections = sections-state.at(loc)
sections.push((kind: "section", title: title, short-title: short-title, loc: loc, count: 0, children: ()))
sections-state.update(sections)
sections-state.update(sections => {
sections.push((kind: "section", title: title, short-title: short-title, loc: loc, count: 0, children: ()))
sections
})
})

#let _new-subsection(short-title: auto, id: auto, title) = locate(loc => {
// to update subsections after the sections are updated,
// so we need sections-state.update instead of sections-state.at(loc)
sections-state.update(sections => {
let last-section = sections.pop()
last-section.children.push((kind: "subsection", title: title, short-title: short-title, loc: loc, count: 0, children: ()))
Expand Down

0 comments on commit a6791b8

Please sign in to comment.