diff options
author | bptato <nincsnevem662@gmail.com> | 2023-09-20 02:27:16 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-09-20 02:27:16 +0200 |
commit | 3194b602d8b2f53d2db3a594300e104bcac67c10 (patch) | |
tree | b5bcac185e13fb7ce7a2a6462aa476e09a02f074 | |
parent | 24162bb4dc813f36f411cb262e51169d7d31bc43 (diff) | |
download | chawan-3194b602d8b2f53d2db3a594300e104bcac67c10.tar.gz |
buffer: support <a name=... for anchor navigation
-rw-r--r-- | src/html/dom.nim | 9 | ||||
-rw-r--r-- | src/server/buffer.nim | 6 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 4fcc6c51..67f0c666 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -1840,6 +1840,15 @@ func formmethod*(element: Element): FormMethod = return FORM_METHOD_GET +func findAnchor*(document: Document, id: string): Element = + if id.len == 0: + return nil + for child in document.elements: + if child.id == id: + return child + if child.tagType == TAG_A and child.attr("name") == id: + return child + # Forward declaration hack isDefaultPassive = func (eventTarget: EventTarget): bool = if eventTarget of Window: diff --git a/src/server/buffer.nim b/src/server/buffer.nim index 349a5d8d..49cd9140 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -510,8 +510,8 @@ proc findNextMatch*(buffer: Buffer, regex: Regex, cursorx, cursory: int, wrap: b proc gotoAnchor*(buffer: Buffer): tuple[x, y: int] {.proxy.} = if buffer.document == nil: return (-1, -1) - let anchor = buffer.document.getElementById(buffer.url.anchor) - if anchor == nil: return + let anchor = buffer.document.findAnchor(buffer.url.anchor) + if anchor == nil: return (-1, -1) for y in 0 ..< buffer.lines.len: let line = buffer.lines[y] for i in 0 ..< line.formats.len: @@ -1297,7 +1297,7 @@ proc readCanceled*(buffer: Buffer): bool {.proxy.} = return buffer.restoreFocus() proc findAnchor*(buffer: Buffer, anchor: string): bool {.proxy.} = - return buffer.document != nil and buffer.document.getElementById(anchor) != nil + return buffer.document != nil and buffer.document.findAnchor(anchor) != nil type GetLinesResult* = tuple[ numLines: int, |