TextEdit

Inherits: Control < CanvasItem < Node < Object

Inherited By: CodeEdit

Multiline text editing control.

Description

TextEdit is meant for editing large, multiline text. It also has facilities for editing code, such as syntax highlighting support and multiple levels of undo/redo.

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.

Properties

bool

caret_blink

false

float

caret_blink_interval

0.65

bool

caret_mid_grapheme

true

bool

caret_move_on_right_click

true

CaretType

caret_type

0

bool

context_menu_enabled

true

bool

deselect_on_focus_loss_enabled

true

bool

drag_and_drop_selection_enabled

true

bool

draw_control_chars

false

bool

draw_spaces

false

bool

draw_tabs

false

bool

editable

true

FocusMode

focus_mode

2 (overrides Control)

bool

highlight_all_occurrences

false

bool

highlight_current_line

false

String

language

""

bool

middle_mouse_paste_enabled

true

bool

minimap_draw

false

int

minimap_width

80

CursorShape

mouse_default_cursor_shape

1 (overrides Control)

bool

override_selected_font_color

false

String

placeholder_text

""

bool

scroll_fit_content_height

false

int

scroll_horizontal

0

bool

scroll_past_end_of_file

false

bool

scroll_smooth

false

float

scroll_v_scroll_speed

80.0

float

scroll_vertical

0.0

bool

selecting_enabled

true

bool

shortcut_keys_enabled

true

StructuredTextParser

structured_text_bidi_override

0

Array

structured_text_bidi_override_options

[]

SyntaxHighlighter

syntax_highlighter

String

text

""

TextDirection

text_direction

0

bool

virtual_keyboard_enabled

true

LineWrappingMode

wrap_mode

0

Methods

void

_backspace ( ) virtual

void

_copy ( ) virtual

void

_cut ( ) virtual

void

_handle_unicode_input ( int unicode_char ) virtual

void

_paste ( ) virtual

void

_paste_primary_clipboard ( ) virtual

void

add_gutter ( int at=-1 )

void

adjust_viewport_to_caret ( )

void

backspace ( )

void

begin_complex_operation ( )

void

center_viewport_to_caret ( )

void

clear ( )

void

clear_undo_history ( )

void

copy ( )

void

cut ( )

void

delete_selection ( )

void

deselect ( )

void

end_complex_operation ( )

int

get_caret_column ( ) const

Vector2

get_caret_draw_pos ( ) const

int

get_caret_line ( ) const

int

get_caret_wrap_index ( ) const

int

get_first_non_whitespace_column ( int line ) const

int

get_first_visible_line ( ) const

int

get_gutter_count ( ) const

String

get_gutter_name ( int gutter ) const

GutterType

get_gutter_type ( int gutter ) const

int

get_gutter_width ( int gutter ) const

int

get_indent_level ( int line ) const

int

get_last_full_visible_line ( ) const

int

get_last_full_visible_line_wrap_index ( ) const

int

get_last_unhidden_line ( ) const

String

get_line ( int line ) const

Color

get_line_background_color ( int line ) const

Vector2i

get_line_column_at_pos ( Vector2i position, bool allow_out_of_bounds=true ) const

int

get_line_count ( ) const

Texture2D

get_line_gutter_icon ( int line, int gutter ) const

Color

get_line_gutter_item_color ( int line, int gutter ) const

Variant

get_line_gutter_metadata ( int line, int gutter ) const

String

get_line_gutter_text ( int line, int gutter ) const

int

get_line_height ( ) const

int

get_line_width ( int line, int wrap_index=-1 ) const

int

get_line_wrap_count ( int line ) const

int

get_line_wrap_index_at_column ( int line, int column ) const

PackedStringArray

get_line_wrapped_text ( int line ) const

Vector2

get_local_mouse_pos ( ) const

PopupMenu

get_menu ( ) const

int

get_minimap_line_at_pos ( Vector2i position ) const

int

get_minimap_visible_lines ( ) const

Vector2i

