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¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
focus_mode |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
mouse_default_cursor_shape |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
Theme Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Signals¶
caret_changed ( )
Emitted when the caret changes position.
gutter_added ( )
Emitted when a gutter is added.
Emitted when a gutter is clicked.
gutter_removed ( )
Emitted when a gutter is removed.
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 ( )
Enumerations¶
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¶
bool caret_blink
Default |
|
Setter |
set_caret_blink_enabled(value) |
Getter |
is_caret_blink_enabled() |
Sets if the caret should blink.
float caret_blink_speed
Default |
|
Setter |
set_caret_blink_speed(value) |
Getter |
get_caret_blink_speed() |
Duration (in seconds) of a caret's blinking cycle.
bool caret_mid_grapheme
Default |
|
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 |
|
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.
CaretType caret_type
Default |
|
Setter |
set_caret_type(value) |
Getter |
get_caret_type() |
Set the type of caret to draw.
Default |
|
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 |
|
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 draw_control_chars
Default |
|
Setter |
set_draw_control_chars(value) |
Getter |
get_draw_control_chars() |
If true
, control characters are displayed.
bool draw_spaces
Default |
|
Setter |
set_draw_spaces(value) |
Getter |
is_drawing_spaces() |
If true
, the "space" character will have a visible representation.
bool draw_tabs
Default |
|
Setter |
set_draw_tabs(value) |
Getter |
is_drawing_tabs() |
If true
, the "tab" character will have a visible representation.
bool editable
Default |
|
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 |
|
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 |
|
Setter |
set_highlight_current_line(value) |
Getter |
is_highlight_current_line_enabled() |
If true
, the line containing the cursor is highlighted.
String language
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 |
|
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.
bool minimap_draw
Default |
|
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 |
|
Setter |
set_minimap_width(value) |
Getter |
get_minimap_width() |
The width, in pixels, of the minimap.
bool override_selected_font_color
Default |
|
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.
String placeholder_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).
int scroll_horizontal
Default |
|
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 |
|
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 |
|
Setter |
set_smooth_scroll_enable(value) |
Getter |
is_smooth_scroll_enabled() |
Scroll smoothly over the text rather then jumping to the next location.
float scroll_v_scroll_speed
Default |
|
Setter |
set_v_scroll_speed(value) |
Getter |
get_v_scroll_speed() |
Sets the scroll speed with the minimap or when scroll_smooth is enabled.
float scroll_vertical
Default |
|
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 |
|
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 |
|
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.
StructuredTextParser structured_text_bidi_override
Default |
|
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.
SyntaxHighlighter syntax_highlighter
Setter |
set_syntax_highlighter(value) |
Getter |
get_syntax_highlighter() |
Sets the SyntaxHighlighter to use.
String text
Default |
|
Setter |
set_text(value) |
Getter |
get_text() |
String value of the TextEdit
.
TextDirection text_direction
Default |
|
Setter |
set_text_direction(value) |
Getter |
get_text_direction() |
Base text writing direction.
bool virtual_keyboard_enabled
Default |
|
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.
LineWrappingMode wrap_mode
Default |
|
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 types in the provided key unicode
.
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_opentype_features ( )
Removes all OpenType features.
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.
int get_caret_column ( ) const
Returns the column the editing caret is at.
Vector2 get_caret_draw_pos ( ) const
Returns the caret pixel draw position.
int get_caret_line ( ) const
Returns the line the editing caret is on.
int get_caret_wrap_index ( ) const
Returns the wrap index the editing caret is on.
Returns the first column containing a non-whitespace character.
int get_first_visible_line ( ) const
Returns the first visible line.
int get_gutter_count ( ) const
Returns the total amount of gutters registered.
Returns the name of the gutter at the given index.
GutterType get_gutter_type ( int gutter ) const
Returns the type of the gutter at the given index.
Returns the width of the gutter at the given index.
Returns the amount of spaces and tab * tab_size
before the first char.
int get_last_full_visible_line ( ) const
Returns the last visible line. Use get_last_full_visible_line_wrap_index for the wrap index.
int get_last_full_visible_line_wrap_index ( ) const
Returns the last visible wrap index of the last visible line.
Returns the last unhidden line in the entire TextEdit
.
Returns the text of a specific line.
Returns the current background color of the line. Color(0, 0, 0, 0)
is returned if no color is set.
Returns the line and column at the given position. In the returned vector, x
is the column, y
is the line. If allow_out_of_bounds
is false
and the position is not over the text, both vector values will be set to -1
.
int get_line_count ( ) const
Returns the amount of total lines in the text.
Returns the icon currently in gutter
at line
.
Returns the color currently in gutter
at line
.
Returns the metadata currently in gutter
at line
.
Returns the text currently in gutter
at line
.
int get_line_height ( ) const
Returns the height of a largest line.
Returns the width in pixels of the wrap_index
on line
.
Returns the number of times the given line is wrapped.
Returns the wrap index of the given line column.
PackedStringArray get_line_wrapped_text ( int line ) const
Returns an array of Strings