diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/html/dom.nim | 5 | ||||
-rw-r--r-- | src/io/buffer.nim | 24 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 85a48174..faa3c846 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -306,3 +306,8 @@ func newAttr*(parent: Element, key, value: string): Attr = result.ownerElement = parent result.name = key result.value = value + +func getElementById*(document: Document, id: string): Element = + if id.len == 0 or id notin document.id_elements: + return nil + return document.id_elements[id][0] diff --git a/src/io/buffer.nim b/src/io/buffer.nim index b4d19e36..922d45ac 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -677,13 +677,20 @@ proc scrollLeft*(buffer: Buffer) = buffer.cursorLeft() buffer.redraw = true -proc gotoAnchor*(buffer: Buffer): bool = - discard - #TODO - #if buffer.location.anchor != "": - # let node = buffer.getElementById(buffer.location.anchor) - # if node != nil: - # buffer.scrollTo(max(node.y - buffer.height div 2, 0)) +proc gotoAnchor*(buffer: Buffer, id: string) = + let anchor = buffer.document.getElementById(id) + if anchor == nil: return + for y in 0..(buffer.numLines - 1): + let line = buffer.lines[y] + var i = 0 + while i < line.formats.len: + let format = line.formats[i] + if anchor in format.nodes: + buffer.setCursorY(y) + buffer.centerLine() + buffer.setCursorXB(format.pos) + return + inc i proc setLocation*(buffer: Buffer, uri: Uri) = buffer.location = uri @@ -1018,7 +1025,8 @@ proc inputLoop(attrs: TermAttributes, buffer: Buffer): bool = nostatus = false proc displayPage*(attrs: TermAttributes, buffer: Buffer): bool = - discard buffer.gotoAnchor() + eprint buffer.location.anchor + buffer.gotoAnchor(buffer.location.anchor) buffer.refreshDisplay() buffer.displayBuffer() buffer.updateHover() |