get_next_visible_line_index_offset_from ( int line, int wrap_index, int visible_amount ) const

int

get_next_visible_line_offset_from ( int line, int visible_amount ) const

Vector2i

get_pos_at_line_column ( int line, int column ) const

Rect2i

get_rect_at_line_column ( int line, int column ) const

int

get_saved_version ( ) const

float

get_scroll_pos_for_line ( int line, int wrap_index=0 ) const

String

get_selected_text ( ) const

int

get_selection_column ( ) const

int

get_selection_from_column ( ) const

int

get_selection_from_line ( ) const

int

get_selection_line ( ) const

SelectionMode

get_selection_mode ( ) const

int

get_selection_to_column ( ) const

int

get_selection_to_line ( ) const

int

get_tab_size ( ) const

int

get_total_gutter_width ( ) const

int

get_total_visible_line_count ( ) const

int

get_version ( ) const

int

get_visible_line_count ( ) const

int

get_visible_line_count_in_range ( int from_line, int to_line ) const

String

get_word_at_pos ( Vector2 position ) const

String

get_word_under_caret ( ) const

bool

has_ime_text ( ) const

bool

has_redo ( ) const

bool

has_selection ( ) const

bool

has_undo ( ) const

void

insert_line_at ( int line, String text )

void

insert_text_at_caret ( String text )

bool

is_caret_visible ( ) const

bool

is_dragging_cursor ( ) const

bool

is_gutter_clickable ( int gutter ) const

bool

is_gutter_drawn ( int gutter ) const

bool

is_gutter_overwritable ( int gutter ) const

bool

is_line_gutter_clickable ( int line, int gutter ) const

bool

is_line_wrapped ( int line ) const

bool

is_menu_visible ( ) const

bool

is_mouse_over_selection ( bool edges ) const

bool

is_overtype_mode_enabled ( ) const

void

menu_option ( int option )

void

merge_gutters ( int from_line, int to_line )

void

paste ( )

void

redo ( )

void

remove_gutter ( int gutter )

void

remove_text ( int from_line, int from_column, int to_line, int to_column )

Vector2i

search ( String text, int flags, int from_line, int from_colum ) const

void

select ( int from_line, int from_column, int to_line, int to_column )

void

select_all ( )

void

select_word_under_caret ( )

void

set_caret_column ( int column, bool adjust_viewport=true )

void

set_caret_line ( int line, bool adjust_viewport=true, bool can_be_hidden=true, int wrap_index=0 )

void

set_gutter_clickable ( int gutter, bool clickable )

void

set_gutter_custom_draw ( int column, Callable draw_callback )

void

set_gutter_draw ( int gutter, bool draw )

void

set_gutter_name ( int gutter, String name )

void

set_gutter_overwritable ( int gutter, bool overwritable )

void

set_gutter_type ( int gutter, GutterType type )

void

set_gutter_width ( int gutter, int width )

void

set_line ( int line, String new_text )

void

set_line_as_center_visible ( int line, int wrap_index=0 )

void

set_line_as_first_visible ( int line, int wrap_index=0 )

void

set_line_as_last_visible ( int line, int wrap_index=0 )

void

set_line_background_color ( int line, Color color )

void

set_line_gutter_clickable ( int line, int gutter, bool clickable )

void

set_line_gutter_icon ( int line, int gutter, Texture2D icon )

void

set_line_gutter_item_color ( int line, int gutter, Color color )

void

set_line_gutter_metadata ( int line, int gutter, Variant metadata )

void

set_line_gutter_text ( int line, int gutter, String text )

void

set_overtype_mode_enabled ( bool enabled )

void

set_search_flags ( int flags )

void

set_search_text ( String search_text )

void

set_selection_mode ( SelectionMode mode, int line=-1, int column=-1 )

void

set_tab_size ( int size )

void

set_tooltip_request_func ( Callable callback )

void

swap_lines ( int from_line, int to_line )

void

tag_saved_version ( )

void

undo ( )

Theme Properties

Color

background_color

Color(0, 0, 0, 0)

Color

