Skip to content

Commit

Permalink
fixed issue with cell text synching
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Nov 30, 2023
1 parent 8be8645 commit 2d7ff14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/ast/cells.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ method getText*(cell: Cell): string {.base.} = discard
method setText*(cell: Cell, text: string, slice: Slice[int] = 0..0) {.base.} = discard

proc currentText*(cell: Cell): string =
if not cell.displayText.isNone:
return cell.displayText.get
# todo: maybe remove display text?
# if not cell.displayText.isNone:
# return cell.displayText.get
return cell.getText

proc `currentText=`*(cell: Cell, text: string) =
Expand Down Expand Up @@ -206,12 +207,12 @@ method setText*(cell: PropertyCell, text: string, slice: Slice[int] = 0..0) =

case prop.typ
of String:
cell.targetNode.setProperty(cell.property, PropertyValue(kind: PropertyType.String, stringValue: cell.currentText), slice)
cell.targetNode.setProperty(cell.property, PropertyValue(kind: PropertyType.String, stringValue: text), slice)
of Int:
let intValue = cell.currentText.parseInt
let intValue = text.parseInt
cell.targetNode.setProperty(cell.property, PropertyValue(kind: PropertyType.Int, intValue: intValue), slice)
of Bool:
let boolValue = cell.currentText.parseBool
let boolValue = text.parseBool
cell.targetNode.setProperty(cell.property, PropertyValue(kind: PropertyType.Bool, boolValue: boolValue), slice)

except CatchableError:
Expand Down
5 changes: 3 additions & 2 deletions src/platform/widget_builder_model_document.nim
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ proc goForward(self: CellLayoutContext) =
self.currentDirection = Forwards

proc getTextAndColor(app: App, cell: Cell, defaultShadowText: string = ""): (string, Color) =
if cell.currentText.len == 0:
let currentText = cell.currentText
if currentText.len == 0:
let text = if cell.shadowText.len == 0:
defaultShadowText
else:
Expand All @@ -277,7 +278,7 @@ proc getTextAndColor(app: App, cell: Cell, defaultShadowText: string = ""): (str
else:
let defaultColor = if cell.foregroundColor.a != 0: cell.foregroundColor else: color(1, 1, 1)
let textColor = if cell.themeForegroundColors.len == 0: defaultColor else: app.theme.anyColor(cell.themeForegroundColors, defaultColor)
return (cell.currentText, textColor)
return (currentText, textColor)

proc createCompletions(self: ModelDocumentEditor, builder: UINodeBuilder, app: App, cursorBounds: Rect) =
let totalLineHeight = app.platform.totalLineHeight
Expand Down

0 comments on commit 2d7ff14

Please sign in to comment.