From ad66c25c72ce2b2ae43e3d7a848836fdea4ee572 Mon Sep 17 00:00:00 2001 From: bptato Date: Thu, 15 Aug 2024 21:54:08 +0200 Subject: buffer: fix some hover weirdness Setting the new hover value before unsetting the previous one would unset the new hover value for nodes in the same branch. In particular, this broke hover when moving the cursor from a pseudo element (e.g. ::before) to its parent. --- src/server/buffer.nim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/server/buffer.nim') diff --git a/src/server/buffer.nim b/src/server/buffer.nim index f92d8174..9370f90b 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -855,7 +855,7 @@ proc updateHover*(buffer: Buffer; cursorx, cursory: int): UpdateHoverResult {.proxy.} = if cursory >= buffer.lines.len: return UpdateHoverResult() - var thisnode: StyledNode + var thisnode: StyledNode = nil let i = buffer.lines[cursory].findFormatN(cursorx) - 1 if i >= 0: thisnode = buffer.lines[cursory].formats[i].node @@ -864,22 +864,22 @@ proc updateHover*(buffer: Buffer; cursorx, cursory: int): UpdateHoverResult let prevnode = buffer.prevnode if thisnode != prevnode and (thisnode == nil or prevnode == nil or thisnode.node != prevnode.node): - for styledNode in thisnode.branch: + for styledNode in prevnode.branch: if styledNode.t == stElement and styledNode.node != nil: let elem = Element(styledNode.node) - if not elem.hover: - elem.setHover(true) + if elem.hover: + elem.setHover(false) repaint = true for ht in HoverType: let s = HoverFun[ht](buffer, thisnode) if buffer.hoverText[ht] != s: hover.add((ht, s)) buffer.hoverText[ht] = s - for styledNode in prevnode.branch: + for styledNode in thisnode.branch: if styledNode.t == stElement and styledNode.node != nil: let elem = Element(styledNode.node) - if elem.hover: - elem.setHover(false) + if not elem.hover: + elem.setHover(true) repaint = true if repaint: buffer.reshape() -- cgit 1.4.1-2-gfad0