caret_background_color

Color(0, 0, 0, 1)

Color

caret_color

Color(0.875, 0.875, 0.875, 1)

Color

current_line_color

Color(0.25, 0.25, 0.26, 0.8)

Color

font_color

Color(0.875, 0.875, 0.875, 1)

Color

font_outline_color

Color(1, 1, 1, 1)

Color

font_placeholder_color

Color(0.875, 0.875, 0.875, 0.6)

Color

font_readonly_color

Color(0.875, 0.875, 0.875, 0.5)

Color

font_selected_color

Color(1, 1, 1, 1)

Color

search_result_border_color

Color(0.3, 0.3, 0.3, 0.4)

Color

search_result_color

Color(0.3, 0.3, 0.3, 1)

Color

selection_color

Color(0.5, 0.5, 0.5, 1)

Color

word_highlighted_color

Color(0.5, 0.5, 0.5, 0.25)

int

caret_width

1

int

line_spacing

4

int

outline_size

0

Font

font

int

font_size

Texture2D

space

Texture2D

tab

StyleBox

focus

StyleBox

normal

StyleBox

read_only

Signals

  • caret_changed ( )

Emitted when the caret changes position.


  • gutter_added ( )

Emitted when a gutter is added.


  • gutter_clicked ( int line, int gutter )

Emitted when a gutter is clicked.


  • gutter_removed ( )

Emitted when a gutter is removed.


  • lines_edited_from ( int from_line, int to_line )

Emitted immediately when the text changes.

When text is added from_line will be less then to_line. On a remove to_line will be less then from_line.


  • text_changed ( )

Emitted when the text changes.


  • text_set ( )

Emitted when clear is called or text is set.

Enumerations

