Table of Contents

Class TextEdit

Namespace
Godot
Assembly
GodotSharp.dll

A multiline text editor. It also has limited facilities for editing code, such as syntax highlighting support. For more advanced facilities for editing code, see CodeEdit.

Note: Most viewport, caret, and edit methods contain a caret_index argument for CaretMultiple support. The argument should be one of the following: -1 for all carets, 0 for the main caret, or greater than 0 for secondary carets in the order they were created.

Note: When holding down Alt, the vertical scroll wheel will scroll 5 times as fast as it would normally do. This also works in the Godot script editor.

public class TextEdit : Control, IDisposable
Inheritance
TextEdit
Implements
Derived
Inherited Members

Constructors

TextEdit()

public TextEdit()

Properties

AutowrapMode

If WrapMode is set to Boundary, sets text wrapping mode. To see how each mode behaves, see TextServer.AutowrapMode.

public TextServer.AutowrapMode AutowrapMode { get; set; }

Property Value

TextServer.AutowrapMode

If true, makes the caret blink.

public bool CaretBlink { get; set; }

Property Value

bool

CaretBlinkInterval

The interval at which the caret blinks (in seconds).

public float CaretBlinkInterval { get; set; }

Property Value

float

CaretDrawWhenEditableDisabled

If true, caret will be visible when Editable is disabled.

public bool CaretDrawWhenEditableDisabled { get; set; }

Property Value

bool

CaretMidGrapheme

Allow moving caret, selecting and removing the individual composite character components.

Note: Backspace is always removing individual composite character components.

public bool CaretMidGrapheme { get; set; }

Property Value

bool

CaretMoveOnRightClick

If true, a right-click moves the caret at the mouse position before displaying the context menu.

If false, the context menu ignores mouse location.

public bool CaretMoveOnRightClick { get; set; }

Property Value

bool

CaretMultiple

Sets if multiple carets are allowed.

public bool CaretMultiple { get; set; }

Property Value

bool

CaretType

Set the type of caret to draw.

public TextEdit.CaretTypeEnum CaretType { get; set; }

Property Value

TextEdit.CaretTypeEnum

ContextMenuEnabled

If true, a right-click displays the context menu.

public bool ContextMenuEnabled { get; set; }

Property Value

bool

CustomWordSeparators

The characters to consider as word delimiters if UseCustomWordSeparators is true. The characters should be defined without separation, for example #_!.

public string CustomWordSeparators { get; set; }

Property Value

string

DeselectOnFocusLossEnabled

If true, the selected text will be deselected when focus is lost.

public bool DeselectOnFocusLossEnabled { get; set; }

Property Value

bool

DragAndDropSelectionEnabled

If true, allow drag and drop of selected text. Text can still be dropped from other sources.

public bool DragAndDropSelectionEnabled { get; set; }

Property Value

bool

DrawControlChars

If true, control characters are displayed.

public bool DrawControlChars { get; set; }

Property Value

bool

DrawSpaces

If true, the "space" character will have a visible representation.

public bool DrawSpaces { get; set; }

Property Value

bool

DrawTabs

If true, the "tab" character will have a visible representation.

public bool DrawTabs { get; set; }

Property Value

bool

Editable

If false, existing text cannot be modified and new text cannot be added.

public bool Editable { get; set; }

Property Value

bool

HighlightAllOccurrences

If true, all occurrences of the selected text will be highlighted.

public bool HighlightAllOccurrences { get; set; }

Property Value

bool

HighlightCurrentLine

If true, the line containing the cursor is highlighted.

public bool HighlightCurrentLine { get; set; }

Property Value

bool

IndentWrappedLines

If true, all wrapped lines are indented to the same amount as the unwrapped line.

public bool IndentWrappedLines { get; set; }

Property Value

bool

Language

Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.

public string Language { get; set; }

Property Value

string

MiddleMousePasteEnabled

If false, using middle mouse button to paste clipboard will be disabled.

Note: This method is only implemented on Linux.

public bool MiddleMousePasteEnabled { get; set; }

Property Value

bool

MinimapDraw

If true, a minimap is shown, providing an outline of your source code. The minimap uses a fixed-width text size.

public bool MinimapDraw { get; set; }

Property Value

bool

MinimapWidth

The width, in pixels, of the minimap.

public int MinimapWidth { get; set; }

Property Value

int

PlaceholderText

Text shown when the TextEdit is empty. It is not the TextEdit's default value (see Text).

public string PlaceholderText { get; set; }

Property Value

string

ScrollFitContentHeight

If true, TextEdit will disable vertical scroll and fit minimum height to the number of visible lines.

public bool ScrollFitContentHeight { get; set; }

Property Value

bool

ScrollHorizontal

If there is a horizontal scrollbar, this determines the current horizontal scroll value in pixels.

public int ScrollHorizontal { get; set; }

Property Value

int

ScrollPastEndOfFile

Allow scrolling past the last line into "virtual" space.

public bool ScrollPastEndOfFile { get; set; }

Property Value

bool

ScrollSmooth

Scroll smoothly over the text rather than jumping to the next location.

public bool ScrollSmooth { get; set; }

Property Value

bool

ScrollVScrollSpeed

Sets the scroll speed with the minimap or when ScrollSmooth is enabled.

public float ScrollVScrollSpeed { get; set; }

Property Value

float

ScrollVertical

If there is a vertical scrollbar, this determines the current vertical scroll value in line numbers, starting at 0 for the top line.

