Class TextEdit
A multiline text editor.
- Inheritance
-
TextEdit
- Derived
Remarks
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 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.
Properties
autowrap_mode
If wrap_mode is set to TextEdit.LINE_WRAPPING_BOUNDARY, sets text wrapping mode. To see how each mode behaves, see AutowrapMode.
var autowrap_mode : int = 3
Property Value
Remarks
caret_blink
If true
, makes the caret blink.
var caret_blink : bool = false
Property Value
Remarks
caret_blink_interval
The interval at which the caret blinks (in seconds).
var caret_blink_interval : float = 0.65
Property Value
Remarks
caret_draw_when_editable_disabled
If true
, caret will be visible when editable is disabled.
var caret_draw_when_editable_disabled : bool = false
Property Value
Remarks
caret_mid_grapheme
Allow moving caret, selecting and removing the individual composite character components.
Note: Backspace
is always removing individual composite character components.
var caret_mid_grapheme : bool = false
Property Value
Remarks
caret_move_on_right_click
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.
var caret_move_on_right_click : bool = true
Property Value
Remarks
caret_multiple
If true
, multiple carets are allowed. Left-clicking with Alt
adds a new caret. See TextEdit.add_caret and get_caret_count.
var caret_multiple : bool = true
Property Value
Remarks
caret_type
Set the type of caret to draw.
var caret_type : int = 0
Property Value
Remarks
context_menu_enabled
If true
, a right-click displays the context menu.
var context_menu_enabled : bool = true
Property Value
Remarks
custom_word_separators
The characters to consider as word delimiters if use_custom_word_separators is true
. The characters should be defined without separation, for example #_!
.
var custom_word_separators : String = ""
Property Value
Remarks
deselect_on_focus_loss_enabled
If true
, the selected text will be deselected when focus is lost.
var deselect_on_focus_loss_enabled : bool = true
Property Value
Remarks
drag_and_drop_selection_enabled
If true
, allow drag and drop of selected text. Text can still be dropped from other sources.
var drag_and_drop_selection_enabled : bool = true
Property Value
Remarks
draw_control_chars
If true
, control characters are displayed.
var draw_control_chars : bool = false
Property Value
Remarks
draw_spaces
If true
, the "space" character will have a visible representation.
var draw_spaces : bool = false
Property Value
Remarks
draw_tabs
If true
, the "tab" character will have a visible representation.
var draw_tabs : bool = false
Property Value
Remarks
editable
If false
, existing text cannot be modified and new text cannot be added.
var editable : bool = true
Property Value
Remarks
emoji_menu_enabled
If true
, "Emoji and Symbols" menu is enabled.
var emoji_menu_enabled : bool = true
Property Value
Remarks
empty_selection_clipboard_enabled
If true
, copying or cutting without a selection is performed on all lines with a caret. Otherwise, copy and cut require a selection.
var empty_selection_clipboard_enabled : bool = true
Property Value
Remarks
highlight_all_occurrences
If true
, all occurrences of the selected text will be highlighted.
var highlight_all_occurrences : bool = false
Property Value
Remarks
highlight_current_line
If true
, the line containing the cursor is highlighted.
var highlight_current_line : bool = false
Property Value
Remarks
indent_wrapped_lines
If true
, all wrapped lines are indented to the same amount as the unwrapped line.
var indent_wrapped_lines : bool = false
Property Value
Remarks
language
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
var language : String = ""
Property Value
Remarks
middle_mouse_paste_enabled
If false
, using middle mouse button to paste clipboard will be disabled.
Note: This method is only implemented on Linux.
var middle_mouse_paste_enabled : bool = true
Property Value
Remarks
minimap_draw
If true
, a minimap is shown, providing an outline of your source code. The minimap uses a fixed-width text size.
var minimap_draw : bool = false
Property Value
Remarks
minimap_width
The width, in pixels, of the minimap.
var minimap_width : int = 80
Property Value
Remarks
placeholder_text
Text shown when the TextEdit is empty. It is not the TextEdit's default value (see text).
var placeholder_text : String = ""
Property Value
Remarks
scroll_fit_content_height
If true
, TextEdit will disable vertical scroll and fit minimum height to the number of visible lines. When both this property and scroll_fit_content_width are true
, no scrollbars will be displayed.
var scroll_fit_content_height : bool = false
Property Value
Remarks
scroll_fit_content_width
If true
, TextEdit will disable horizontal scroll and fit minimum width to the widest line in the text. When both this property and scroll_fit_content_height are true
, no scrollbars will be displayed.
var scroll_fit_content_width : bool = false
Property Value
Remarks
scroll_horizontal
If there is a horizontal scrollbar, this determines the current horizontal scroll value in pixels.
var scroll_horizontal : int = 0
Property Value
Remarks
scroll_past_end_of_file
Allow scrolling past the last line into "virtual" space.
var scroll_past_end_of_file : bool = false
Property Value
Remarks
scroll_smooth
Scroll smoothly over the text rather than jumping to the next location.
var scroll_smooth : bool = false
Property Value
Remarks
scroll_v_scroll_speed
Sets the scroll speed with the minimap or when scroll_smooth is enabled.
var scroll_v_scroll_speed : float = 80.0
Property Value
Remarks
scroll_vertical
If there is a vertical scrollbar, this determines the current vertical scroll value in line numbers, starting at 0 for the top line.
var scroll_vertical : float = 0.0
Property Value
Remarks
selecting_enabled
If true
, text can be selected.
If false
, text can not be selected by the user or by the TextEdit.select or select_all methods.
var selecting_enabled : bool = true
Property Value
Remarks
shortcut_keys_enabled
If true
, shortcut keys for context menu items are enabled, even if the context menu is disabled.
var shortcut_keys_enabled : bool = true
Property Value
Remarks
structured_text_bidi_override
Set BiDi algorithm override for the structured text.
var structured_text_bidi_override : int = 0
Property Value
Remarks
structured_text_bidi_override_options
Set additional options for BiDi override.
var structured_text_bidi_override_options : Array = []
Property Value
Remarks
syntax_highlighter
The syntax highlighter to use.
Note: A SyntaxHighlighter instance should not be used across multiple TextEdit nodes.
var syntax_highlighter : SyntaxHighlighter
Property Value
Remarks
- void set_syntax_highlighter(SyntaxHighlighter value)
- SyntaxHighlighter get_syntax_highlighter
text
String value of the TextEdit.
var text : String = ""
Property Value
Remarks
text_direction
Base text writing direction.
var text_direction : int = 0
Property Value
Remarks
use_custom_word_separators
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.
var use_custom_word_separators : bool = false
Property Value
Remarks
use_default_word_separators
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.
var use_default_word_separators : bool = true
Property Value
Remarks
virtual_keyboard_enabled
If true
, the native virtual keyboard is shown when focused on platforms that support it.
var virtual_keyboard_enabled : bool = true
Property Value
Remarks
wrap_mode
Sets the line wrapping mode to use.
var wrap_mode : int = 0
Property Value
Remarks
background_color
Theme Property
Sets the background Color of this TextEdit.
= ``Color(0, 0, 0, 0)``
Property Value
caret_background_color
Theme Property
Color of the text behind the caret when using a block caret.
= ``Color(0, 0, 0, 1)``
Property Value
caret_color
Theme Property
Color of the caret. This can be set to a fully transparent color to hide the caret entirely.
= ``Color(0.875, 0.875, 0.875, 1)``
Property Value
current_line_color
Theme Property
Background Color of the line containing the caret.
= ``Color(0.25, 0.25, 0.26, 0.8)``
Property Value
font_color
Theme Property
Sets the font Color.
= ``Color(0.875, 0.875, 0.875, 1)``
Property Value
font_outline_color
Theme Property
The tint of text outline of the TextEdit.
= ``Color(0, 0, 0, 1)``
Property Value
font_placeholder_color
Theme Property
Font color for placeholder_text.
= ``Color(0.875, 0.875, 0.875, 0.6)``
Property Value
font_readonly_color
= ``Color(0.875, 0.875, 0.875, 0.5)``
Property Value
font_selected_color
Theme Property
Sets the Color of the selected text. If equal to Color(0, 0, 0, 0)
, it will be ignored.
= ``Color(0, 0, 0, 0)``
Property Value
search_result_border_color
Theme Property
Color of the border around text that matches the search query.
= ``Color(0.3, 0.3, 0.3, 0.4)``
Property Value
search_result_color
Theme Property
Color behind the text that matches the search query.
= ``Color(0.3, 0.3, 0.3, 1)``
Property Value
selection_color
Theme Property
Sets the highlight Color of text selections.
= ``Color(0.5, 0.5, 0.5, 1)``
Property Value
word_highlighted_color
Theme Property
Sets the highlight Color of multiple occurrences. highlight_all_occurrences has to be enabled.
= ``Color(0.5, 0.5, 0.5, 0.25)``
Property Value
caret_width
Theme Property
The caret's width in pixels. Greater values can be used to improve accessibility by ensuring the caret is easily visible, or to ensure consistency with a large font size. If set to 0
or lower, the caret width is automatically set to 1 pixel and multiplied by the display scaling factor.
= ``1``
Property Value
line_spacing
Theme Property
Additional vertical spacing between lines (in pixels), spacing is added to line descent. This value can be negative.
= ``4``
Property Value
outline_size
Theme Property
The size of the text outline.
Note: If using a font with multichannel_signed_distance_field enabled, its msdf_pixel_range must be set to at least twice the value of outline_size for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.
= ``0``
Property Value
font
Theme Property
Sets the default Font.
Font font
Property Value
font_size
Theme Property
Sets default font size.
int font_size
Property Value
space
Theme Property
Sets a custom Texture2D for space text characters.
Texture2D space
Property Value
tab
Theme Property
Sets a custom Texture2D for tab text characters.
Texture2D tab
Property Value
focus
Theme Property
Sets the StyleBox when in focus. The focus StyleBox is displayed over the base StyleBox, so a partially transparent StyleBox should be used to ensure the base StyleBox remains visible. A StyleBox that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a StyleBoxEmpty resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.
StyleBox focus
Property Value
normal
Theme Property
Sets the StyleBox of this TextEdit.
StyleBox normal
Property Value
read_only
StyleBox read_only
Property Value
Methods
_backspace(int)
Qualifiers: virtual
Override this method to define what happens when the user presses the backspace key.
void _backspace(int caret_index)
Parameters
caret_index
int
_copy(int)
Qualifiers: virtual
Override this method to define what happens when the user performs a copy operation.
void _copy(int caret_index)
Parameters
caret_index
int
_cut(int)
Qualifiers: virtual
Override this method to define what happens when the user performs a cut operation.
void _cut(int caret_index)
Parameters
caret_index
int
_handle_unicode_input(int, int)
Qualifiers: virtual
Override this method to define what happens when the user types in the provided key unicode_char
.
void _handle_unicode_input(int unicode_char, int caret_index)
Parameters
_paste(int)
Qualifiers: virtual
Override this method to define what happens when the user performs a paste operation.
void _paste(int caret_index)
Parameters
caret_index
int
_paste_primary_clipboard(int)
Qualifiers: 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 _paste_primary_clipboard(int caret_index)
Parameters
caret_index
int
add_caret(int, int)
Adds a new caret at the given location. Returns the index of the new caret, or -1
if the location is invalid.
int add_caret(int line, int column)
Parameters
add_caret_at_carets(bool)
Adds an additional caret above or below every caret. If below
is true
the new caret will be added below and above otherwise.
void add_caret_at_carets(bool below)
Parameters
below
bool
add_gutter(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.
void add_gutter(int at)
Parameters
at
int
add_selection_for_next_occurrence
Adds a selection and a caret for the next occurrence of the current selection. If there is no active selection, selects word under caret.
void add_selection_for_next_occurrence
adjust_carets_after_edit(int, int, int, int, int)
This method does nothing.
void adjust_carets_after_edit(int caret, int from_line, int from_col, int to_line, int to_col)
Parameters
adjust_viewport_to_caret(int)
Adjust the viewport so the caret is visible.
void adjust_viewport_to_caret(int caret_index)
Parameters
caret_index
int
apply_ime
Applies text from the Input Method Editor (IME) to each caret and closes the IME if it is open.
void apply_ime
backspace(int)
Called when the user presses the backspace key. Can be overridden with TextEdit._backspace.
void backspace(int caret_index)
Parameters
caret_index
int
begin_complex_operation
Starts a multipart edit. All edits will be treated as one action until end_complex_operation is called.
void begin_complex_operation
begin_multicaret_edit
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()
void begin_multicaret_edit
cancel_ime
Closes the Input Method Editor (IME) if it is open. Any text in the IME will be lost.
void cancel_ime
center_viewport_to_caret(int)
Centers the viewport on the line the editing caret is at. This also resets the scroll_horizontal value to 0
.
void center_viewport_to_caret(int caret_index)
Parameters
caret_index
int
clear
Performs a full reset of TextEdit, including undo history.
void clear
clear_undo_history
Clears the undo history.
void clear_undo_history
collapse_carets(int, int, int, int, bool)
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 TextEdit.multicaret_edit_ignore_caret.
merge_overlapping_carets will be called if any carets were collapsed.
void collapse_carets(int from_line, int from_column, int to_line, int to_column, bool inclusive)
Parameters
copy(int)
Copies the current text selection. Can be overridden with TextEdit._copy.
void copy(int caret_index)
Parameters
caret_index
int
cut(int)
Cut's the current selection. Can be overridden with TextEdit._cut.
void cut(int caret_index)
Parameters
caret_index
int
delete_selection(int)
Deletes the selected text.
void delete_selection(int caret_index)
Parameters
caret_index
int
deselect(int)
Deselects the current selection.
void deselect(int caret_index)
Parameters
caret_index
int
end_action
Marks the end of steps in the current action started with TextEdit.start_action.
void end_action
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.
void end_complex_operation
end_multicaret_edit
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.
void end_multicaret_edit
get_caret_column(int)
Qualifiers: const
Returns the column the editing caret is at.
int get_caret_column(int caret_index)
Parameters
caret_index
int
get_caret_count
Qualifiers: const
Returns the number of carets in this TextEdit.
int get_caret_count
get_caret_draw_pos(int)
Qualifiers: const
Returns the caret pixel draw position.
Vector2 get_caret_draw_pos(int caret_index)
Parameters
caret_index
int
get_caret_index_edit_order
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 TextEdit.insert_text_at_caret are applied.
PackedInt32Array get_caret_index_edit_order
get_caret_line(int)
Qualifiers: const
Returns the line the editing caret is on.
int get_caret_line(int caret_index)
Parameters
caret_index
int
get_caret_wrap_index(int)
Qualifiers: const
Returns the wrap index the editing caret is on.
int get_caret_wrap_index(int caret_index)
Parameters
caret_index
int
get_first_non_whitespace_column(int)
Qualifiers: const
Returns the first column containing a non-whitespace character on the given line. If there is only whitespace, returns the number of characters.
int get_first_non_whitespace_column(int line)
Parameters
line
int
get_first_visible_line
Qualifiers: const
Returns the first visible line.
int get_first_visible_line
get_gutter_count
Qualifiers: const
Returns the number of gutters registered.
int get_gutter_count
get_gutter_name(int)
Qualifiers: const
Returns the name of the gutter at the given index.
String get_gutter_name(int gutter)
Parameters
gutter
int
get_gutter_type(int)
Qualifiers: const
Returns the type of the gutter at the given index. Gutters can contain icons, text, or custom visuals. See GutterType for options.
int get_gutter_type(int gutter)
Parameters
gutter
int
get_gutter_width(int)
Qualifiers: const
Returns the width of the gutter at the given index.
int get_gutter_width(int gutter)
Parameters
gutter
int
get_h_scroll_bar
Qualifiers: const
Returns the HScrollBar used by TextEdit.
HScrollBar get_h_scroll_bar
get_indent_level(int)
Qualifiers: const
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).
int get_indent_level(int line)
Parameters
line
int
get_last_full_visible_line
Qualifiers: const
Returns the last visible line. Use get_last_full_visible_line_wrap_index for the wrap index.
int get_last_full_visible_line
get_last_full_visible_line_wrap_index
Qualifiers: const
Returns the last visible wrap index of the last visible line.
int get_last_full_visible_line_wrap_index
get_last_unhidden_line
Qualifiers: const
Returns the last unhidden line in the entire TextEdit.
int get_last_unhidden_line
get_line(int)
Qualifiers: const
Returns the text of a specific line.
String get_line(int line)
Parameters
line
int
get_line_background_color(int)
Qualifiers: const
Returns the custom background color of the given line. If no color is set, returns Color(0, 0, 0, 0)
.
Color get_line_background_color(int line)
Parameters
line
int
get_line_column_at_pos(Vector2i, bool, bool)
Qualifiers: const
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.
Vector2i get_line_column_at_pos(Vector2i position, bool clamp_line, bool clamp_column)
Parameters
get_line_count
Qualifiers: const
Returns the number of lines in the text.
int get_line_count
get_line_gutter_icon(int, int)
Qualifiers: const
Returns the icon currently in gutter
at line
. This only works when the gutter type is TextEdit.GUTTER_TYPE_ICON (see TextEdit.set_gutter_type).
Texture2D get_line_gutter_icon(int line, int gutter)
Parameters
get_line_gutter_item_color(int, int)
Qualifiers: const
Returns the color currently in gutter
at line
.
Color get_line_gutter_item_color(int line, int gutter)
Parameters
get_line_gutter_metadata(int, int)
Qualifiers: const
Returns the metadata currently in gutter
at line
.
Variant get_line_gutter_metadata(int line, int gutter)
Parameters
get_line_gutter_text(int, int)
Qualifiers: const
Returns the text currently in gutter
at line
. This only works when the gutter type is TextEdit.GUTTER_TYPE_STRING (see TextEdit.set_gutter_type).
String get_line_gutter_text(int line, int gutter)
Parameters
get_line_height
Qualifiers: const
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
.
int get_line_height
get_line_ranges_from_carets(bool, bool)
Qualifiers: const
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 (TextEdit.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.
Vector2i[] get_line_ranges_from_carets(bool only_selections, bool merge_adjacent)
Parameters
get_line_width(int, int)
Qualifiers: const
Returns the width in pixels of the wrap_index
on line
.
int get_line_width(int line, int wrap_index)
Parameters
get_line_with_ime(int)
Qualifiers: const
Returns line text as it is currently displayed, including IME composition string.
String get_line_with_ime(int line)
Parameters
line
int
get_line_wrap_count(int)
Qualifiers: const
Returns the number of times the given line is wrapped.
int get_line_wrap_count(int line)
Parameters
line
int
get_line_wrap_index_at_column(int, int)
Qualifiers: const
Returns the wrap index of the given column on the given line. This ranges from 0
to TextEdit.get_line_wrap_count.
int get_line_wrap_index_at_column(int line, int column)
Parameters
get_line_wrapped_text(int)
Qualifiers: const
Returns an array of Strings representing each wrapped index.
PackedStringArray get_line_wrapped_text(int line)
Parameters
line
int
get_local_mouse_pos
Qualifiers: const
Returns the local mouse position adjusted for the text direction.
Vector2 get_local_mouse_pos
get_menu
Qualifiers: const
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 MenuItems). For example:
func _ready():
var menu = get_menu()
# Remove all items after "Redo".
menu.item_count = menu.get_item_index(MENU_REDO) + 1
# Add custom items.
menu.add_separator()
menu.add_item("Insert Date", MENU_MAX + 1)
# Connect callback.
menu.id_pressed.connect(_on_item_pressed)
func _on_item_pressed(id):
if id == MENU_MAX + 1:
insert_text_at_caret(Time.get_date_string_from_system())
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.
PopupMenu get_menu
get_minimap_line_at_pos(Vector2i)
Qualifiers: const
Returns the equivalent minimap line at position
.
int get_minimap_line_at_pos(Vector2i position)
Parameters
position
Vector2i
get_minimap_visible_lines
Qualifiers: const
Returns the number of lines that may be drawn on the minimap.
int get_minimap_visible_lines
get_next_visible_line_index_offset_from(int, int, int)
Qualifiers: const
Similar to TextEdit.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.
Vector2i get_next_visible_line_index_offset_from(int line, int wrap_index, int visible_amount)
Parameters
get_next_visible_line_offset_from(int, int)
Qualifiers: const
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.
int get_next_visible_line_offset_from(int line, int visible_amount)
Parameters
get_pos_at_line_column(int, int)
Qualifiers: const
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 TextEdit.get_rect_at_line_column to get the top side position.
Vector2i get_pos_at_line_column(int line, int column)
Parameters
get_rect_at_line_column(int, int)
Qualifiers: const
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 TextEdit.get_pos_at_line_column which returns the bottom side.
Rect2i get_rect_at_line_column(int line, int column)
Parameters
get_saved_version
Qualifiers: const
Returns the last tagged saved version from tag_saved_version.
int get_saved_version
get_scroll_pos_for_line(int, int)
Qualifiers: const
Returns the scroll position for wrap_index
of line
.
float get_scroll_pos_for_line(int line, int wrap_index)
Parameters
get_selected_text(int)
Returns the text inside the selection of a caret, or all the carets if caret_index
is its default value -1
.
String get_selected_text(int caret_index)
Parameters
caret_index
int
get_selection_at_line_column(int, int, bool, bool)
Qualifiers: const
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.
int get_selection_at_line_column(int line, int column, bool include_edges, bool only_selections)
Parameters
get_selection_column(int)
Qualifiers: const
Returns the original start column of the selection.
int get_selection_column(int caret_index)
Parameters
caret_index
int
get_selection_from_column(int)
Qualifiers: const
Returns the selection begin column. Returns the caret column if there is no selection.
int get_selection_from_column(int caret_index)
Parameters
caret_index
int
get_selection_from_line(int)
Qualifiers: const
Returns the selection begin line. Returns the caret line if there is no selection.
int get_selection_from_line(int caret_index)
Parameters
caret_index
int
get_selection_line(int)
Qualifiers: const
Returns the original start line of the selection.
int get_selection_line(int caret_index)
Parameters
caret_index
int
get_selection_mode
Qualifiers: const
Returns the current selection mode.
int get_selection_mode
get_selection_origin_column(int)
Qualifiers: const
Returns the origin column of the selection. This is the opposite end from the caret.
int get_selection_origin_column(int caret_index)
Parameters
caret_index
int
get_selection_origin_line(int)
Qualifiers: const
Returns the origin line of the selection. This is the opposite end from the caret.
int get_selection_origin_line(int caret_index)
Parameters
caret_index
int
get_selection_to_column(int)
Qualifiers: const
Returns the selection end column. Returns the caret column if there is no selection.
int get_selection_to_column(int caret_index)
Parameters
caret_index
int
get_selection_to_line(int)
Qualifiers: const
Returns the selection end line. Returns the caret line if there is no selection.
int get_selection_to_line(int caret_index)
Parameters
caret_index
int
get_sorted_carets(bool)
Qualifiers: const
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 TextEdit.multicaret_edit_ignore_caret will be ignored.
PackedInt32Array get_sorted_carets(bool include_ignored_carets)
Parameters
include_ignored_carets
bool
get_tab_size
Qualifiers: const
Returns the TextEdit's' tab size.
int get_tab_size
get_total_gutter_width
Qualifiers: const
Returns the total width of all gutters and internal padding.
int get_total_gutter_width
get_total_visible_line_count
Qualifiers: const
Returns the total number of lines in the text. This includes wrapped lines and excludes folded lines. If wrap_mode is set to TextEdit.LINE_WRAPPING_NONE and no lines are folded (see CodeEdit.is_line_folded) then this is equivalent to get_line_count. See TextEdit.get_visible_line_count_in_range for a limited range of lines.
int get_total_visible_line_count
get_v_scroll_bar
Qualifiers: const
Returns the VScrollBar of the TextEdit.
VScrollBar get_v_scroll_bar
get_version
Qualifiers: const
Returns the current version of the TextEdit. The version is a count of recorded operations by the undo/redo history.
int get_version
get_visible_line_count
Qualifiers: const
Returns the number of lines that can visually fit, rounded down, based on this control's height.
int get_visible_line_count
get_visible_line_count_in_range(int, int)
Qualifiers: const
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.
int get_visible_line_count_in_range(int from_line, int to_line)
Parameters
get_word_at_pos(Vector2)
Qualifiers: const
Returns the word at position
.
String get_word_at_pos(Vector2 position)
Parameters
position
Vector2
get_word_under_caret(int)
Qualifiers: const
Returns a String text with the word under the caret's location.
String get_word_under_caret(int caret_index)
Parameters
caret_index
int
has_ime_text
Qualifiers: const
Returns true
if the user has text in the Input Method Editor (IME).
bool has_ime_text
has_redo
Qualifiers: const
Returns true
if a "redo" action is available.
bool has_redo
has_selection(int)
Qualifiers: const
Returns true
if the user has selected text.
bool has_selection(int caret_index)
Parameters
caret_index
int
has_undo
Qualifiers: const
Returns true
if an "undo" action is available.
bool has_undo
insert_line_at(int, String)
Inserts a new line with text
at line
.
void insert_line_at(int line, String text)
Parameters
insert_text(String, int, int, bool, bool)
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.
void insert_text(String text, int line, int column, bool before_selection_begin, bool before_selection_end)
Parameters
insert_text_at_caret(String, int)
Insert the specified text at the caret position.
void insert_text_at_caret(String text, int caret_index)
Parameters
is_caret_after_selection_origin(int)
Qualifiers: const
Returns true
if the caret of the selection is after the selection origin. This can be used to determine the direction of the selection.
bool is_caret_after_selection_origin(int caret_index)
Parameters
caret_index
int
is_caret_visible(int)
Qualifiers: const
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: TextEdit.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.
bool is_caret_visible(int caret_index)
Parameters
caret_index
int
is_dragging_cursor
Qualifiers: const
Returns true
if the user is dragging their mouse for scrolling, selecting, or text dragging.
bool is_dragging_cursor
is_gutter_clickable(int)
Qualifiers: const
Returns true
if the gutter at the given index is clickable. See TextEdit.set_gutter_clickable.
bool is_gutter_clickable(int gutter)
Parameters
gutter
int
is_gutter_drawn(int)
Qualifiers: const
Returns true
if the gutter at the given index is currently drawn. See TextEdit.set_gutter_draw.
bool is_gutter_drawn(int gutter)
Parameters
gutter
int
is_gutter_overwritable(int)
Qualifiers: const
Returns true
if the gutter at the given index is overwritable. See TextEdit.set_gutter_overwritable.
bool is_gutter_overwritable(int gutter)
Parameters
gutter
int
is_in_mulitcaret_edit
Qualifiers: const
Returns true
if a begin_multicaret_edit has been called and end_multicaret_edit has not yet been called.
bool is_in_mulitcaret_edit
is_line_gutter_clickable(int, int)
Qualifiers: const
Returns true
if the gutter at the given index on the given line is clickable. See TextEdit.set_line_gutter_clickable.
bool is_line_gutter_clickable(int line, int gutter)
Parameters
is_line_wrapped(int)
Qualifiers: const
Returns if the given line is wrapped.
bool is_line_wrapped(int line)
Parameters
line
int
is_menu_visible
Qualifiers: const
Returns true
if the menu is visible. Use this instead of get_menu().visible
to improve performance (so the creation of the menu is avoided). See get_menu.
bool is_menu_visible
is_mouse_over_selection(bool, int)
Qualifiers: const
Returns true
if the mouse is over a selection. If edges
is true
, the edges are considered part of the selection.
bool is_mouse_over_selection(bool edges, int caret_index)
Parameters
is_overtype_mode_enabled
Qualifiers: const
Returns true
if overtype mode is enabled. See TextEdit.set_overtype_mode_enabled.
bool is_overtype_mode_enabled
menu_option(int)
Executes a given action as defined in the MenuItems enum.
void menu_option(int option)
Parameters
option
int
merge_gutters(int, int)
Merge the gutters from from_line
into to_line
. Only overwritable gutters will be copied. See TextEdit.set_gutter_overwritable.
void merge_gutters(int from_line, int to_line)
Parameters
merge_overlapping_carets
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.
void merge_overlapping_carets
multicaret_edit_ignore_caret(int)
Qualifiers: const
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.
bool multicaret_edit_ignore_caret(int caret_index)
Parameters
caret_index
int
paste(int)
Paste at the current location. Can be overridden with TextEdit._paste.
void paste(int caret_index)
Parameters
caret_index
int
paste_primary_clipboard(int)
Pastes the primary clipboard.
void paste_primary_clipboard(int caret_index)
Parameters
caret_index
int
redo
Perform redo operation.
void redo
remove_caret(int)
Removes the given caret index.
Note: This can result in adjustment of all other caret indices.
void remove_caret(int caret)
Parameters
caret
int
remove_gutter(int)
Removes the gutter at the given index.
void remove_gutter(int gutter)
Parameters
gutter
int
remove_line_at(int, bool)
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.
void remove_line_at(int line, bool move_carets_down)
Parameters
remove_secondary_carets
Removes all additional carets.
void remove_secondary_carets
remove_text(int, int, int, int)
Removes text between the given positions.
void remove_text(int from_line, int from_column, int to_line, int to_column)
Parameters
search(String, int, int, int)
Qualifiers: const
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
.
Vector2i search(String text, int flags, int from_line, int from_column)
Parameters
select(int, int, int, int, int)
Selects 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.
void select(int origin_line, int origin_column, int caret_line, int caret_column, int caret_index)
Parameters
select_all
Select all the text.
If selecting_enabled is false
, no selection will occur.
void select_all
select_word_under_caret(int)
Selects the word under the caret.
void select_word_under_caret(int caret_index)
Parameters
caret_index
int
set_caret_column(int, bool, int)
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.
void set_caret_column(int column, bool adjust_viewport, int caret_index)
Parameters
set_caret_line(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 TextEdit.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 TextEdit.set_caret_column was called.
Note: If supporting multiple carets this will not check for any overlap. See merge_overlapping_carets.
void set_caret_line(int line, bool adjust_viewport, bool can_be_hidden, int wrap_index, int caret_index)
Parameters
set_gutter_clickable(int, bool)
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 TextEdit.is_gutter_clickable and TextEdit.set_line_gutter_clickable.
void set_gutter_clickable(int gutter, bool clickable)
Parameters
set_gutter_custom_draw(int, Callable)
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 TextEdit.GUTTER_TYPE_CUSTOM (see TextEdit.set_gutter_type).
void set_gutter_custom_draw(int column, Callable draw_callback)
Parameters
set_gutter_draw(int, bool)
If true
, the gutter at the given index is drawn. The gutter type (TextEdit.set_gutter_type) determines how it is drawn. See TextEdit.is_gutter_drawn.
void set_gutter_draw(int gutter, bool draw)
Parameters
set_gutter_name(int, String)
Sets the name of the gutter at the given index.
void set_gutter_name(int gutter, String name)
Parameters
set_gutter_overwritable(int, bool)
If true
, the line data of the gutter at the given index can be overridden when using TextEdit.merge_gutters. See TextEdit.is_gutter_overwritable.
void set_gutter_overwritable(int gutter, bool overwritable)
Parameters
set_gutter_type(int, int)
Sets the type of gutter at the given index. Gutters can contain icons, text, or custom visuals. See GutterType for options.
void set_gutter_type(int gutter, int type)
Parameters
set_gutter_width(int, int)
Set the width of the gutter at the given index.
void set_gutter_width(int gutter, int width)
Parameters
set_line(int, String)
Sets the text for a specific line
.
Carets on the line will attempt to keep their visual x position.
void set_line(int line, String new_text)
Parameters
set_line_as_center_visible(int, int)
Positions the wrap_index
of line
at the center of the viewport.
void set_line_as_center_visible(int line, int wrap_index)
Parameters
set_line_as_first_visible(int, int)
Positions the wrap_index
of line
at the top of the viewport.
void set_line_as_first_visible(int line, int wrap_index)
Parameters
set_line_as_last_visible(int, int)
Positions the wrap_index
of line
at the bottom of the viewport.
void set_line_as_last_visible(int line, int wrap_index)
Parameters
set_line_background_color(int, Color)
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.
void set_line_background_color(int line, Color color)
Parameters
set_line_gutter_clickable(int, int, bool)
If clickable
is true
, makes the gutter
on the given line
clickable. This is like TextEdit.set_gutter_clickable, but for a single line. If TextEdit.is_gutter_clickable is true
, this will not have any effect. See TextEdit.is_line_gutter_clickable and TextEdit.gutter_clicked.
void set_line_gutter_clickable(int line, int gutter, bool clickable)
Parameters
set_line_gutter_icon(int, int, Texture2D)
Sets the icon for gutter
on line
to icon
. This only works when the gutter type is TextEdit.GUTTER_TYPE_ICON (see TextEdit.set_gutter_type).
void set_line_gutter_icon(int line, int gutter, Texture2D icon)
Parameters
set_line_gutter_item_color(int, int, Color)
Sets the color for gutter
on line
to color
.
void set_line_gutter_item_color(int line, int gutter, Color color)
Parameters
set_line_gutter_metadata(int, int, Variant)
Sets the metadata for gutter
on line
to metadata
.
void set_line_gutter_metadata(int line, int gutter, Variant metadata)
Parameters
set_line_gutter_text(int, int, String)
Sets the text for gutter
on line
to text
. This only works when the gutter type is TextEdit.GUTTER_TYPE_STRING (see TextEdit.set_gutter_type).
void set_line_gutter_text(int line, int gutter, String text)
Parameters
set_overtype_mode_enabled(bool)
If true
, enables overtype mode. In this mode, typing overrides existing text instead of inserting text. The input/ui_text_toggle_insert_mode action toggles overtype mode. See is_overtype_mode_enabled.
void set_overtype_mode_enabled(bool enabled)
Parameters
enabled
bool
set_search_flags(int)
Sets the search flags
. This is used with TextEdit.set_search_text to highlight occurrences of the searched text. Search flags can be specified from the SearchFlags enum.
void set_search_flags(int flags)
Parameters
flags
int
set_search_text(String)
Sets the search text. See TextEdit.set_search_flags.
void set_search_text(String search_text)
Parameters
search_text
String
set_selection_mode(int)
Sets the current selection mode.
void set_selection_mode(int mode)
Parameters
mode
int
set_selection_origin_column(int, int)
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.
void set_selection_origin_column(int column, int caret_index)
Parameters
set_selection_origin_line(int, bool, int, int)
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 TextEdit.set_selection_origin_column or TextEdit.select was called.
void set_selection_origin_line(int line, bool can_be_hidden, int wrap_index, int caret_index)
Parameters
set_tab_size(int)
Sets the tab size for the TextEdit to use.
void set_tab_size(int size)
Parameters
size
int
set_tooltip_request_func(Callable)
Provide custom tooltip text. The callback method must take the following args: hovered_word: String
.
void set_tooltip_request_func(Callable callback)
Parameters
callback
Callable
skip_selection_for_next_occurrence
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.
void skip_selection_for_next_occurrence
start_action(int)
Starts an action, will end the current action if action
is different.
An action will also end after a call to end_action, after gui/timers/text_edit_idle_detect_sec is triggered or a new undoable step outside the TextEdit.start_action and end_action calls.
void start_action(int action)
Parameters
action
int
swap_lines(int, int)
Swaps the two lines. Carets will be swapped with the lines.
void swap_lines(int from_line, int to_line)
Parameters
tag_saved_version
Tag the current version as saved.
void tag_saved_version
undo
Perform undo operation.
void undo
Events
caret_changed
Emitted when any caret changes position.
signal caret_changed
gutter_added
Emitted when a gutter is added.
signal gutter_added
gutter_clicked(int, int)
Emitted when a gutter is clicked.
signal gutter_clicked(int line, int gutter)
Parameters
gutter_removed
Emitted when a gutter is removed.
signal gutter_removed
lines_edited_from(int, int)
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
.
signal lines_edited_from(int from_line, int to_line)
Parameters
text_changed
Emitted when the text changes.
signal text_changed
text_set
signal text_set