Skip to content

TextBox

A multi-line text editor component with cursor support and text manipulation features

Extends: VisualElement

Properties

PropertyTypeDefaultDescription
linestable{}Array of text lines
cursorXnumber1Cursor X position
cursorYnumber1Cursor Y position (line number)
scrollXnumber0Horizontal scroll offset
scrollYnumber0Vertical scroll offset
editablebooleantrueWhether text can be edited
syntaxPatternstable{}Syntax highlighting patterns
cursorColornumbernilColor of the cursor

Functions

MethodReturnsDescription
TextBox:addSyntaxPatternTextBoxAdds a new syntax highlighting pattern
TextBox:removeSyntaxPatternTextBoxRemoves a syntax pattern by index (1-based)
TextBox:clearSyntaxPatternsTextBoxClears all syntax highlighting patterns
TextBox:updateViewportTextBoxUpdates the viewport to keep the cursor in view
TextBox:setTextTextBoxSets the text of the TextBox
TextBox:getTextstringGets the text of the TextBox

TextBox:addSyntaxPattern(pattern, color)

Adds a new syntax highlighting pattern

Parameters

  • pattern string The regex pattern to match
  • color number The color to apply

Returns

  • TextBox self The TextBox instance

TextBox:removeSyntaxPattern(index)

Removes a syntax pattern by index (1-based)

Parameters

  • index number The index of the pattern to remove

Returns

  • TextBox self

TextBox:clearSyntaxPatterns()

Clears all syntax highlighting patterns

Returns

  • TextBox self

TextBox:updateViewport()

Updates the viewport to keep the cursor in view

Returns

  • TextBox self The TextBox instance

TextBox:setText(text)

Sets the text of the TextBox

Parameters

  • text string The text to set

Returns

  • TextBox self The TextBox instance

TextBox:getText()

Gets the text of the TextBox

Returns

  • string text The text of the TextBox

Released under the MIT License.