public double ScrollVertical { get; set; }

Property Value

double

SelectingEnabled

If true, text can be selected.

If false, text can not be selected by the user or by the Select(int, int, int, int, int) or SelectAll() methods.

public bool SelectingEnabled { get; set; }

Property Value

bool

ShortcutKeysEnabled

If true, shortcut keys for context menu items are enabled, even if the context menu is disabled.

public bool ShortcutKeysEnabled { get; set; }

Property Value

bool

StructuredTextBidiOverride

Set BiDi algorithm override for the structured text.

public TextServer.StructuredTextParser StructuredTextBidiOverride { get; set; }

Property Value

TextServer.StructuredTextParser

StructuredTextBidiOverrideOptions

Set additional options for BiDi override.

public Array StructuredTextBidiOverrideOptions { get; set; }

Property Value

Array

SyntaxHighlighter

Sets the SyntaxHighlighter to use.

public SyntaxHighlighter SyntaxHighlighter { get; set; }

Property Value

SyntaxHighlighter

Text

String value of the TextEdit.

public string Text { get; set; }

Property Value

string

TextDirection

Base text writing direction.

public Control.TextDirection TextDirection { get; set; }

Property Value

Control.TextDirection

UseCustomWordSeparators

If false, using Ctrl + Left or Ctrl + Right (Cmd + Left or Cmd + Right on macOS) bindings will use the behavior of UseDefaultWordSeparators. If true, it will also stop the caret if a character within CustomWordSeparators is detected. Useful for subword moving. This behavior also will be applied to the behavior of text selection.

public bool UseCustomWordSeparators { get; set; }

Property Value

bool

UseDefaultWordSeparators

If false, using Ctrl + Left or Ctrl + Right (Cmd + Left or Cmd + Right on macOS) bindings will stop moving caret only if a space or punctuation is detected. If true, it will also stop the caret if a character is part of !"#$%&'()*+,-./:;<=>?@[\]^`{|}~, the Unicode General Punctuation table, or the Unicode CJK Punctuation table. Useful for subword moving. This behavior also will be applied to the behavior of text selection.

public bool UseDefaultWordSeparators { get; set; }

Property Value

bool

VirtualKeyboardEnabled

If true, the native virtual keyboard is shown when focused on platforms that support it.

public bool VirtualKeyboardEnabled { get; set; }

Property Value

bool

WrapMode

Sets the line wrapping mode to use.

public TextEdit.LineWrappingMode WrapMode { get; set; }

Property Value

TextEdit.LineWrappingMode

Methods

AddCaret(int, int)

Adds a new caret at the given location. Returns the index of the new caret, or -1 if the location is invalid.

public int AddCaret(int line, int column)

Parameters

line int
column int

Returns

int

AddCaretAtCarets(bool)

Adds an additional caret above or below every caret. If below is true the new caret will be added below and above otherwise.

public void AddCaretAtCarets(bool below)

Parameters

below bool

AddGutter(int)

Register a new gutter to this TextEdit. Use at to have a specific gutter order. A value of -1 appends the gutter to the right.

public void AddGutter(int at = -1)

Parameters

at int

AddSelectionForNextOccurrence()

Adds a selection and a caret for the next occurrence of the current selection. If there is no active selection, selects word under caret.

public void AddSelectionForNextOccurrence()

AdjustCaretsAfterEdit(int, int, int, int, int)

This method does nothing.

[Obsolete("No longer necessary since methods now adjust carets themselves.")]
public void AdjustCaretsAfterEdit(int caret, int fromLine, int fromCol, int toLine, int toCol)

Parameters

caret int
fromLine int
fromCol int
toLine int
toCol int

AdjustViewportToCaret(int)

Adjust the viewport so the caret is visible.

public void AdjustViewportToCaret(int caretIndex = 0)

Parameters

caretIndex int

ApplyIme()

Applies text from the Input Method Editor (IME) to each caret and closes the IME if it is open.

public void ApplyIme()

Backspace(int)

Called when the user presses the backspace key. Can be overridden with _Backspace(int).

public void Backspace(int caretIndex = -1)

Parameters

caretIndex int

BeginComplexOperation()

Starts a multipart edit. All edits will be treated as one action until EndComplexOperation() is called.

public void BeginComplexOperation()

BeginMulticaretEdit()

Starts an edit for multiple carets. The edit must be ended with EndMulticaretEdit(). Multicaret edits can be used to edit text at multiple carets and delay merging the carets until the end, so the caret indexes aren't affected immediately. BeginMulticaretEdit() and EndMulticaretEdit() can be nested, and the merge will happen at the last EndMulticaretEdit().

Example usage:

begin_complex_operation()
  begin_multicaret_edit()
  for i in range(get_caret_count()):
      if multicaret_edit_ignore_caret(i):
          continue
      # Logic here.
  end_multicaret_edit()
  end_complex_operation()
public void BeginMulticaretEdit()

CancelIme()

Closes the Input Method Editor (IME) if it is open. Any text in the IME will be lost.

public void CancelIme()

CenterViewportToCaret(int)

Centers the viewport on the line the editing caret is at. This also resets the ScrollHorizontal value to 0.

public void CenterViewportToCaret(int caretIndex = 0)

Parameters

caretIndex int

Clear()

Performs a full reset of TextEdit, including undo history.

public void Clear()

ClearUndoHistory()

Clears the undo history.

