From a316ae2406bd4d0f1006cdcb572a06b772b10237 Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 16 Dec 2022 20:58:48 +0100 Subject: Allow cycling through hover-texts with u --- src/buffer/buffer.nim | 53 +++++++++++++++++++++++++++--------------------- src/buffer/container.nim | 34 ++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 28 deletions(-) (limited to 'src/buffer') diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim index 8bfd3f6e..f20804c7 100644 --- a/src/buffer/buffer.nim +++ b/src/buffer/buffer.nim @@ -51,6 +51,10 @@ type GET_SOURCE, GET_LINES, UPDATE_HOVER, PASS_FD, CONNECT, GOTO_ANCHOR, CANCEL, GET_TITLE + HoverType* = enum + HOVER_TITLE = "TITLE" + HOVER_LINK = "URL" + BufferMatch* = object success*: bool x*: int @@ -88,7 +92,7 @@ type timeouts: Table[int, (proc())] tasks: array[BufferCommand, int] #TODO this should have arguments savetask: bool - hovertext: string + hovertext: array[HoverType, string] # async, but worse EmptyPromise = ref object of RootObj @@ -280,15 +284,6 @@ func getTitleAttr(node: StyledNode): string = return element.attr("title") #TODO pseudo-elements -func getLink(node: StyledNode): HTMLAnchorElement = - if node == nil: - return nil - if node.t == STYLED_ELEMENT and node.node != nil and Element(node.node).tagType == TAG_A: - return HTMLAnchorElement(node.node) - if node.node != nil: - return HTMLAnchorElement(node.node.findAncestor({TAG_A})) - #TODO ::before links? - const ClickableElements = { TAG_A, TAG_INPUT, TAG_OPTION, TAG_BUTTON, TAG_TEXTAREA } @@ -302,6 +297,22 @@ func getClickable(styledNode: StyledNode): Element = return element styledNode.node.findAncestor(ClickableElements) +func getClickHover(styledNode: StyledNode): string = + let clickable = styledNode.getClickable() + if clickable != nil: + case clickable.tagType + of TAG_A: + return HTMLAnchorElement(clickable).href + of TAG_INPUT: + return "" + of TAG_OPTION: + return "