enum MenuItems:

  • MENU_CUT = 0 --- Cuts (copies and clears) the selected text.

  • MENU_COPY = 1 --- Copies the selected text.

  • MENU_PASTE = 2 --- Pastes the clipboard text over the selected text (or at the cursor's position).

  • MENU_CLEAR = 3 --- Erases the whole TextEdit text.

  • MENU_SELECT_ALL = 4 --- Selects the whole TextEdit text.

  • MENU_UNDO = 5 --- Undoes the previous action.

  • MENU_REDO = 6 --- Redoes the previous action.

  • MENU_DIR_INHERITED = 7 --- Sets text direction to inherited.

  • MENU_DIR_AUTO = 8 --- Sets text direction to automatic.

  • MENU_DIR_LTR = 9 --- Sets text direction to left-to-right.

  • MENU_DIR_RTL = 10 --- Sets text direction to right-to-left.

  • MENU_DISPLAY_UCC = 11 --- Toggles control character display.

  • MENU_INSERT_LRM = 12 --- Inserts left-to-right mark (LRM) character.

  • MENU_INSERT_RLM = 13 --- Inserts right-to-left mark (RLM) character.

  • MENU_INSERT_LRE = 14 --- Inserts start of left-to-right embedding (LRE) character.

  • MENU_INSERT_RLE = 15 --- Inserts start of right-to-left embedding (RLE) character.

  • MENU_INSERT_LRO = 16 --- Inserts start of left-to-right override (LRO) character.

  • MENU_INSERT_RLO = 17 --- Inserts start of right-to-left override (RLO) character.

  • MENU_INSERT_PDF = 18 --- Inserts pop direction formatting (PDF) character.

  • MENU_INSERT_ALM = 19 --- Inserts Arabic letter mark (ALM) character.

  • MENU_INSERT_LRI = 20 --- Inserts left-to-right isolate (LRI) character.

  • MENU_INSERT_RLI = 21 --- Inserts right-to-left isolate (RLI) character.

  • MENU_INSERT_FSI = 22 --- Inserts first strong isolate (FSI) character.

  • MENU_INSERT_PDI = 23 --- Inserts pop direction isolate (PDI) character.

  • MENU_INSERT_ZWJ = 24 --- Inserts zero width joiner (ZWJ) character.

  • MENU_INSERT_ZWNJ = 25 --- Inserts zero width non-joiner (ZWNJ) character.

  • MENU_INSERT_WJ = 26 --- Inserts word joiner (WJ) character.

  • MENU_INSERT_SHY = 27 --- Inserts soft hyphen (SHY) character.

  • MENU_MAX = 28 --- Represents the size of the MenuItems enum.


enum SearchFlags:

  • SEARCH_MATCH_CASE = 1 --- Match case when searching.

  • SEARCH_WHOLE_WORDS = 2 --- Match whole words when searching.

  • SEARCH_BACKWARDS = 4 --- Search from end to beginning.


enum CaretType:

  • CARET_TYPE_LINE = 0 --- Vertical line caret.

  • CARET_TYPE_BLOCK = 1 --- Block caret.


enum SelectionMode:

  • SELECTION_MODE_NONE = 0 --- Not selecting.

  • SELECTION_MODE_SHIFT = 1 --- Select as if shift is pressed.

  • SELECTION_MODE_POINTER = 2 --- Select single characters as if the user single clicked.

  • SELECTION_MODE_WORD = 3 --- Select whole words as if the user double clicked.

  • SELECTION_MODE_LINE = 4 --- Select whole lines as if the user tripped clicked.


enum LineWrappingMode:

  • LINE_WRAPPING_NONE = 0 --- Line wrapping is disabled.

  • LINE_WRAPPING_BOUNDARY = 1 --- Line wrapping occurs at the control boundary, beyond what would normally be visible.


enum GutterType:

  • GUTTER_TYPE_STRING = 0 --- Draw a string.

  • GUTTER_TYPE_ICON = 1 --- Draw an icon.

  • GUTTER_TYPE_CUSTOM = 2 --- Custom draw.

Property Descriptions

Default

false

Setter

set_caret_blink_enabled(value)

Getter

is_caret_blink_enabled()

Sets if the caret should blink.


Default

0.65

Setter

set_caret_blink_interval(value)

Getter

get_caret_blink_interval()

Duration (in seconds) of a caret's blinking cycle.


  • bool caret_mid_grapheme

Default

true

Setter

set_caret_mid_grapheme_enabled(value)

Getter

is_caret_mid_grapheme_enabled()

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

Note: Backspace is always removing individual composite character components.


  • bool caret_move_on_right_click

Default

true

Setter

set_move_caret_on_right_click_enabled(value)

Getter

is_move_caret_on_right_click_enabled()

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

If false, the context menu disregards mouse location.


Default

0

Setter

set_caret_type(value)

Getter

get_caret_type()

Set the type of caret to draw.


  • bool context_menu_enabled

Default

true

Setter

set_context_menu_enabled(value)

Getter

is_context_menu_enabled()

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


  • bool deselect_on_focus_loss_enabled

Default

true

Setter

set_deselect_on_focus_loss_enabled(value)

Getter

is_deselect_on_focus_loss_enabled()

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


  • bool drag_and_drop_selection_enabled

Default

true

Setter

set_drag_and_drop_selection_enabled(value)

Getter

is_drag_and_drop_selection_enabled()

If true, allow drag and drop of selected text.


  • bool draw_control_chars

Default

false

Setter

set_draw_control_chars(value)

Getter

get_draw_control_chars()

If true, control characters are displayed.


Default

false

Setter

set_draw_spaces(value)

Getter

is_drawing_spaces()

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


Default

false

Setter

set_draw_tabs(value)

Getter

is_drawing_tabs()

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


Default

true

Setter

set_editable(value)

Getter

is_editable()

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


  • bool highlight_all_occurrences

Default

false

Setter

set_highlight_all_occurrences(value)

Getter

is_highlight_all_occurrences_enabled()

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


  • bool highlight_current_line

Default

false

Setter

set_highlight_current_line(value)

Getter

is_highlight_current_line_enabled()

If true, the line containing the cursor is highlighted.


Default

""

Setter

set_language(value)

Getter

get_language()

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


  • bool middle_mouse_paste_enabled

Default

true

Setter

set_middle_mouse_paste_enabled(value)

Getter

is_middle_mouse_paste_enabled()

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

Note: This method is only implemented on Linux.


Default

false

Setter

set_draw_minimap(value)

Getter

is_drawing_minimap()

If true, a minimap is shown, providing an outline of your source code.


  • int minimap_width

Default

80

Setter

set_minimap_width(value)

Getter

get_minimap_width()

The width, in pixels, of the minimap.


  • bool override_selected_font_color

Default

false

Setter

set_override_selected_font_color(value)

Getter

is_overriding_selected_font_color()

If true, custom font_selected_color will be used for selected text.


Default

""

Setter

set_placeholder(value)

Getter

get_placeholder()

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


  • bool scroll_fit_content_height

Default

false

Setter

set_fit_content_height_enabled(value)

Getter

is_fit_content_height_enabled()

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


  • int scroll_horizontal

Default

0

Setter

set_h_scroll(value)

Getter

get_h_scroll()

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


  • bool scroll_past_end_of_file

Default

false

Setter

set_scroll_past_end_of_file_enabled(value)

Getter

is_scroll_past_end_of_file_enabled()

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


  • bool scroll_smooth

Default

false

Setter

set_smooth_scroll_enabled(value)

Getter

is_smooth_scroll_enabled()

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


  • float scroll_v_scroll_speed

Default

80.0

Setter

set_v_scroll_speed(value)

Getter

get_v_scroll_speed()

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


Default

0.0

Setter

set_v_scroll(value)

Getter

get_v_scroll()

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


  • bool selecting_enabled

Default

true

Setter

set_selecting_enabled(value)

Getter

is_selecting_enabled()

If true, text can be selected.

If false, text can not be selected by the user or by the select or select_all methods.


  • bool shortcut_keys_enabled

Default

true

Setter

set_shortcut_keys_enabled(value)

Getter

is_shortcut_keys_enabled()

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


Default

0

Setter

set_structured_text_bidi_override(value)

Getter

get_structured_text_bidi_override()

Set BiDi algorithm override for the structured text.


  • Array structured_text_bidi_override_options

Default

[]

Setter

set_structured_text_bidi_override_options(value)

Getter

get_structured_text_bidi_override_options()

Set additional options for BiDi override.


Setter

set_syntax_highlighter(value)

Getter

get_syntax_highlighter()

Sets the SyntaxHighlighter to use.


Default

""

Setter

set_text(value)

Getter

get_text()

String value of the TextEdit.


Default

0

Setter

set_text_direction(value)

Getter

get_text_direction()

Base text writing direction.


  • bool virtual_keyboard_enabled

Default

true

Setter

set_virtual_keyboard_enabled(value)

Getter

is_virtual_keyboard_enabled()

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


Default

0

Setter

set_line_wrapping_mode(value)

Getter

get_line_wrapping_mode()

Sets the line wrapping mode to use.

Method Descriptions

  • void _backspace ( ) virtual

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


  • void _copy ( ) virtual

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


  • void _cut ( ) virtual

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


  • void _handle_unicode_input ( int unicode_char ) virtual

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


  • void _paste ( ) virtual

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


  • void _paste_primary_clipboard ( ) virtual

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.


  • void add_gutter ( int at=-1 )

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.


  • void adjust_viewport_to_caret ( )

Adjust the viewport so the caret is visible.


  • void backspace ( )

Called when the user presses the backspace key. Can be overridden with _backspace.


  • void begin_complex_operation ( )

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


  • void center_viewport_to_caret ( )

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


  • void clear ( )

Performs a full reset of TextEdit, including undo history.


  • void clear_undo_history ( )

Clears the undo history.


  • void copy ( )

Copies the current text selection. Can be overridden with _copy.


  • void cut ( )

Cut's the current selection. Can be overridden with _cut.


  • void delete_selection ( )

Deletes the selected text.


  • void deselect ( )

Deselects the current selection.


  • void end_complex_operation ( )

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.