public void ClearUndoHistory()

CollapseCarets(int, int, int, int, bool)

Collapse all carets in the given range to the fromLine and fromColumn position.

inclusive applies to both ends.

If IsInMulitcaretEdit() is true, carets that are collapsed will be true for MulticaretEditIgnoreCaret(int).

MergeOverlappingCarets() will be called if any carets were collapsed.

public void CollapseCarets(int fromLine, int fromColumn, int toLine, int toColumn, bool inclusive = false)

Parameters

fromLine int
fromColumn int
toLine int
toColumn int
inclusive bool

Copy(int)

Copies the current text selection. Can be overridden with _Copy(int).

public void Copy(int caretIndex = -1)

Parameters

caretIndex int

Cut(int)

Cut's the current selection. Can be overridden with _Cut(int).

public void Cut(int caretIndex = -1)

Parameters

caretIndex int

DeleteSelection(int)

Deletes the selected text.

public void DeleteSelection(int caretIndex = -1)

Parameters

caretIndex int

Deselect(int)

Deselects the current selection.

public void Deselect(int caretIndex = -1)

Parameters

caretIndex int

EndAction()

Marks the end of steps in the current action started with StartAction(EditAction).

public void EndAction()

EndComplexOperation()

Ends a multipart edit, started with BeginComplexOperation(). If called outside a complex operation, the current operation is pushed onto the undo/redo stack.

public void EndComplexOperation()

EndMulticaretEdit()

Ends an edit for multiple carets, that was started with BeginMulticaretEdit(). If this was the last EndMulticaretEdit() and MergeOverlappingCarets() was called, carets will be merged.

public void EndMulticaretEdit()

GetCaretColumn(int)

Returns the column the editing caret is at.

