From a4133432e47d9e45159f0ed1d4e7f6a2c02dc5b6 Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 12 Nov 2024 18:52:26 +0100 Subject: buffer: fix broken gotoAnchor behavior 23beebe6 introduced a regression that broke gotoAnchor. This fixes that, plus a couple other long-standing gotoAnchor bugs: * If no anchor is found, do not dupe the buffer. Desktop browsers still add a history entry, while w3m prints an error. I've copied the latter because it makes more sense as a user, but this will have to be refined for the navigation API at some point. * If the anchor *is* found, then always jump to it, even if it's not visible. This was a limitation of relying on the line array, so now we rely on the box tree instead. (Sooner or later, the former must go anyway.) Also, fix `U' reload not restoring the position (hopefully this time for good). --- src/css/box.nim | 5 +++++ src/css/render.nim | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/css') diff --git a/src/css/box.nim b/src/css/box.nim index a40cd4af..3d35b2ab 100644 --- a/src/css/box.nim +++ b/src/css/box.nim @@ -58,6 +58,7 @@ type InlineFragment* = ref object state*: InlineFragmentState + render*: BoxRenderState computed*: CSSComputedValues node*: StyledNode splitType*: set[SplitType] @@ -79,8 +80,12 @@ type RelativeRect* = array[DimensionType, Span] + BoxRenderState* = object + offset*: Offset + BlockBox* = ref object state*: BoxLayoutState + render*: BoxRenderState computed*: CSSComputedValues node*: StyledNode inline*: InlineFragment diff --git a/src/css/render.nim b/src/css/render.nim index 6db0a9de..9688ff30 100644 --- a/src/css/render.nim +++ b/src/css/render.nim @@ -2,7 +2,6 @@ import std/algorithm import css/box import css/cssvalues -import css/layout import css/lunit import css/stylednode import types/bitmap @@ -345,8 +344,10 @@ proc renderInlineFragment(grid: var FlexibleGrid; state: var RenderState; if bgcolor0.a > 0: grid.paintInlineFragment(state, fragment, offset, bgcolor0.rgb.cellColor()) + let startOffset = offset + fragment.state.startOffset + fragment.render.offset = startOffset if position notin PositionStaticLike and stSplitStart in fragment.splitType: - state.absolutePos.add(offset + fragment.state.startOffset) + state.absolutePos.add(startOffset) if fragment.t == iftParent: for child in fragment.children: grid.renderInlineFragment(state, child, offset, bgcolor0) @@ -396,6 +397,7 @@ proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState; if not box.computed{"top"}.auto or not box.computed{"bottom"}.auto: offset.y = state.absolutePos[^1].y offset += box.state.offset + box.render.offset = offset if position notin PositionStaticLike: state.absolutePos.add(offset) if box.computed{"visibility"} == VisibilityVisible: @@ -438,13 +440,12 @@ proc renderBlockBox(grid: var FlexibleGrid; state: var RenderState; discard state.absolutePos.pop() proc renderDocument*(grid: var FlexibleGrid; bgcolor: var CellColor; - styledRoot: StyledNode; attrsp: ptr WindowAttributes; + rootBox: BlockBox; attrsp: ptr WindowAttributes; images: var seq[PosBitmap]) = grid.setLen(0) - if styledRoot == nil: + if rootBox == nil: # no HTML element when we run cascade; just clear all lines. return - let rootBox = styledRoot.layout(attrsp) var state = RenderState( absolutePos: @[offset(0, 0)], attrsp: attrsp, -- cgit