Skip to content

Commit

Permalink
Add ability to ignore ancestor scoping
Browse files Browse the repository at this point in the history
  • Loading branch information
tingerrr committed May 18, 2024
1 parent d6e869f commit 594e348
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/core.typ
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@
/// This function is contextual.
///
/// - ctx (context): The context for which to get the candidates.
/// - scope-prev (bool): Whether the search should be scoped by the first ancestor element in this
/// direction.
/// - scope-next (bool): Whether the search should be scoped by the first ancestor element in this
/// direction.
/// -> candidates
#let get-candidates(ctx) = {
let look-behind = selector(ctx.primary.target).before(ctx.anchor-loc)
let look-ahead = selector(ctx.primary.target).after(ctx.anchor-loc)
#let get-candidates(ctx, scope-prev: true, scope-next: true) = {
let look-prev = selector(ctx.primary.target).before(ctx.anchor-loc)
let look-next = selector(ctx.primary.target).after(ctx.anchor-loc)

let prev-ancestor = none
let next-ancestor = none
Expand All @@ -93,19 +97,19 @@
next = next.filter(x => (ctx.ancestors.filter)(ctx, x))
}

if prev != () {
if scope-prev and prev != () {
prev-ancestor = prev.last()
look-behind = look-behind.after(prev-ancestor.location())
look-prev = look-prev.after(prev-ancestor.location())
}

if next != () {
if scope-next and next != () {
next-ancestor = next.first()
look-ahead = look-ahead.before(next-ancestor.location())
look-next = look-next.before(next-ancestor.location())
}
}

let prev = query(look-behind)
let next = query(look-ahead)
let prev = query(look-prev)
let next = query(look-next)

if ctx.primary.filter != none {
prev = prev.filter(x => (ctx.primary.filter)(ctx, x))
Expand Down

0 comments on commit 594e348

Please sign in to comment.