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
autoPairEnabledbooleantrueWhether automatic bracket/quote pairing is enabled
autoPairCharacterstable{["("]=")", ["["]="]", ["{"]="}", ['"']='"', [''']=''', ['']=''} Mapping of opening to closing characters for auto pairing
autoPairSkipClosingbooleantrueSkip inserting a closing char if the same one is already at cursor
autoPairOverTypebooleantrueWhen pressing a closing char that matches the next char, move over it instead of inserting
autoPairNewlineIndentbooleantrueOn Enter between matching braces, create blank line and keep closing aligned
autoCompleteEnabledbooleanfalseWhether autocomplete suggestions are enabled
autoCompleteItemstable{}List of suggestions used when no provider is supplied
autoCompleteProviderfunctionnilOptional suggestion provider returning a list for the current prefix
autoCompleteMinCharsnumber1Minimum characters required before showing suggestions
autoCompleteMaxItemsnumber6Maximum number of visible suggestions
autoCompleteCaseInsensitivebooleantrueWhether suggestions should match case-insensitively
autoCompleteTokenPatternstring"[%w_]+"Pattern used to extract the current token for suggestions
autoCompleteOffsetXnumber0Horizontal offset applied to the popup frame relative to the TextBox
autoCompleteOffsetYnumber1Vertical offset applied to the popup frame relative to the TextBox bottom edge
autoCompleteZOffsetnumber1Z-index offset applied to the popup frame
autoCompleteMaxWidthnumber0Maximum width of the autocomplete popup (0 uses the textbox width)
autoCompleteShowBorderbooleantrueWhether to render a character border around the popup
autoCompleteBorderColorcolorblackColor of the popup border when enabled
autoCompleteBackgroundcolorlightGrayBackground color of the suggestion popup
autoCompleteForegroundcolorblackForeground color of the suggestion popup
autoCompleteSelectedBackgroundcolorgrayBackground color for the selected suggestion
autoCompleteSelectedForegroundcolorwhiteForeground color for the selected suggestion
autoCompleteAcceptOnEnterbooleantrueWhether pressing Enter accepts the current suggestion
autoCompleteAcceptOnClickbooleantrueWhether clicking a suggestion accepts it immediately
autoCompleteCloseOnEscapebooleantrueWhether pressing Escape closes the popup

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.