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
CaretBlink
If true, makes the caret blink.
public bool CaretBlink { get; set; }
Property Value
CaretBlinkInterval
The interval at which the caret blinks (in seconds).
public float CaretBlinkInterval { get; set; }
Property Value
CaretDrawWhenEditableDisabled
public bool CaretDrawWhenEditableDisabled { get; set; }
Property Value
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
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
CaretMultiple
Sets if multiple carets are allowed.
public bool CaretMultiple { get; set; }
Property Value
CaretType
Set the type of caret to draw.
public TextEdit.CaretTypeEnum CaretType { get; set; }
Property Value
ContextMenuEnabled
If true, a right-click displays the context menu.
public bool ContextMenuEnabled { get; set; }
Property Value
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
DeselectOnFocusLossEnabled
If true, the selected text will be deselected when focus is lost.
public bool DeselectOnFocusLossEnabled { get; set; }
Property Value
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
DrawControlChars
If true, control characters are displayed.
public bool DrawControlChars { get; set; }
Property Value
DrawSpaces
If true, the "space" character will have a visible representation.
public bool DrawSpaces { get; set; }
Property Value
DrawTabs
If true, the "tab" character will have a visible representation.
public bool DrawTabs { get; set; }
Property Value
Editable
If false, existing text cannot be modified and new text cannot be added.
public bool Editable { get; set; }
Property Value
HighlightAllOccurrences
If true, all occurrences of the selected text will be highlighted.
public bool HighlightAllOccurrences { get; set; }
Property Value
HighlightCurrentLine
If true, the line containing the cursor is highlighted.
public bool HighlightCurrentLine { get; set; }
Property Value
IndentWrappedLines
If true, all wrapped lines are indented to the same amount as the unwrapped line.
public bool IndentWrappedLines { get; set; }
Property Value
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
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
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
MinimapWidth
The width, in pixels, of the minimap.
public int MinimapWidth { get; set; }
Property Value
PlaceholderText
public string PlaceholderText { get; set; }
Property Value
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
ScrollHorizontal
If there is a horizontal scrollbar, this determines the current horizontal scroll value in pixels.
public int ScrollHorizontal { get; set; }
Property Value
ScrollPastEndOfFile
Allow scrolling past the last line into "virtual" space.
public bool ScrollPastEndOfFile { get; set; }
Property Value
ScrollSmooth
Scroll smoothly over the text rather than jumping to the next location.
public bool ScrollSmooth { get; set; }
Property Value
ScrollVScrollSpeed
Sets the scroll speed with the minimap or when ScrollSmooth is enabled.
public float ScrollVScrollSpeed { get; set; }
Property Value
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
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
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
StructuredTextBidiOverride
Set BiDi algorithm override for the structured text.
public TextServer.StructuredTextParser StructuredTextBidiOverride { get; set; }
Property Value
StructuredTextBidiOverrideOptions
Set additional options for BiDi override.
public Array StructuredTextBidiOverrideOptions { get; set; }
Property Value
SyntaxHighlighter
Sets the SyntaxHighlighter to use.
public SyntaxHighlighter SyntaxHighlighter { get; set; }
Property Value
Text
String value of the TextEdit.
public string Text { get; set; }
Property Value
TextDirection
Base text writing direction.
public Control.TextDirection TextDirection { get; set; }
Property Value
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
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
VirtualKeyboardEnabled
If true, the native virtual keyboard is shown when focused on platforms that support it.
public bool VirtualKeyboardEnabled { get; set; }
Property Value
WrapMode
Sets the line wrapping mode to use.
public TextEdit.LineWrappingMode WrapMode { get; set; }
Property Value
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
Returns
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
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
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
GetCaretCount()
Returns the number of carets in this TextEdit.
public int GetCaretCount()
Returns
GetCaretDrawPos(int)
Returns the caret pixel draw position.
public Vector2 GetCaretDrawPos(int caretIndex = 0)
Parameters
caretIndex
int
Returns
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
GetCaretWrapIndex(int)
Returns the wrap index the editing caret is on.
public int GetCaretWrapIndex(int caretIndex = 0)
Parameters
caretIndex
int
Returns
GetFirstNonWhiteSpaceColumn(int)
Returns the first column containing a non-whitespace character.
public int GetFirstNonWhiteSpaceColumn(int line)
Parameters
line
int
Returns
GetFirstVisibleLine()
Returns the first visible line.
public int GetFirstVisibleLine()
Returns
GetGutterCount()
Returns the number of gutters registered.
public int GetGutterCount()
Returns
GetGutterName(int)
Returns the name of the gutter at the given index.
public string GetGutterName(int gutter)
Parameters
gutter
int
Returns
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
GetGutterWidth(int)
Returns the width of the gutter at the given index.
public int GetGutterWidth(int gutter)
Parameters
gutter
int
Returns
GetHScrollBar()
Returns the HScrollBar used by TextEdit.
public HScrollBar GetHScrollBar()
Returns
GetIndentLevel(int)
Returns the number of spaces and tab * tab_size
before the first char.
public int GetIndentLevel(int line)
Parameters
line
int
Returns
GetLastFullVisibleLine()
Returns the last visible line. Use GetLastFullVisibleLineWrapIndex() for the wrap index.
public int GetLastFullVisibleLine()
Returns
GetLastFullVisibleLineWrapIndex()
Returns the last visible wrap index of the last visible line.
public int GetLastFullVisibleLineWrapIndex()
Returns
GetLastUnhiddenLine()
Returns the last unhidden line in the entire TextEdit.
public int GetLastUnhiddenLine()
Returns
GetLine(int)
Returns the text of a specific line.
public string GetLine(int line)
Parameters
line
int
Returns
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
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
Returns
GetLineCount()
Returns the number of lines in the text.
public int GetLineCount()
Returns
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
Returns
GetLineGutterItemColor(int, int)
Returns the color currently in gutter
at line
.
public Color GetLineGutterItemColor(int line, int gutter)
Parameters
Returns
GetLineGutterMetadata(int, int)
Returns the metadata currently in gutter
at line
.
public Variant GetLineGutterMetadata(int line, int gutter)
Parameters
Returns
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
Returns
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
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
Returns
GetLineWidth(int, int)
Returns the width in pixels of the wrapIndex
on line
.
public int GetLineWidth(int line, int wrapIndex = -1)
Parameters
Returns
GetLineWrapCount(int)
Returns the number of times the given line is wrapped.
public int GetLineWrapCount(int line)
Parameters
line
int
Returns
GetLineWrapIndexAtColumn(int, int)
Returns the wrap index of the given line column.
public int GetLineWrapIndexAtColumn(int line, int column)
Parameters
Returns
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
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
GetMinimapLineAtPos(Vector2I)
Returns the equivalent minimap line at position
.
public int GetMinimapLineAtPos(Vector2I position)
Parameters
position
Vector2I
Returns
GetMinimapVisibleLines()
Returns the number of lines that may be drawn on the minimap.
public int GetMinimapVisibleLines()
Returns
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
Returns
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
Returns
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
Returns
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
Returns
GetSavedVersion()
Returns the last tagged saved version from TagSavedVersion().
public uint GetSavedVersion()
Returns
GetScrollPosForLine(int, int)
Returns the scroll position for wrapIndex
of line
.
public double GetScrollPosForLine(int line, int wrapIndex = 0)
Parameters
Returns
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
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
Returns
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
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
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
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
GetSelectionMode()
Returns the current selection mode.
public TextEdit.SelectionMode GetSelectionMode()
Returns
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
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
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
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
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
GetTotalGutterWidth()
Returns the total width of all gutters and internal padding.
public int GetTotalGutterWidth()
Returns
GetTotalVisibleLineCount()
Returns the number of lines that may be drawn.
public int GetTotalVisibleLineCount()
Returns
GetVScrollBar()
Returns the VScrollBar of the TextEdit.
public VScrollBar GetVScrollBar()
Returns
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
GetVisibleLineCount()
Returns the number of visible lines, including wrapped text.
public int GetVisibleLineCount()
Returns
GetVisibleLineCountInRange(int, int)
Returns the total number of visible + wrapped lines between the two lines.
public int GetVisibleLineCountInRange(int fromLine, int toLine)
Parameters
Returns
GetWordAtPos(Vector2)
Returns the word at position
.
public string GetWordAtPos(Vector2 position)
Parameters
position
Vector2
Returns
GetWordUnderCaret(int)
Returns a string text with the word under the caret's location.
public string GetWordUnderCaret(int caretIndex = -1)
Parameters
caretIndex
int
Returns
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_nameName of the method to check for.
Returns
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_nameName of the signal to check for.
Returns
HasImeText()
Returns true if the user has text in the Input Method Editor (IME).
public bool HasImeText()
Returns
HasRedo()
Returns true if a "redo" action is available.
public bool HasRedo()
Returns
HasSelection(int)
Returns true if the user has selected text.
public bool HasSelection(int caretIndex = -1)
Parameters
caretIndex
int
Returns
HasUndo()
Returns true if an "undo" action is available.
public bool HasUndo()
Returns
InsertLineAt(int, string)
Inserts a new line with text
at line
.
public void InsertLineAt(int line, string text)
Parameters
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
InsertTextAtCaret(string, int)
Insert the specified text at the caret position.
public void InsertTextAtCaret(string text, int caretIndex = -1)
Parameters
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_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
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
IsCaretVisible(int)
Returns true if the caret is visible on the screen.
public bool IsCaretVisible(int caretIndex = 0)
Parameters
caretIndex
int
Returns
IsDraggingCursor()
Returns true if the user is dragging their mouse for scrolling, selecting, or text dragging.
public bool IsDraggingCursor()
Returns
IsGutterClickable(int)
Returns whether the gutter is clickable.
public bool IsGutterClickable(int gutter)
Parameters
gutter
int
Returns
IsGutterDrawn(int)
Returns whether the gutter is currently drawn.
public bool IsGutterDrawn(int gutter)
Parameters
gutter
int
Returns
IsGutterOverwritable(int)
Returns whether the gutter is overwritable.
public bool IsGutterOverwritable(int gutter)
Parameters
gutter
int
Returns
IsInMulitcaretEdit()
Returns true if a BeginMulticaretEdit() has been called and EndMulticaretEdit() has not yet been called.
public bool IsInMulitcaretEdit()
Returns
IsLineGutterClickable(int, int)
Returns whether the gutter on the given line is clickable.
public bool IsLineGutterClickable(int line, int gutter)
Parameters
Returns
IsLineWrapped(int)
Returns if the given line is wrapped.
public bool IsLineWrapped(int line)
Parameters
line
int
Returns
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
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
Returns
IsOvertypeModeEnabled()
Returns whether the user is in overtype mode.
public bool IsOvertypeModeEnabled()
Returns
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
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
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
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
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
Returns
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
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
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
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
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
SetGutterDraw(int, bool)
Sets whether the gutter should be drawn.
public void SetGutterDraw(int gutter, bool draw)
Parameters
SetGutterName(int, string)
Sets the name of the gutter.
public void SetGutterName(int gutter, string name)
Parameters
SetGutterOverwritable(int, bool)
Sets the gutter to overwritable. See MergeGutters(int, int).
public void SetGutterOverwritable(int gutter, bool overwritable)
Parameters
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
inttype
TextEdit.GutterType
SetGutterWidth(int, int)
Set the width of the gutter.
public void SetGutterWidth(int gutter, int width)
Parameters
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
SetLineAsCenterVisible(int, int)
Positions the wrapIndex
of line
at the center of the viewport.
public void SetLineAsCenterVisible(int line, int wrapIndex = 0)
Parameters
SetLineAsFirstVisible(int, int)
Positions the wrapIndex
of line
at the top of the viewport.
public void SetLineAsFirstVisible(int line, int wrapIndex = 0)
Parameters
SetLineAsLastVisible(int, int)
Positions the wrapIndex
of line
at the bottom of the viewport.
public void SetLineAsLastVisible(int line, int wrapIndex = 0)
Parameters
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
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
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
SetLineGutterItemColor(int, int, Color)
Sets the color for gutter
on line
to color
.
public void SetLineGutterItemColor(int line, int gutter, Color color)
Parameters
SetLineGutterMetadata(int, int, Variant)
Sets the metadata for gutter
on line
to metadata
.
public void SetLineGutterMetadata(int line, int gutter, Variant metadata)
Parameters
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
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
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
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
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
_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
GutterAdded
Emitted when a gutter is added.
public event Action GutterAdded
Event Type
GutterClicked
Emitted when a gutter is clicked.
public event TextEdit.GutterClickedEventHandler GutterClicked
Event Type
GutterRemoved
Emitted when a gutter is removed.
public event Action GutterRemoved
Event Type
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
TextChanged
Emitted when the text changes.
public event Action TextChanged
Event Type
TextSet
public event Action TextSet