public int GetCaretColumn(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetCaretCount()

Returns the number of carets in this TextEdit.

public int GetCaretCount()

Returns

int

GetCaretDrawPos(int)

Returns the caret pixel draw position.

public Vector2 GetCaretDrawPos(int caretIndex = 0)

Parameters

caretIndex int

Returns

Vector2

GetCaretIndexEditOrder()

Returns a list of caret indexes in their edit order, this done from bottom to top. Edit order refers to the way actions such as InsertTextAtCaret(string, int) are applied.

[Obsolete("Carets no longer need to be edited in any specific order. If the carets need to be sorted, use 'Godot.TextEdit.GetSortedCarets(bool)' instead.")]
public int[] GetCaretIndexEditOrder()

Returns

int[]

GetCaretLine(int)

Returns the line the editing caret is on.

public int GetCaretLine(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetCaretWrapIndex(int)

Returns the wrap index the editing caret is on.

public int GetCaretWrapIndex(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetFirstNonWhiteSpaceColumn(int)

Returns the first column containing a non-whitespace character.

public int GetFirstNonWhiteSpaceColumn(int line)

Parameters

line int

Returns

int

GetFirstVisibleLine()

Returns the first visible line.

public int GetFirstVisibleLine()

Returns

int

GetGutterCount()

Returns the number of gutters registered.

public int GetGutterCount()

Returns

int

GetGutterName(int)

Returns the name of the gutter at the given index.

public string GetGutterName(int gutter)

Parameters

gutter int

Returns

string

GetGutterType(int)

Returns the type of the gutter at the given index. Gutters can contain icons, text, or custom visuals. See TextEdit.GutterType for options.

public TextEdit.GutterType GetGutterType(int gutter)

Parameters

gutter int

Returns

TextEdit.GutterType

GetGutterWidth(int)

Returns the width of the gutter at the given index.

public int GetGutterWidth(int gutter)

Parameters

gutter int

Returns

int

GetHScrollBar()

Returns the HScrollBar used by TextEdit.

public HScrollBar GetHScrollBar()

Returns

HScrollBar

GetIndentLevel(int)

Returns the number of spaces and tab * tab_size before the first char.

public int GetIndentLevel(int line)

Parameters

line int

Returns

int

GetLastFullVisibleLine()

Returns the last visible line. Use GetLastFullVisibleLineWrapIndex() for the wrap index.

public int GetLastFullVisibleLine()

Returns

int

GetLastFullVisibleLineWrapIndex()

Returns the last visible wrap index of the last visible line.

public int GetLastFullVisibleLineWrapIndex()

Returns

int

GetLastUnhiddenLine()

Returns the last unhidden line in the entire TextEdit.

public int GetLastUnhiddenLine()

Returns

int

GetLine(int)

Returns the text of a specific line.

public string GetLine(int line)

Parameters

line int

Returns

string

GetLineBackgroundColor(int)

Returns the current background color of the line. Color(0, 0, 0, 0) is returned if no color is set.

public Color GetLineBackgroundColor(int line)

Parameters

line int

Returns

Color

GetLineColumnAtPos(Vector2I, bool)

Returns the line and column at the given position. In the returned vector, x is the column, y is the line. If allowOutOfBounds is false and the position is not over the text, both vector values will be set to -1.

public Vector2I GetLineColumnAtPos(Vector2I position, bool allowOutOfBounds = true)

Parameters

position Vector2I
allowOutOfBounds bool

Returns

Vector2I

GetLineCount()

Returns the number of lines in the text.

public int GetLineCount()

Returns

int

GetLineGutterIcon(int, int)

Returns the icon currently in gutter at line. This only works when the gutter type is Icon (see SetGutterType(int, GutterType)).

public Texture2D GetLineGutterIcon(int line, int gutter)

Parameters

line int
gutter int

Returns

Texture2D

GetLineGutterItemColor(int, int)

Returns the color currently in gutter at line.

public Color GetLineGutterItemColor(int line, int gutter)

Parameters

line int
gutter int

Returns

Color

GetLineGutterMetadata(int, int)

Returns the metadata currently in gutter at line.

public Variant GetLineGutterMetadata(int line, int gutter)

Parameters

line int
gutter int

Returns

Variant

GetLineGutterText(int, int)

Returns the text currently in gutter at line. This only works when the gutter type is String (see SetGutterType(int, GutterType)).

public string GetLineGutterText(int line, int gutter)

Parameters

line int
gutter int

Returns

string

GetLineHeight()

Returns the maximum value of the line height among all lines.

Note: The return value is influenced by line_spacing and font_size. And it will not be less than 1.

public int GetLineHeight()

Returns

int

GetLineRangesFromCarets(bool, bool)

Returns an Array of line ranges where x is the first line and y is the last line. All lines within these ranges will have a caret on them or be part of a selection. Each line will only be part of one line range, even if it has multiple carets on it.

If a selection's end column (GetSelectionToColumn(int)) is at column 0, that line will not be included. If a selection begins on the line after another selection ends and mergeAdjacent is true, or they begin and end on the same line, one line range will include both selections.

public Array<Vector2I> GetLineRangesFromCarets(bool onlySelections = false, bool mergeAdjacent = true)

Parameters

onlySelections bool
mergeAdjacent bool

Returns

Array<Vector2I>

GetLineWidth(int, int)

Returns the width in pixels of the wrapIndex on line.

public int GetLineWidth(int line, int wrapIndex = -1)

Parameters

line int
wrapIndex int

Returns

int

GetLineWrapCount(int)

Returns the number of times the given line is wrapped.

public int GetLineWrapCount(int line)

Parameters

line int

Returns

int

GetLineWrapIndexAtColumn(int, int)

Returns the wrap index of the given line column.

public int GetLineWrapIndexAtColumn(int line, int column)

Parameters

line int
column int

Returns

int

GetLineWrappedText(int)

Returns an array of strings representing each wrapped index.

public string[] GetLineWrappedText(int line)

Parameters

line int

Returns

string[]

GetLocalMousePos()

Returns the local mouse position adjusted for the text direction.

public Vector2 GetLocalMousePos()

Returns

Vector2

GetMenu()

Returns the PopupMenu of this TextEdit. By default, this menu is displayed when right-clicking on the TextEdit.

You can add custom menu items or remove standard ones. Make sure your IDs don't conflict with the standard ones (see TextEdit.MenuItems). For example:

public override void _Ready()
  {
      var menu = GetMenu();
      // Remove all items after "Redo".
      menu.ItemCount = menu.GetItemIndex(TextEdit.MenuItems.Redo) + 1;
      // Add custom items.
      menu.AddSeparator();
      menu.AddItem("Insert Date", TextEdit.MenuItems.Max + 1);
      // Add event handler.
      menu.IdPressed += OnItemPressed;
  }

public void OnItemPressed(int id) { if (id == TextEdit.MenuItems.Max + 1) { InsertTextAtCaret(Time.GetDateStringFromSystem()); } }

Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their Visible property.

public PopupMenu GetMenu()

Returns

PopupMenu

GetMinimapLineAtPos(Vector2I)

Returns the equivalent minimap line at position.

public int GetMinimapLineAtPos(Vector2I position)

Parameters

position Vector2I

Returns

int

GetMinimapVisibleLines()

Returns the number of lines that may be drawn on the minimap.

public int GetMinimapVisibleLines()

Returns

int

GetNextVisibleLineIndexOffsetFrom(int, int, int)

Similar to GetNextVisibleLineOffsetFrom(int, int), but takes into account the line wrap indexes. In the returned vector, x is the line, y is the wrap index.

public Vector2I GetNextVisibleLineIndexOffsetFrom(int line, int wrapIndex, int visibleAmount)

Parameters

line int
wrapIndex int
visibleAmount int

Returns

Vector2I

GetNextVisibleLineOffsetFrom(int, int)

Returns the count to the next visible line from line to line + visible_amount. Can also count backwards. For example if a TextEdit has 5 lines with lines 2 and 3 hidden, calling this with line = 1, visible_amount = 1 would return 3.

public int GetNextVisibleLineOffsetFrom(int line, int visibleAmount)

Parameters

line int
visibleAmount int

Returns

int

GetPosAtLineColumn(int, int)

Returns the local position for the given line and column. If x or y of the returned vector equal -1, the position is outside of the viewable area of the control.

Note: The Y position corresponds to the bottom side of the line. Use GetRectAtLineColumn(int, int) to get the top side position.

public Vector2I GetPosAtLineColumn(int line, int column)

Parameters

line int
column int

Returns

Vector2I

GetRectAtLineColumn(int, int)

Returns the local position and size for the grapheme at the given line and column. If x or y position of the returned rect equal -1, the position is outside of the viewable area of the control.

Note: The Y position of the returned rect corresponds to the top side of the line, unlike GetPosAtLineColumn(int, int) which returns the bottom side.

public Rect2I GetRectAtLineColumn(int line, int column)

Parameters

line int
column int

Returns

Rect2I

GetSavedVersion()

Returns the last tagged saved version from TagSavedVersion().

public uint GetSavedVersion()

Returns

uint

GetScrollPosForLine(int, int)

Returns the scroll position for wrapIndex of line.

public double GetScrollPosForLine(int line, int wrapIndex = 0)

Parameters

line int
wrapIndex int

Returns

double

GetSelectedText(int)

Returns the text inside the selection of a caret, or all the carets if caretIndex is its default value -1.

public string GetSelectedText(int caretIndex = -1)

Parameters

caretIndex int

Returns

string

GetSelectionAtLineColumn(int, int, bool, bool)

Returns the caret index of the selection at the given line and column, or -1 if there is none.

If includeEdges is false, the position must be inside the selection and not at either end. If onlySelections is false, carets without a selection will also be considered.

public int GetSelectionAtLineColumn(int line, int column, bool includeEdges = true, bool onlySelections = true)

Parameters

line int
column int
includeEdges bool
onlySelections bool

Returns

int

GetSelectionColumn(int)

Returns the original start column of the selection.

[Obsolete("Use 'Godot.TextEdit.GetSelectionOriginColumn(int)' instead.")]
public int GetSelectionColumn(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetSelectionFromColumn(int)

Returns the selection begin column. Returns the caret column if there is no selection.

public int GetSelectionFromColumn(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetSelectionFromLine(int)

Returns the selection begin line. Returns the caret line if there is no selection.

public int GetSelectionFromLine(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetSelectionLine(int)

Returns the original start line of the selection.

[Obsolete("Use 'Godot.TextEdit.GetSelectionOriginLine(int)' instead.")]
public int GetSelectionLine(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetSelectionMode()

Returns the current selection mode.

public TextEdit.SelectionMode GetSelectionMode()

Returns

TextEdit.SelectionMode

GetSelectionOriginColumn(int)

Returns the origin column of the selection. This is the opposite end from the caret.

public int GetSelectionOriginColumn(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetSelectionOriginLine(int)

Returns the origin line of the selection. This is the opposite end from the caret.

public int GetSelectionOriginLine(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetSelectionToColumn(int)

Returns the selection end column. Returns the caret column if there is no selection.

public int GetSelectionToColumn(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetSelectionToLine(int)

Returns the selection end line. Returns the caret line if there is no selection.

public int GetSelectionToLine(int caretIndex = 0)

Parameters

caretIndex int

Returns

int

GetSortedCarets(bool)

Returns the carets sorted by selection beginning from lowest line and column to highest (from top to bottom of text).

If includeIgnoredCarets is false, carets from MulticaretEditIgnoreCaret(int) will be ignored.

public int[] GetSortedCarets(bool includeIgnoredCarets = false)

Parameters

includeIgnoredCarets bool

Returns

int[]

GetTabSize()

Returns the TextEdit's' tab size.

public int GetTabSize()

Returns

int

GetTotalGutterWidth()

Returns the total width of all gutters and internal padding.

public int GetTotalGutterWidth()

Returns

int

GetTotalVisibleLineCount()

Returns the number of lines that may be drawn.

public int GetTotalVisibleLineCount()

Returns

int

GetVScrollBar()

Returns the VScrollBar of the TextEdit.

public VScrollBar GetVScrollBar()

Returns

VScrollBar

GetVersion()

Returns the current version of the TextEdit. The version is a count of recorded operations by the undo/redo history.

public uint GetVersion()

Returns

uint

GetVisibleLineCount()

Returns the number of visible lines, including wrapped text.

public int GetVisibleLineCount()

Returns

int

GetVisibleLineCountInRange(int, int)

Returns the total number of visible + wrapped lines between the two lines.

public int GetVisibleLineCountInRange(int fromLine, int toLine)

Parameters

fromLine int
toLine int

Returns

int

GetWordAtPos(Vector2)

Returns the word at position.

public string GetWordAtPos(Vector2 position)

Parameters

position Vector2

Returns

string

GetWordUnderCaret(int)

Returns a string text with the word under the caret's location.

public string GetWordUnderCaret(int caretIndex = -1)

Parameters

caretIndex int

Returns

string

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

HasImeText()

Returns true if the user has text in the Input Method Editor (IME).

public bool HasImeText()

Returns

bool

HasRedo()

Returns true if a "redo" action is available.

public bool HasRedo()

Returns

bool

HasSelection(int)

Returns true if the user has selected text.

public bool HasSelection(int caretIndex = -1)

Parameters

caretIndex int

Returns

bool

HasUndo()

Returns true if an "undo" action is available.

public bool HasUndo()

Returns

bool

InsertLineAt(int, string)

Inserts a new line with text at line.

public void InsertLineAt(int line, string text)

Parameters

line int
text string

InsertText(string, int, int, bool, bool)

Inserts the text at line and column.

If beforeSelectionBegin is true, carets and selections that begin at line and column will moved to the end of the inserted text, along with all carets after it.

If beforeSelectionEnd is true, selections that end at line and column will be extended to the end of the inserted text. These parameters can be used to insert text inside of or outside of selections.

public void InsertText(string text, int line, int column, bool beforeSelectionBegin = true, bool beforeSelectionEnd = false)

Parameters

text string
line int
column int
beforeSelectionBegin bool
beforeSelectionEnd bool

InsertTextAtCaret(string, int)

Insert the specified text at the caret position.

public void InsertTextAtCaret(string text, int caretIndex = -1)

Parameters

text string
caretIndex int

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

IsCaretAfterSelectionOrigin(int)

Returns true if the caret of the selection is after the selection origin. This can be used to determine the direction of the selection.

public bool IsCaretAfterSelectionOrigin(int caretIndex = 0)

Parameters

caretIndex int

Returns

bool

IsCaretVisible(int)

Returns true if the caret is visible on the screen.

public bool IsCaretVisible(int caretIndex = 0)

Parameters

caretIndex int

Returns

bool

IsDraggingCursor()

Returns true if the user is dragging their mouse for scrolling, selecting, or text dragging.

public bool IsDraggingCursor()

Returns

bool

IsGutterClickable(int)

Returns whether the gutter is clickable.

public bool IsGutterClickable(int gutter)

Parameters

gutter int

Returns

bool

IsGutterDrawn(int)

Returns whether the gutter is currently drawn.

public bool IsGutterDrawn(int gutter)

Parameters

gutter int

Returns

bool

IsGutterOverwritable(int)

Returns whether the gutter is overwritable.

public bool IsGutterOverwritable(int gutter)

Parameters

gutter int

Returns

bool

IsInMulitcaretEdit()

Returns true if a BeginMulticaretEdit() has been called and EndMulticaretEdit() has not yet been called.

public bool IsInMulitcaretEdit()

Returns

bool

IsLineGutterClickable(int, int)

Returns whether the gutter on the given line is clickable.

public bool IsLineGutterClickable(int line, int gutter)

Parameters

line int
gutter int

Returns

bool

IsLineWrapped(int)

Returns if the given line is wrapped.

public bool IsLineWrapped(int line)

Parameters

line int

Returns

bool

IsMenuVisible()

Returns whether the menu is visible. Use this instead of get_menu().visible to improve performance (so the creation of the menu is avoided).

public bool IsMenuVisible()

Returns

bool

IsMouseOverSelection(bool, int)

Returns whether the mouse is over selection. If edges is true, the edges are considered part of the selection.

public bool IsMouseOverSelection(bool edges, int caretIndex = -1)

Parameters

edges bool
caretIndex int

Returns

bool

IsOvertypeModeEnabled()

Returns whether the user is in overtype mode.

public bool IsOvertypeModeEnabled()

Returns

bool

MenuOption(int)

Executes a given action as defined in the TextEdit.MenuItems enum.

public void MenuOption(int option)

Parameters

option int

MergeGutters(int, int)

Merge the gutters from fromLine into toLine. Only overwritable gutters will be copied.

public void MergeGutters(int fromLine, int toLine)

Parameters

fromLine int
toLine int

MergeOverlappingCarets()

Merges any overlapping carets. Will favor the newest caret, or the caret with a selection.

If IsInMulitcaretEdit() is true, the merge will be queued to happen at the end of the multicaret edit. See BeginMulticaretEdit() and EndMulticaretEdit().

Note: This is not called when a caret changes position but after certain actions, so it is possible to get into a state where carets overlap.

public void MergeOverlappingCarets()

MulticaretEditIgnoreCaret(int)

Returns true if the given caretIndex should be ignored as part of a multicaret edit. See BeginMulticaretEdit() and EndMulticaretEdit(). Carets that should be ignored are ones that were part of removed text and will likely be merged at the end of the edit, or carets that were added during the edit.

It is recommended to continue within a loop iterating on multiple carets if a caret should be ignored.

public bool MulticaretEditIgnoreCaret(int caretIndex)

Parameters

caretIndex int

Returns

bool

Paste(int)

Paste at the current location. Can be overridden with _Paste(int).

public void Paste(int caretIndex = -1)

Parameters

caretIndex int

PastePrimaryClipboard(int)

Pastes the primary clipboard.

public void PastePrimaryClipboard(int caretIndex = -1)

Parameters

caretIndex int

Redo()

Perform redo operation.

public void Redo()

RemoveCaret(int)

Removes the given caret index.

Note: This can result in adjustment of all other caret indices.

public void RemoveCaret(int caret)

Parameters

caret int

RemoveGutter(int)

Removes the gutter from this TextEdit.

public void RemoveGutter(int gutter)

Parameters

gutter int

RemoveLineAt(int, bool)

Removes the line of text at line. Carets on this line will attempt to match their previous visual x position.

If moveCaretsDown is true carets will move to the next line down, otherwise carets will move up.

public void RemoveLineAt(int line, bool moveCaretsDown = true)

Parameters

line int
moveCaretsDown bool

RemoveSecondaryCarets()

Removes all additional carets.

public void RemoveSecondaryCarets()

RemoveText(int, int, int, int)

Removes text between the given positions.

public void RemoveText(int fromLine, int fromColumn, int toLine, int toColumn)

Parameters

fromLine int
fromColumn int
toLine int
toColumn int

Search(string, uint, int, int)

Perform a search inside the text. Search flags can be specified in the TextEdit.SearchFlags enum.

In the returned vector, x is the column, y is the line. If no results are found, both are equal to -1.

Vector2I result = Search("print", (uint)TextEdit.SearchFlags.WholeWords, 0, 0);
  if (result.X != -1)
  {
      // Result found.
      int lineNumber = result.Y;
      int columnNumber = result.X;
  }
public Vector2I Search(string text, uint flags, int fromLine, int fromColumn)

Parameters

text string
flags uint
fromLine int
fromColumn int

Returns

Vector2I

Select(int, int, int, int, int)

Selects text from originLine and originColumn to caretLine and caretColumn for the given caretIndex. This moves the selection origin and the caret. If the positions are the same, the selection will be deselected.

If SelectingEnabled is false, no selection will occur.

Note: If supporting multiple carets this will not check for any overlap. See MergeOverlappingCarets().

public void Select(int originLine, int originColumn, int caretLine, int caretColumn, int caretIndex = 0)

Parameters

originLine int
originColumn int
caretLine int
caretColumn int
caretIndex int

SelectAll()

Select all the text.

If SelectingEnabled is false, no selection will occur.

public void SelectAll()

SelectWordUnderCaret(int)

Selects the word under the caret.

public void SelectWordUnderCaret(int caretIndex = -1)

Parameters

caretIndex int

SetCaretColumn(int, bool, int)

Moves the caret to the specified column index.

If adjustViewport is true, the viewport will center at the caret position after the move occurs.

Note: If supporting multiple carets this will not check for any overlap. See MergeOverlappingCarets().

public void SetCaretColumn(int column, bool adjustViewport = true, int caretIndex = 0)

Parameters

column int
adjustViewport bool
caretIndex int

SetCaretLine(int, bool, bool, int, int)

Moves the caret to the specified line index. The caret column will be moved to the same visual position it was at the last time SetCaretColumn(int, bool, int) was called, or clamped to the end of the line.

If adjustViewport is true, the viewport will center at the caret position after the move occurs.

If canBeHidden is true, the specified line can be hidden.

If wrapIndex is -1, the caret column will be clamped to the line's length. If wrapIndex is greater than -1, the column will be moved to attempt to match the visual x position on the line's wrapIndex to the position from the last time SetCaretColumn(int, bool, int) was called.

Note: If supporting multiple carets this will not check for any overlap. See MergeOverlappingCarets().

public void SetCaretLine(int line, bool adjustViewport = true, bool canBeHidden = true, int wrapIndex = 0, int caretIndex = 0)

Parameters

line int
adjustViewport bool
canBeHidden bool
wrapIndex int
caretIndex int

SetGutterClickable(int, bool)

Sets the gutter as clickable. This will change the mouse cursor to a pointing hand when hovering over the gutter.

public void SetGutterClickable(int gutter, bool clickable)

Parameters

gutter int
clickable bool

SetGutterCustomDraw(int, Callable)

Set a custom draw method for the gutter. The callback method must take the following args: line: int, gutter: int, Area: Rect2. This only works when the gutter type is Custom (see SetGutterType(int, GutterType)).

public void SetGutterCustomDraw(int column, Callable drawCallback)

Parameters

column int
drawCallback Callable

SetGutterDraw(int, bool)

Sets whether the gutter should be drawn.

public void SetGutterDraw(int gutter, bool draw)

Parameters

gutter int
draw bool

SetGutterName(int, string)

Sets the name of the gutter.

public void SetGutterName(int gutter, string name)

Parameters

gutter int
name string

SetGutterOverwritable(int, bool)

Sets the gutter to overwritable. See MergeGutters(int, int).

public void SetGutterOverwritable(int gutter, bool overwritable)

Parameters

gutter int
overwritable bool

SetGutterType(int, GutterType)

Sets the type of gutter. Gutters can contain icons, text, or custom visuals. See TextEdit.GutterType for options.

public void SetGutterType(int gutter, TextEdit.GutterType type)

Parameters

gutter int
type TextEdit.GutterType

SetGutterWidth(int, int)

Set the width of the gutter.

public void SetGutterWidth(int gutter, int width)

Parameters

gutter int
width int

SetLine(int, string)

Sets the text for a specific line.

Carets on the line will attempt to keep their visual x position.

public void SetLine(int line, string newText)

Parameters

line int
newText string

SetLineAsCenterVisible(int, int)

Positions the wrapIndex of line at the center of the viewport.

public void SetLineAsCenterVisible(int line, int wrapIndex = 0)

Parameters

line int
wrapIndex int

SetLineAsFirstVisible(int, int)

Positions the wrapIndex of line at the top of the viewport.

public void SetLineAsFirstVisible(int line, int wrapIndex = 0)

Parameters

line int
wrapIndex int

SetLineAsLastVisible(int, int)

Positions the wrapIndex of line at the bottom of the viewport.

public void SetLineAsLastVisible(int line, int wrapIndex = 0)

Parameters

line int
wrapIndex int

SetLineBackgroundColor(int, Color)

Sets the current background color of the line. Set to Color(0, 0, 0, 0) for no color.

public void SetLineBackgroundColor(int line, Color color)

Parameters

line int
color Color

SetLineGutterClickable(int, int, bool)

If clickable is true, makes the gutter on line clickable. See GutterClicked.

public void SetLineGutterClickable(int line, int gutter, bool clickable)

Parameters

line int
gutter int
clickable bool

SetLineGutterIcon(int, int, Texture2D)

Sets the icon for gutter on line to icon. This only works when the gutter type is Icon (see SetGutterType(int, GutterType)).

public void SetLineGutterIcon(int line, int gutter, Texture2D icon)

Parameters

line int
gutter int
icon Texture2D

SetLineGutterItemColor(int, int, Color)

Sets the color for gutter on line to color.

public void SetLineGutterItemColor(int line, int gutter, Color color)

Parameters

line int
gutter int
color Color

SetLineGutterMetadata(int, int, Variant)

Sets the metadata for gutter on line to metadata.

public void SetLineGutterMetadata(int line, int gutter, Variant metadata)

Parameters

line int
gutter int
metadata Variant

SetLineGutterText(int, int, string)

Sets the text for gutter on line to text. This only works when the gutter type is String (see SetGutterType(int, GutterType)).

public void SetLineGutterText(int line, int gutter, string text)

Parameters

line int
gutter int
text string

SetOvertypeModeEnabled(bool)

If true, sets the user into overtype mode. When the user types in this mode, it will override existing text.

public void SetOvertypeModeEnabled(bool enabled)

Parameters

enabled bool

SetSearchFlags(uint)

Sets the search flags. This is used with SetSearchText(string) to highlight occurrences of the searched text. Search flags can be specified from the TextEdit.SearchFlags enum.

public void SetSearchFlags(uint flags)

Parameters

flags uint

SetSearchText(string)

Sets the search text. See SetSearchFlags(uint).

public void SetSearchText(string searchText)

Parameters

searchText string

SetSelectionMode(SelectionMode)

Sets the current selection mode.

public void SetSelectionMode(TextEdit.SelectionMode mode)

Parameters

mode TextEdit.SelectionMode

SetSelectionOriginColumn(int, int)

Sets the selection origin column to the column for the given caretIndex. If the selection origin is moved to the caret position, the selection will deselect.

public void SetSelectionOriginColumn(int column, int caretIndex = 0)

Parameters

column int
caretIndex int

SetSelectionOriginLine(int, bool, int, int)

Sets the selection origin line to the line for the given caretIndex. If the selection origin is moved to the caret position, the selection will deselect.

If canBeHidden is false, The line will be set to the nearest unhidden line below or above.

If wrapIndex is -1, the selection origin column will be clamped to the line's length. If wrapIndex is greater than -1, the column will be moved to attempt to match the visual x position on the line's wrapIndex to the position from the last time SetSelectionOriginColumn(int, int) or Select(int, int, int, int, int) was called.

public void SetSelectionOriginLine(int line, bool canBeHidden = true, int wrapIndex = -1, int caretIndex = 0)

Parameters

line int
canBeHidden bool
wrapIndex int
caretIndex int

SetTabSize(int)

Sets the tab size for the TextEdit to use.

public void SetTabSize(int size)

Parameters

size int

SetTooltipRequestFunc(Callable)

Provide custom tooltip text. The callback method must take the following args: hovered_word: String.

public void SetTooltipRequestFunc(Callable callback)

Parameters

callback Callable

SkipSelectionForNextOccurrence()

Moves a selection and a caret for the next occurrence of the current selection. If there is no active selection, moves to the next occurrence of the word under caret.

public void SkipSelectionForNextOccurrence()

StartAction(EditAction)

Starts an action, will end the current action if action is different.

An action will also end after a call to EndAction(), after ProjectSettings.gui/timers/text_edit_idle_detect_sec is triggered or a new undoable step outside the StartAction(EditAction) and EndAction() calls.

public void StartAction(TextEdit.EditAction action)

Parameters

action TextEdit.EditAction

SwapLines(int, int)

Swaps the two lines. Carets will be swapped with the lines.

public void SwapLines(int fromLine, int toLine)

Parameters

fromLine int
toLine int

TagSavedVersion()

Tag the current version as saved.

public void TagSavedVersion()

Undo()

Perform undo operation.

public void Undo()

_Backspace(int)

Override this method to define what happens when the user presses the backspace key.

public virtual void _Backspace(int caretIndex)

Parameters

caretIndex int

_Copy(int)

Override this method to define what happens when the user performs a copy operation.

public virtual void _Copy(int caretIndex)

Parameters

caretIndex int

_Cut(int)

Override this method to define what happens when the user performs a cut operation.

public virtual void _Cut(int caretIndex)

Parameters

caretIndex int

_HandleUnicodeInput(int, int)

Override this method to define what happens when the user types in the provided key unicodeChar.

public virtual void _HandleUnicodeInput(int unicodeChar, int caretIndex)

Parameters

unicodeChar int
caretIndex int

_Paste(int)

Override this method to define what happens when the user performs a paste operation.

public virtual void _Paste(int caretIndex)

Parameters

caretIndex int

_PastePrimaryClipboard(int)

Override this method to define what happens when the user performs a paste operation with middle mouse button.

Note: This method is only implemented on Linux.

public virtual void _PastePrimaryClipboard(int caretIndex)

Parameters

caretIndex int

Events

CaretChanged

Emitted when any caret changes position.

public event Action CaretChanged

Event Type

Action

GutterAdded

Emitted when a gutter is added.

public event Action GutterAdded

Event Type

Action

GutterClicked

Emitted when a gutter is clicked.

public event TextEdit.GutterClickedEventHandler GutterClicked

Event Type

TextEdit.GutterClickedEventHandler

GutterRemoved

Emitted when a gutter is removed.

public event Action GutterRemoved

Event Type

Action

LinesEditedFrom

Emitted immediately when the text changes.

When text is added fromLine will be less than toLine. On a remove toLine will be less than fromLine.

public event TextEdit.LinesEditedFromEventHandler LinesEditedFrom

Event Type

TextEdit.LinesEditedFromEventHandler

TextChanged

Emitted when the text changes.

public event Action TextChanged

Event Type

Action

TextSet

Emitted when Clear() is called or Text is set.

public event Action TextSet

Event Type

Action