A multiline text editor.
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.
While entering text, it is possible to insert special characters using Unicode, OEM or Windows alt codes:
- To enter Unicode codepoints, hold Alt and type the codepoint on the numpad. For example, to enter the character á (U+00E1), hold Alt and type +E1 on the numpad (the leading zeroes can be omitted).
- To enter OEM codepoints, hold Alt and type the code on the numpad. For example, to enter the character á (OEM 160), hold Alt and type 160 on the numpad.
- To enter Windows codepoints, hold Alt and type the code on the numpad. For example, to enter the character á (Windows 0225), hold Alt and type 0, 2, 2, 5 on the numpad. The leading zero here must not be omitted, as this is how Windows codepoints are distinguished from OEM codepoints.
Note: Most viewport, caret, and edit methods contain a caret_index argument for caret_multiple 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.
If wrap_mode is set to LINE_WRAPPING_BOUNDARY, sets text wrapping mode.
If true and caret_mid_grapheme is false, backspace deletes an entire composite character such as ❤️🩹, instead of deleting part of the composite character.
If true, caret will be visible when editable is disabled.
Allow moving caret, selecting and removing the individual composite character components.
Note: Backspace is always removing individual composite character components.
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.
If true, multiple carets are allowed. Left-clicking with Alt adds a new caret. See add_caret() and get_caret_count().
The characters to consider as word delimiters if use_custom_word_separators is true. The characters should be defined without separation, for example #_!.
If true, copying or cutting without a selection is performed on all lines with a caret. Otherwise, copy and cut require a selection.
Language code used for line-breaking and text shaping algorithms. If left empty, the current locale is used instead.
If false, using middle mouse button to paste clipboard will be disabled.
Note: This method is only implemented on Linux.
If true, a minimap is shown, providing an outline of your source code. The minimap uses a fixed-width text size.
If true, TextEdit fits its minimum height to the number of visible lines instead of scrolling vertically. If a maximum height is set (for example via Control.custom_maximum_size) and content exceeds it, a vertical scrollbar is shown.
If true, TextEdit fits its minimum width to the widest line instead of scrolling horizontally. If a maximum width is set (for example via Control.custom_maximum_size) and content exceeds it, a horizontal scrollbar is shown.
Sets the scroll speed with the minimap or when scroll_smooth is enabled.
If there is a vertical scrollbar, this determines the current vertical scroll value in line numbers, starting at 0 for the top line.
If true, text can be selected.
If false, text can not be selected by the user or by the select() or select_all() methods.
The syntax highlighter to use.
Note: A SyntaxHighlighter instance should not be used across multiple TextEdit nodes.
If true, ProjectSettings.input/ui_text_indent input Tab character, otherwise it moves keyboard focus to the next Control in the scene.
If false, using Ctrl + Left or Ctrl + Right (Cmd + Left or Cmd + Right on macOS) bindings will use the behavior of use_default_word_separators. If true, it will also stop the caret if a character within custom_word_separators is detected. Useful for subword moving. This behavior also will be applied to the behavior of text selection.
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.
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.
Adds a new caret at the given location. Returns the index of the new caret, or -1 if the location is invalid.
Adds an additional caret above or below every caret. If below is true the new caret will be added below and above otherwise.
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.
Adds a selection and a caret for the next occurrence of the current selection. If there is no active selection, selects word under caret.
This method does nothing.
Applies text from the Input Method Editor (IME) to each caret and closes the IME if it is open.
Called when the user presses the backspace key. Can be overridden with _backspace().
Starts a multipart edit. All edits will be treated as one action until end_complex_operation() is called.
Starts an edit for multiple carets. The edit must be ended with end_multicaret_edit(). 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. begin_multicaret_edit() and end_multicaret_edit() can be nested, and the merge will happen at the last end_multicaret_edit().
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()Closes the Input Method Editor (IME) if it is open. Any text in the IME will be lost.
Centers the viewport on the line the editing caret is at. This also resets the scroll_horizontal value to 0.
Collapse all carets in the given range to the from_line and from_column position.
inclusive applies to both ends.
If is_in_mulitcaret_edit() is true, carets that are collapsed will be true for multicaret_edit_ignore_caret().
merge_overlapping_carets() will be called if any carets were collapsed.
Copies the current text selection. Can be overridden with _copy().
Ends a multipart edit, started with begin_complex_operation(). If called outside a complex operation, the current operation is pushed onto the undo/redo stack.
Ends an edit for multiple carets, that was started with begin_multicaret_edit(). If this was the last end_multicaret_edit() and merge_overlapping_carets() was called, carets will be merged.
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 insert_text_at_caret() are applied.
Returns the first column containing a non-whitespace character on the given line. If there is only whitespace, returns the number of characters.
Returns the type of the gutter at the given index. Gutters can contain icons, text, or custom visuals.
Returns the indent level of the given line. This is the number of spaces and tabs at the beginning of the line, with the tabs taking the tab size into account (see get_tab_size()).
Returns the last visible line. Use get_last_full_visible_line_wrap_index() for the wrap index.
Returns the custom background color of the given line. If no color is set, returns Color(0, 0, 0, 0).
Returns the line and column at the given position. In the returned vector, x is the column and y is the line.
If clamp_line is false and position is below the last line, Vector2i(-1, -1) is returned.
If clamp_column is false and position is outside the column range of the line, Vector2i(-1, -1) is returned.
Returns the icon currently in gutter at line. This only works when the gutter type is GUTTER_TYPE_ICON (see set_gutter_type()).
Returns the text currently in gutter at line. This only works when the gutter type is GUTTER_TYPE_STRING (see set_gutter_type()).
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.
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 (get_selection_to_column()) is at column 0, that line will not be included. If a selection begins on the line after another selection ends and merge_adjacent is true, or they begin and end on the same line, one line range will include both selections.
Returns the wrap index of the given column on the given line. This ranges from 0 to get_line_wrap_count().
Returns an array of Strings representing each wrapped index.
Returns the correct column at the end of a composite character like ❤️🩹 (mending heart; Unicode: U+2764 U+FE0F U+200D U+1FA79) which is comprised of more than one Unicode code point, if the caret is at the start of the composite character. Also returns the correct column with the caret at mid grapheme and for non-composite characters.
Note: To check at caret location use get_next_composite_character_column(get_caret_line(), get_caret_column())
Similar to get_next_visible_line_offset_from(), but takes into account the line wrap indexes. In the returned vector, x is the line, y is the wrap index.
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.
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 get_rect_at_line_column() to get the top side position.
Returns the correct column at the start of a composite character like ❤️🩹 (mending heart; Unicode: U+2764 U+FE0F U+200D U+1FA79) which is comprised of more than one Unicode code point, if the caret is at the end of the composite character. Also returns the correct column with the caret at mid grapheme and for non-composite characters.
Note: To check at caret location use get_previous_composite_character_column(get_caret_line(), get_caret_column())
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 get_pos_at_line_column() which returns the bottom side.
Returns the text inside the selection of a caret, or all the carets if caret_index is its default value -1.
Returns the caret index of the selection at the given line and column, or -1 if there is none.
If include_edges is false, the position must be inside the selection and not at either end. If only_selections is false, carets without a selection will also be considered.
Returns the carets sorted by selection beginning from lowest line and column to highest (from top to bottom of text).
If include_ignored_carets is false, carets from multicaret_edit_ignore_caret() will be ignored.
Returns the total number of lines in the text. This includes wrapped lines and excludes folded lines. If wrap_mode is set to LINE_WRAPPING_NONE and no lines are folded (see CodeEdit.is_line_folded()) then this is equivalent to get_line_count(). See get_visible_line_count_in_range() for a limited range of lines.
Returns the current version of the TextEdit. The version is a count of recorded operations by the undo/redo history.
Returns the total number of lines between from_line and to_line (inclusive) in the text. This includes wrapped lines and excludes folded lines. If the range covers all lines it is equivalent to get_total_visible_line_count().
Returns a String text with the word under the caret's location.
Inserts the text at line and column.
If before_selection_begin 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 before_selection_end 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.
Returns true if the caret of the selection is after the selection origin. This can be used to determine the direction of the selection.
Returns true if the caret is visible, false otherwise. A caret will be considered hidden if it is outside the scrollable area when scrolling is enabled.
Note: is_caret_visible() does not account for a caret being off-screen if it is still within the scrollable area. It will return true even if the caret is off-screen as long as it meets TextEdit's own conditions for being visible. This includes uses of scroll_fit_content_width and scroll_fit_content_height that cause the TextEdit to expand beyond the viewport's bounds.
Note: This method does not guarantee an accurate visibility check immediately after setting the caret position. The correct value may only be available in the next frame after the TextEdit has finished drawing. This also applies to any operation that causes the TextEdit to change in size.
Returns true if the gutter at the given index is clickable. See set_gutter_clickable().
Returns true if the gutter at the given index is currently drawn. See set_gutter_draw().
Returns true if the gutter at the given index is overwritable. See set_gutter_overwritable().
Returns true if a begin_multicaret_edit() has been called and end_multicaret_edit() has not yet been called.
Returns true if the gutter at the given index on the given line is clickable. See set_line_gutter_clickable().
Returns true if the mouse is over a selection. If edges is true, the edges are considered part of the selection.
Returns true if overtype mode is enabled. See set_overtype_mode_enabled().
Merge the gutters from from_line into to_line. Only overwritable gutters will be copied. See set_gutter_overwritable().
Merges any overlapping carets. Will favor the newest caret, or the caret with a selection.
If is_in_mulitcaret_edit() is true, the merge will be queued to happen at the end of the multicaret edit. See begin_multicaret_edit() and end_multicaret_edit().
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.
Returns true if the given caret_index should be ignored as part of a multicaret edit. See begin_multicaret_edit() and end_multicaret_edit(). 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.
Paste at the current location. Can be overridden with _paste().
Removes the line of text at line. Carets on this line will attempt to match their previous visual x position.
If move_carets_down is true carets will move to the next line down, otherwise carets will move up.
Perform a search inside the text. Search flags can be specified in the SearchFlags enum.
In the returned vector, x is the column, y is the line. If no results are found, both are equal to -1.
var result = search("print", SEARCH_WHOLE_WORDS, 0, 0)
if result.x != -1:
# Result found.
var line_number = result.y
var column_number = result.xSelects text from origin_line and origin_column to caret_line and caret_column for the given caret_index. This moves the selection origin and the caret. If the positions are the same, the selection will be deselected.
If selecting_enabled is false, no selection will occur.
Note: If supporting multiple carets this will not check for any overlap. See merge_overlapping_carets().
Select all the text.
If selecting_enabled is false, no selection will occur.
Moves the caret to the specified column index.
If adjust_viewport 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 merge_overlapping_carets().
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 set_caret_column() was called, or clamped to the end of the line.
If adjust_viewport is true, the viewport will center at the caret position after the move occurs.
If can_be_hidden is true, the specified line can be hidden.
If wrap_index is -1, the caret column will be clamped to the line's length. If wrap_index is greater than -1, the column will be moved to attempt to match the visual x position on the line's wrap_index to the position from the last time set_caret_column() was called.
Note: If supporting multiple carets this will not check for any overlap. See merge_overlapping_carets().
If true, the mouse cursor will change to a pointing hand (Control.CURSOR_POINTING_HAND) when hovering over the gutter at the given index. See is_gutter_clickable() and set_line_gutter_clickable().
Set a custom draw callback for the gutter at the given index. draw_callback must take the following arguments: A line index int, a gutter index int, and an area Rect2. This callback only works when the gutter type is GUTTER_TYPE_CUSTOM (see set_gutter_type()).
If true, the gutter at the given index is drawn. The gutter type (set_gutter_type()) determines how it is drawn. See is_gutter_drawn().
If true, the line data of the gutter at the given index can be overridden when using merge_gutters(). See is_gutter_overwritable().
Sets the custom background color of the given line. If transparent, this color is applied on top of the default background color (See background_color). If set to Color(0, 0, 0, 0), no additional color is applied.
If clickable is true, makes the gutter on the given line clickable. This is like set_gutter_clickable(), but for a single line. If is_gutter_clickable() is true, this will not have any effect. See is_line_gutter_clickable() and gutter_clicked.
Sets the icon for gutter on line to icon. This only works when the gutter type is GUTTER_TYPE_ICON (see set_gutter_type()).
Sets the text for gutter on line to text. This only works when the gutter type is GUTTER_TYPE_STRING (see set_gutter_type()).
If true, enables overtype mode. In this mode, typing overrides existing text instead of inserting text. The ProjectSettings.input/ui_text_toggle_insert_mode action toggles overtype mode. See is_overtype_mode_enabled().
Sets the search flags. This is used with set_search_text() to highlight occurrences of the searched text. Search flags can be specified from the SearchFlags enum.
Sets the selection origin column to the column for the given caret_index. If the selection origin is moved to the caret position, the selection will deselect.
Sets the selection origin line to the line for the given caret_index. If the selection origin is moved to the caret position, the selection will deselect.
If can_be_hidden is false, The line will be set to the nearest unhidden line below or above.
If wrap_index is -1, the selection origin column will be clamped to the line's length. If wrap_index is greater than -1, the column will be moved to attempt to match the visual x position on the line's wrap_index to the position from the last time set_selection_origin_column() or select() was called.
Provide custom tooltip text. The callback method must take the following args: hovered_word: String.
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.
Starts an action, will end the current action if action is different.
An action will also end after a call to end_action(), after ProjectSettings.gui/timers/text_edit_idle_detect_sec is triggered or a new undoable step outside the start_action() and end_action() calls.
Emitted immediately when the text changes.
When text is added from_line will be less than to_line. On a remove to_line will be less than from_line.
MENU_CUT = 0Cuts (copies and clears) the selected text.
MENU_COPY = 1Copies the selected text.
MENU_PASTE = 2Pastes the clipboard text over the selected text (or at the cursor's position).
MENU_CLEAR = 3Erases the whole TextEdit text.
MENU_SELECT_ALL = 4Selects the whole TextEdit text.
MENU_UNDO = 5Undoes the previous action.
MENU_REDO = 6Redoes the previous action.
MENU_SUBMENU_TEXT_DIR = 7ID of "Text Writing Direction" submenu.
MENU_DIR_INHERITED = 8Sets text direction to inherited.
MENU_DIR_AUTO = 9Sets text direction to automatic.
MENU_DIR_LTR = 10Sets text direction to left-to-right.
MENU_DIR_RTL = 11Sets text direction to right-to-left.
MENU_DISPLAY_UCC = 12Toggles control character display.
MENU_SUBMENU_INSERT_UCC = 13ID of "Insert Control Character" submenu.
MENU_INSERT_LRM = 14Inserts left-to-right mark (LRM) character.
MENU_INSERT_RLM = 15Inserts right-to-left mark (RLM) character.
MENU_INSERT_LRE = 16Inserts start of left-to-right embedding (LRE) character.
MENU_INSERT_RLE = 17Inserts start of right-to-left embedding (RLE) character.
MENU_INSERT_LRO = 18Inserts start of left-to-right override (LRO) character.
MENU_INSERT_RLO = 19Inserts start of right-to-left override (RLO) character.
MENU_INSERT_PDF = 20Inserts pop direction formatting (PDF) character.
MENU_INSERT_ALM = 21Inserts Arabic letter mark (ALM) character.
MENU_INSERT_LRI = 22Inserts left-to-right isolate (LRI) character.
MENU_INSERT_RLI = 23Inserts right-to-left isolate (RLI) character.
MENU_INSERT_FSI = 24Inserts first strong isolate (FSI) character.
MENU_INSERT_PDI = 25Inserts pop direction isolate (PDI) character.
MENU_INSERT_ZWJ = 26Inserts zero width joiner (ZWJ) character.
MENU_INSERT_ZWNJ = 27Inserts zero width non-joiner (ZWNJ) character.
MENU_INSERT_WJ = 28Inserts word joiner (WJ) character.
MENU_INSERT_SHY = 29Inserts soft hyphen (SHY) character.
MENU_EMOJI_AND_SYMBOL = 30Opens system emoji and symbol picker.
MENU_MAX = 31Represents the size of the MenuItems enum.
ACTION_NONE = 0No current action.
ACTION_TYPING = 1A typing action.
ACTION_BACKSPACE = 2A backwards delete action.
ACTION_DELETE = 3A forward delete action.
SEARCH_MATCH_CASE = 1Match case when searching.
SEARCH_WHOLE_WORDS = 2Match whole words when searching.
SEARCH_BACKWARDS = 4Search from end to beginning.
SELECTION_MODE_NONE = 0Not selecting.
SELECTION_MODE_SHIFT = 1Select as if shift is pressed.
SELECTION_MODE_POINTER = 2Select single characters as if the user single clicked.
SELECTION_MODE_WORD = 3Select whole words as if the user double clicked.
SELECTION_MODE_LINE = 4Select whole lines as if the user triple clicked.
LINE_WRAPPING_NONE = 0Line wrapping is disabled.
LINE_WRAPPING_BOUNDARY = 1Line wrapping occurs at the control boundary, beyond what would normally be visible.
GUTTER_TYPE_STRING = 0When a gutter is set to string using set_gutter_type(), it is used to contain text set via the set_line_gutter_text() method.
GUTTER_TYPE_ICON = 1When a gutter is set to icon using set_gutter_type(), it is used to contain an icon set via the set_line_gutter_icon() method.
GUTTER_TYPE_CUSTOM = 2When a gutter is set to custom using set_gutter_type(), it is used to contain custom visuals controlled by a callback method set via the set_gutter_custom_draw() method.