aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/css/box.nim16
-rw-r--r--src/server/buffer.nim20
2 files changed, 20 insertions, 16 deletions
diff --git a/src/css/box.nim b/src/css/box.nim
index 7bcf0f3b..dca3ade2 100644
--- a/src/css/box.nim
+++ b/src/css/box.nim
@@ -108,6 +108,22 @@ type
of ibtBox:
box*: BlockBox
+iterator children*(box: CSSBox): lent CSSBox {.inline.} =
+ if box of BlockBox:
+ let box = BlockBox(box)
+ for child in box.children:
+ yield child
+ else:
+ let ibox = InlineBox(box)
+ case ibox.t
+ of ibtParent:
+ for child in ibox.children:
+ yield child
+ of ibtBox:
+ yield CSSBox(ibox.box)
+ else:
+ discard
+
# We store runs in state as a private field, so that we can both check
# if the box type is correct and reset them on relayout by zeroing out
# state.
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index e34d88f6..dca85806 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -666,22 +666,10 @@ type GotoAnchorResult* = object
focus*: ReadLineResult
proc findAnchor(box: CSSBox; anchor: Element): Offset =
- if box of InlineBox:
- let ibox = InlineBox(box)
- if ibox.t == ibtBox:
- let off = ibox.box.findAnchor(anchor)
- if off.y >= 0:
- return off
- elif ibox.t == ibtParent:
- for child in ibox.children:
- let off = child.findAnchor(anchor)
- if off.y >= 0:
- return off
- else:
- for child in BlockBox(box).children:
- let off = child.findAnchor(anchor)
- if off.y >= 0:
- return off
+ for child in box.children:
+ let off = child.findAnchor(anchor)
+ if off.y >= 0:
+ return off
if box.element == anchor:
return box.render.offset
return offset(-1, -1)