diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-05 12:13:49 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-05 12:13:49 +0100 |
commit | b31c6a2072b6897ae1ef355013fcd199496aee82 (patch) | |
tree | 71d8151423dd488518108137cff826ca9327a785 /src/buffer | |
parent | 302e6cd0bd687709b33e0885302c76182bc74918 (diff) | |
download | chawan-b31c6a2072b6897ae1ef355013fcd199496aee82.tar.gz |
Add title tag support, peek, peekCursor
Diffstat (limited to 'src/buffer')
-rw-r--r-- | src/buffer/buffer.nim | 23 | ||||
-rw-r--r-- | src/buffer/container.nim | 10 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim index ef2ce5fd..ae91be54 100644 --- a/src/buffer/buffer.nim +++ b/src/buffer/buffer.nim @@ -81,6 +81,7 @@ type config: BufferConfig userstyle: CSSStylesheet timeouts: Table[int, (proc())] + hovertext: string # async, but worse EmptyPromise = ref object of RootObj @@ -228,6 +229,20 @@ macro proxy(fun: typed) = proxy0(`fun`) proxy1(`fun`) +func getTitle(node: StyledNode): string = + if node == nil: + return "" + if node.t == STYLED_ELEMENT and node.node != nil: + let element = Element(node.node) + if element.attrb("title"): + return element.attr("title") + if node.node != nil: + var node = node.node + for element in node.ancestors: + if element.attrb("title"): + return element.attr("title") + #TODO pseudo-elements + func getLink(node: StyledNode): HTMLAnchorElement = if node == nil: return nil @@ -447,6 +462,11 @@ proc updateHover*(buffer: Buffer, cursorx, cursory: int): UpdateHoverResult {.pr if i >= 0: thisnode = buffer.lines[cursory].formats[i].node let prevnode = buffer.prevnode + let title = thisnode.getTitle() + if title != "": + result.hover = some(title) + elif buffer.hovertext != "": + result.hover = some(buffer.hovertext) if thisnode != prevnode and (thisnode == nil or prevnode == nil or thisnode.node != prevnode.node): for styledNode in thisnode.branch: @@ -458,9 +478,10 @@ proc updateHover*(buffer: Buffer, cursorx, cursory: int): UpdateHoverResult {.pr let link = thisnode.getLink() if link != nil: + buffer.hovertext = link.href result.hover = some(link.href) else: - result.hover = some("") + buffer.hovertext = "" for styledNode in prevnode.branch: if styledNode.t == STYLED_ELEMENT and styledNode.node != nil: diff --git a/src/buffer/container.nim b/src/buffer/container.nim index 6960f260..e24b0342 100644 --- a/src/buffer/container.nim +++ b/src/buffer/container.nim @@ -284,6 +284,9 @@ proc sendCursorPosition*(container: Container) = if res.hover.isSome: container.hovertext = res.hover.get container.triggerEvent(STATUS) + elif container.hovertext != "": + container.hovertext = "" + container.triggerEvent(STATUS) if res.repaint: container.needslines = true) @@ -722,6 +725,13 @@ proc windowChange*(container: Container, attrs: WindowAttributes) = container.iface.windowChange(attrs).then(proc() = container.needslines = true) +proc peek*(container: Container) {.jsfunc.} = + container.alert($container.source.location) + +proc peekCursor*(container: Container) {.jsfunc.} = + if container.hovertext != "": + container.alert(container.hovertext) + proc handleCommand(container: Container) = var packetid, len: int container.iface.stream.sread(len) |