diff --git a/src/platform/widget_builder_text_document.nim b/src/platform/widget_builder_text_document.nim index 3d7ab8ef..0e6cd892 100644 --- a/src/platform/widget_builder_text_document.nim +++ b/src/platform/widget_builder_text_document.nim @@ -43,7 +43,7 @@ proc renderLine*( y: float, sizeToContentX: bool, lineNumberTotalWidth: float, lineNumberWidth: float, pivot: Vec2, backgroundColor: Color, textColor: Color, backgroundColors: openArray[tuple[first: RuneIndex, last: RuneIndex, color: Color]], cursors: openArray[int], - wrapLine: bool): seq[CursorLocationInfo] = + wrapLine: bool, wrapLineEndChar: string, wrapLineEndColor: Color): seq[CursorLocationInfo] = var flagsInner = &{FillX, SizeToContentY} if sizeToContentX: @@ -100,6 +100,9 @@ proc renderLine*( break if lastPartXW + wrapWidth + builder.charWidth >= lineWidth: + builder.panel(&{DrawText, FillBackground, SizeToContentX, SizeToContentY}, text = wrapLineEndChar, backgroundColor = backgroundColor, textColor = wrapLineEndColor): + defer: + lastPartXW = currentNode.xw subLineIndex += 1 subLinePartIndex = 0 break @@ -297,7 +300,7 @@ proc createTextLines(self: TextDocumentEditor, builder: UINodeBuilder, app: App, let charWidth = builder.charWidth # ↲ ↩ ⤦ ⤶ ⤸ ⮠ - let wrapLineEndChar = getOption[string](app, "editor.text.wrap-line-end-char", "⤶") + let wrapLineEndChar = getOption[string](app, "editor.text.wrap-line-end-char", "↲") let wrapLines = getOption[bool](app, "editor.text.wrap-lines", true) let showContextLines = getOption[bool](app, "editor.text.context-lines", true) @@ -396,7 +399,7 @@ proc createTextLines(self: TextDocumentEditor, builder: UINodeBuilder, app: App, cursors.add self.renderLine(builder, app.theme, styledLine, self.document.lines[i], self.document.lineIds[i], self.userId, cursorLine, i, lineNumbers, y, sizeToContentX, lineNumberWidth, lineNumberBounds.x, pivot, backgroundColor, textColor, - colors, cursorsPerLine, wrapLine + colors, cursorsPerLine, wrapLine, wrapLineEndChar, wrapLineEndColor, ) builder.createLines(self.previousBaseIndex, self.scrollOffset, self.document.lines.high, sizeToContentX, sizeToContentY, backgroundColor, handleScroll, handleLine) @@ -422,7 +425,7 @@ proc createTextLines(self: TextDocumentEditor, builder: UINodeBuilder, app: App, cursors.add self.renderLine(builder, app.theme, styledLine, self.document.lines[contextLine], self.document.lineIds[contextLine], self.userId, cursorLine, contextLine, lineNumbers, y, sizeToContentX, lineNumberWidth, lineNumberBounds.x, vec2(0, 0), contextBackgroundColor, textColor, - colors, [], false + colors, [], false, wrapLineEndChar, wrapLineEndColor, ) # let fill = self.scrollOffset mod builder.textHeight diff --git a/src/ui/node.nim b/src/ui/node.nim index 6c460718..6257e279 100644 --- a/src/ui/node.nim +++ b/src/ui/node.nim @@ -787,24 +787,25 @@ proc removeFromParent*(node: UINode) = proc getNextOrNewNode(builder: UINodeBuilder, node: UINode, last: UINode, userId: var UIUserId): UINode = let insert = true - let firstOrLast = if last.isNotNil: last else: node.first - - # search ahead to see if we find a matching node - var matchingNode = UINode.none - if userId.kind != None and node.first.isNotNil: - for _, c in firstOrLast.nextSiblings: - if c.userId == userId: - matchingNode = c.some - break - - if matchingNode.isSome: - matchingNode.get.removeFromParent() - node.insert(matchingNode.get, firstOrLast) - - assert firstOrLast.next == matchingNode.get - assert firstOrLast.next.userId == userId - - return firstOrLast.next + # # search ahead to see if we find a matching node + # let firstOrLast = if last.isNotNil: last else: node.first + # var matchingNode = UINode.none + # if userId.kind != None and firstOrLast.isNotNil: + # for _, c in firstOrLast.nextSiblings: + # if c.userId == userId: + # matchingNode = c.some + # break + + # if matchingNode.isSome: + # if builder.useInvalidation: + # node.clearedChildrenBounds = node.clearedChildrenBounds or matchingNode.get.boundsActual.some + # matchingNode.get.removeFromParent() + # node.insert(matchingNode.get, firstOrLast) + + # assert firstOrLast.next == matchingNode.get + # assert firstOrLast.next.userId == userId + + # return firstOrLast.next if last.isNil: # Creating/Updating first child if node.first.isNotNil: # First child already exists @@ -829,6 +830,30 @@ proc getNextOrNewNode(builder: UINodeBuilder, node: UINode, last: UINode, userId if last.next.userId == userId: return last.next elif userId.kind != None: # Has user id, doesn't match + + # search ahead to see if we find a matching node + var matchingNode = UINode.none + for _, c in last.nextSiblings: + if c.userId == userId: + matchingNode = c.some + break + + if matchingNode.isSome: + # echo "found matching node later, delete inbetween" + # remove all nodes in between + for _, c in last.nextSiblings: + if c == matchingNode.get: + break + # echo "delete old node ", c.dump(), ", ", node.clearRect + if builder.useInvalidation: + node.clearedChildrenBounds = node.clearedChildrenBounds or c.boundsActual.some + c.removeFromParent() + builder.returnNode(c) + assert last.next == matchingNode.get + assert last.next.userId == userId + + return last.next + let newNode = builder.unpoolNode(userId) if newNode.parent.isNotNil: