Skip to content

Commit

Permalink
fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Sep 26, 2023
1 parent 182d8ef commit 3eadd5d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/platform/widget_builder_text_document.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import std/[strformat, tables, sugar, sequtils, strutils]
import util, app, document_editor, text/text_editor, custom_logger, widgets, platform, theme, custom_unicode, config_provider
import scripting_api except DocumentEditor, TextDocumentEditor, AstDocumentEditor
import vmath, bumpy, chroma
import custom_logger

import ui/node

# Mark this entire file as used, otherwise we get warnings when importing it but only calling a method
{.used.}

logCategory "widget_builder_text"

type CursorLocationInfo = tuple[node: UINode, text: string, bounds: Rect]

when defined(js):
Expand Down Expand Up @@ -62,18 +65,21 @@ proc renderLine*(

if lineNumberText.len > 0:
builder.panel(&{UINodeFlag.FillBackground, SizeToContentY}, w = lineNumberTotalWidth, backgroundColor = backgroundColor):
builder.panel(&{DrawText, SizeToContentX, SizeToContentY}, text = lineNumberText, x = lineNumberX, textColor = textColor):
lastPartXW = currentNode.bounds.xw
builder.panel(&{DrawText, SizeToContentX, SizeToContentY}, text = lineNumberText, x = lineNumberX, textColor = textColor)
lastPartXW = lineNumberTotalWidth

for part in line.parts:
defer:
start += part.text.len
startRune += part.text.runeLen

var partNode: UINode
builder.panel(&{DrawText, FillBackground, SizeToContentX, SizeToContentY}, text = part.text):
currentNode.backgroundColor = backgroundColor
currentNode.textColor = if part.scope.len == 0: textColor else: app.theme.tokenColor(part, textColor)

partNode = currentNode

onClick Left:
echo "clicked "

Expand All @@ -85,7 +91,7 @@ proc renderLine*(
let cursorX = builder.textWidth(int(selectionLastRune - startRune)).round
result = some (currentNode, $part.text[selectionLastRune - startRune], rect(cursorX, 0, builder.charWidth, builder.textHeight))

lastPartXW = currentNode.bounds.xw
lastPartXW = partNode.bounds.xw

# cursor after latest char
if curs.getSome(curs) and curs == lineOriginal.len:
Expand Down
4 changes: 4 additions & 0 deletions src/ui/node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ proc returnNode*(builder: UINodeBuilder, node: UINode) =
node.lastRenderTime = 0

node.mText = ""
node.mTextRuneLen = 0

node.pivot.x = 0
node.pivot.y = 0

node.boundsOld.x = 0
node.boundsOld.y = 0
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/input/tinput.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ discard """
action: "run"
cmd: "nim $target --nimblePath:./nimbleDir/simplePkgs $options $file"
timeout: 60
targets: "c js vcc"
targets: "c js"
matrix: ""
"""

Expand Down

0 comments on commit 3eadd5d

Please sign in to comment.