CodeEdit
Inherits:TextEdit<Control<CanvasItem<Node<Object
A multiline text editor designed for editing code.
Description
CodeEdit is a specializedTextEdit designed for editing plain text code files. It has many features commonly found in code editors such as line numbers, line folding, code completion, indent management, and string/comment management.
Note: Regardless of locale,CodeEdit will by default always use left-to-right text direction to correctly display source code.
Properties
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
layout_direction |
| |
| ||
| ||
| ||
| ||
text_direction |
|
Methods
Theme Properties
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
Signals
Emitted when a breakpoint is added or removed from a line. If the line is moved via backspace a removed is emitted at the old line.
code_completion_requested()🔗
Emitted when the user requests code completion. This signal will not be sent if_request_code_completion() is overridden orcode_completion_enabled isfalse
.
symbol_hovered(symbol:String, line:int, column:int)🔗
Emitted when the user hovers over a symbol. UnlikeControl.mouse_entered, this signal is not emitted immediately, but when the cursor is over the symbol forProjectSettings.gui/timers/tooltip_delay_sec seconds.
Note:symbol_tooltip_on_hover must betrue
for this signal to be emitted.
symbol_lookup(symbol:String, line:int, column:int)🔗
Emitted when the user has clicked on a valid symbol.
symbol_validate(symbol:String)🔗
Emitted when the user hovers over a symbol. The symbol should be validated and responded to, by callingset_symbol_lookup_word_as_valid().
Note:symbol_lookup_on_click must betrue
for this signal to be emitted.
Enumerations
enumCodeCompletionKind:🔗
CodeCompletionKindKIND_CLASS =0
Marks the option as a class.
CodeCompletionKindKIND_FUNCTION =1
Marks the option as a function.
CodeCompletionKindKIND_SIGNAL =2
Marks the option as a Godot signal.
CodeCompletionKindKIND_VARIABLE =3
Marks the option as a variable.
CodeCompletionKindKIND_MEMBER =4
Marks the option as a member.
CodeCompletionKindKIND_ENUM =5
Marks the option as an enum entry.
CodeCompletionKindKIND_CONSTANT =6
Marks the option as a constant.
CodeCompletionKindKIND_NODE_PATH =7
Marks the option as a Godot node path.
CodeCompletionKindKIND_FILE_PATH =8
Marks the option as a file path.
CodeCompletionKindKIND_PLAIN_TEXT =9
Marks the option as unclassified or plain text.
enumCodeCompletionLocation:🔗
CodeCompletionLocationLOCATION_LOCAL =0
The option is local to the location of the code completion query - e.g. a local variable. Subsequent value of location represent options from the outer class, the exact value represent how far they are (in terms of inner classes).
CodeCompletionLocationLOCATION_PARENT_MASK =256
The option is from the containing class or a parent class, relative to the location of the code completion query. Perform a bitwise OR with the class depth (e.g.0
for the local class,1
for the parent,2
for the grandparent, etc.) to store the depth of an option in the class or a parent class.
CodeCompletionLocationLOCATION_OTHER_USER_CODE =512
The option is from user code which is not local and not in a derived class (e.g. Autoload Singletons).
CodeCompletionLocationLOCATION_OTHER =1024
The option is from other engine code, not covered by the other enum constants - e.g. built-in classes.
Property Descriptions
boolauto_brace_completion_enabled =false
🔗
boolis_auto_brace_completion_enabled()
Iftrue
, usesauto_brace_completion_pairs to automatically insert the closing brace when the opening brace is inserted by typing or autocompletion. Also automatically removes the closing brace when using backspace on the opening brace.
boolauto_brace_completion_highlight_matching =false
🔗
boolis_highlight_matching_braces_enabled()
Iftrue
, highlights brace pairs when the caret is on either one, usingauto_brace_completion_pairs. If matching, the pairs will be underlined. If a brace is unmatched, it is colored withbrace_mismatch_color.
Dictionaryauto_brace_completion_pairs ={"\"":"\"","'":"'","(":")","[":"]","{":"}"}
🔗
Dictionaryget_auto_brace_completion_pairs()
Sets the brace pairs to be autocompleted. For each entry in the dictionary, the key is the opening brace and the value is the closing brace that matches it. A brace is aString made of symbols. Seeauto_brace_completion_enabled andauto_brace_completion_highlight_matching.
boolcode_completion_enabled =false
🔗
boolis_code_completion_enabled()
Iftrue
, theProjectSettings.input/ui_text_completion_query action requests code completion. To handle it, see_request_code_completion() orcode_completion_requested.
Array[String]code_completion_prefixes =[]
🔗
Sets prefixes that will trigger code completion.
Array[String]delimiter_comments =[]
🔗
Sets the comment delimiters. All existing comment delimiters will be removed.
Array[String]delimiter_strings =["''","\"\""]
🔗
Sets the string delimiters. All existing string delimiters will be removed.
boolgutters_draw_bookmarks =false
🔗
boolis_drawing_bookmarks_gutter()
Iftrue
, bookmarks are drawn in the gutter. This gutter is shared with breakpoints and executing lines. Seeset_line_as_bookmarked().
boolgutters_draw_breakpoints_gutter =false
🔗
boolis_drawing_breakpoints_gutter()
Iftrue
, breakpoints are drawn in the gutter. This gutter is shared with bookmarks and executing lines. Clicking the gutter will toggle the breakpoint for the line, seeset_line_as_breakpoint().
boolgutters_draw_executing_lines =false
🔗
boolis_drawing_executing_lines_gutter()
Iftrue
, executing lines are marked in the gutter. This gutter is shared with breakpoints and bookmarks. Seeset_line_as_executing().
boolgutters_draw_fold_gutter =false
🔗
boolis_drawing_fold_gutter()
Iftrue
, the fold gutter is drawn. In this gutter, thecan_fold_code_region icon is drawn for each foldable line (seecan_fold_line()) and thefolded_code_region icon is drawn for each folded line (seeis_line_folded()). These icons can be clicked to toggle the fold state, seetoggle_foldable_line().line_folding must betrue
to show icons.
boolgutters_draw_line_numbers =false
🔗
boolis_draw_line_numbers_enabled()
Iftrue
, the line number gutter is drawn. Line numbers start at1
and are incremented for each line of text. Clicking and dragging in the line number gutter will select entire lines of text.
boolgutters_zero_pad_line_numbers =false
🔗
boolis_line_numbers_zero_padded()
Iftrue
, line numbers drawn in the gutter are zero padded based on the total line count. Requiresgutters_draw_line_numbers to be set totrue
.
boolis_auto_indent_enabled()
Iftrue
, an extra indent is automatically inserted when a new line is added and a prefix inindent_automatic_prefixes is found. If a brace pair opening key is found, the matching closing brace will be moved to another new line (seeauto_brace_completion_pairs).
Array[String]indent_automatic_prefixes =[":","{","[","("]
🔗
Prefixes to trigger an automatic indent. Used whenindent_automatic is set totrue
.
intget_indent_size()
Size of the tabulation indent (oneTab press) in characters. Ifindent_use_spaces is enabled the number of spaces to use.
boolis_indent_using_spaces()
Use spaces instead of tabs for indentation.
boolis_line_folding_enabled()
Iftrue
, lines can be folded. Otherwise, line folding methods likefold_line() will not work andcan_fold_line() will always returnfalse
. Seegutters_draw_fold_gutter.
Array[int]line_length_guidelines =[]
🔗
Draws vertical lines at the provided columns. The first entry is considered a main hard guideline and is draw more prominently.
boolsymbol_lookup_on_click =false
🔗
boolis_symbol_lookup_on_click_enabled()
Set when a validated word fromsymbol_validate is clicked, thesymbol_lookup should be emitted.
boolsymbol_tooltip_on_hover =false
🔗
boolis_symbol_tooltip_on_hover_enabled()
Set when a word is hovered, thesymbol_hovered should be emitted.
Method Descriptions
void_confirm_code_completion(replace:bool)virtual🔗
Override this method to define how the selected entry should be inserted. Ifreplace
istrue
, any existing text should be replaced.
Array[Dictionary]_filter_code_completion_candidates(candidates:Array[Dictionary])virtualconst🔗
Override this method to define what items incandidates
should be displayed.
Bothcandidates
and the return is aArray ofDictionary, seeget_code_completion_option() forDictionary content.
void_request_code_completion(force:bool)virtual🔗
Override this method to define what happens when the user requests code completion. Ifforce
istrue
, any checks should be bypassed.
voidadd_auto_brace_completion_pair(start_key:String, end_key:String)🔗
Adds a brace pair.
Both the start and end keys must be symbols. Only the start key has to be unique.
voidadd_code_completion_option(type:CodeCompletionKind, display_text:String, insert_text:String, text_color:Color = Color(1, 1, 1, 1), icon:Resource = null, value:Variant = null, location:int = 1024)🔗
Submits an item to the queue of potential candidates for the autocomplete menu. Callupdate_code_completion_options() to update the list.
location
indicates location of the option relative to the location of the code completion query. SeeCodeCompletionLocation for how to set this value.
Note: This list will replace all current candidates.
voidadd_comment_delimiter(start_key:String, end_key:String, line_only:bool = false)🔗
Adds a comment delimiter fromstart_key
toend_key
. Both keys should be symbols, andstart_key
must not be shared with other delimiters.
Ifline_only
istrue
orend_key
is an emptyString, the region does not carry over to the next line.
voidadd_string_delimiter(start_key:String, end_key:String, line_only:bool = false)🔗
Defines a string delimiter fromstart_key
toend_key
. Both keys should be symbols, andstart_key
must not be shared with other delimiters.
Ifline_only
istrue
orend_key
is an emptyString, the region does not carry over to the next line.
boolcan_fold_line(line:int)const🔗
Returnstrue
if the given line is foldable. A line is foldable if it is the start of a valid code region (seeget_code_region_start_tag()), if it is the start of a comment or string block, or if the next non-empty line is more indented (seeTextEdit.get_indent_level()).
Cancels the autocomplete menu.
Clears all bookmarked lines.
voidclear_breakpointed_lines()🔗
Clears all breakpointed lines.
voidclear_comment_delimiters()🔗
Removes all comment delimiters.
Clears all executed lines.
voidclear_string_delimiters()🔗
Removes all string delimiters.
voidconfirm_code_completion(replace:bool = false)🔗
Inserts the selected entry into the text. Ifreplace
istrue
, any existing text is replaced rather than merged.
voidconvert_indent(from_line:int = -1, to_line:int = -1)🔗
Converts the indents of lines betweenfrom_line
andto_line
to tabs or spaces as set byindent_use_spaces.
Values of-1
convert the entire text.
Creates a new code region with the selection. At least one single line comment delimiter have to be defined (seeadd_comment_delimiter()).
A code region is a part of code that is highlighted when folded and can help organize your script.
Code region start and end tags can be customized (seeset_code_region_tags()).
Code regions are delimited using start and end tags (respectivelyregion
andendregion
by default) preceded by one line comment delimiter. (eg.#region
and#endregion
)
Deletes all lines that are selected or have a caret on them.
If there is no selection, indentation is inserted at the caret. Otherwise, the selected lines are indented likeindent_lines(). Equivalent to theProjectSettings.input/ui_text_indent action. The indentation characters used depend onindent_use_spaces andindent_size.
Duplicates all lines currently selected with any caret. Duplicates the entire line beneath the current one no matter where the caret is within the line.
Duplicates all selected text and duplicates all lines with a caret on them.
Folds all lines that are possible to be folded (seecan_fold_line()).
Folds the given line, if possible (seecan_fold_line()).
Stringget_auto_brace_completion_close_key(open_key:String)const🔗
Gets the matching auto brace close key foropen_key
.
PackedInt32Arrayget_bookmarked_lines()const🔗
Gets all bookmarked lines.
PackedInt32Arrayget_breakpointed_lines()const🔗
Gets all breakpointed lines.
Dictionaryget_code_completion_option(index:int)const🔗
Gets the completion option atindex
. The returnDictionary has the following key-values:
kind
:CodeCompletionKind
display_text
: Text that is shown on the autocomplete menu.
insert_text
: Text that is to be inserted when this item is selected.
font_color
: Color of the text on the autocomplete menu.
icon
: Icon to draw on the autocomplete menu.
default_value
: Value of the symbol.
Array[Dictionary]get_code_completion_options()const🔗
Gets all completion options, seeget_code_completion_option() for return content.
intget_code_completion_selected_index()const🔗
Gets the index of the current selected completion option.
Stringget_code_region_end_tag()const🔗
Returns the code region end tag (without comment delimiter).
Stringget_code_region_start_tag()const🔗
Returns the code region start tag (without comment delimiter).
Stringget_delimiter_end_key(delimiter_index:int)const🔗
Gets the end key for a string or comment region index.
Vector2get_delimiter_end_position(line:int, column:int)const🔗
Ifline
column
is in a string or comment, returns the end position of the region. If not or no end could be found, bothVector2 values will be-1
.
Stringget_delimiter_start_key(delimiter_index:int)const🔗
Gets the start key for a string or comment region index.
Vector2get_delimiter_start_position(line:int, column:int)const🔗
Ifline
column
is in a string or comment, returns the start position of the region. If not or no start could be found, bothVector2 values will be-1
.
PackedInt32Arrayget_executing_lines()const🔗
Gets all executing lines.
Array[int]get_folded_lines()const🔗
Returns all lines that are currently folded.
Stringget_text_for_code_completion()const🔗
Returns the full text with char0xFFFF
at the caret location.
Stringget_text_for_symbol_lookup()const🔗
Returns the full text with char0xFFFF
at the cursor location.
Stringget_text_with_cursor_char(line:int, column:int)const🔗
Returns the full text with char0xFFFF
at the specified location.
boolhas_auto_brace_completion_close_key(close_key:String)const🔗
Returnstrue
if close keyclose_key
exists.
boolhas_auto_brace_completion_open_key(open_key:String)const🔗
Returnstrue
if open keyopen_key
exists.
boolhas_comment_delimiter(start_key:String)const🔗
Returnstrue
if commentstart_key
exists.
boolhas_string_delimiter(start_key:String)const🔗
Returnstrue
if stringstart_key
exists.
Indents all lines that are selected or have a caret on them. Uses spaces or a tab depending onindent_use_spaces. Seeunindent_lines().
intis_in_comment(line:int, column:int = -1)const🔗
Returns delimiter index ifline
column
is in a comment. Ifcolumn
is not provided, will return delimiter index if the entireline
is a comment. Otherwise-1
.
intis_in_string(line:int, column:int = -1)const🔗
Returns the delimiter index ifline
column
is in a string. Ifcolumn
is not provided, will return the delimiter index if the entireline
is a string. Otherwise-1
.
boolis_line_bookmarked(line:int)const🔗
Returnstrue
if the given line is bookmarked. Seeset_line_as_bookmarked().
boolis_line_breakpointed(line:int)const🔗
Returnstrue
if the given line is breakpointed. Seeset_line_as_breakpoint().
boolis_line_code_region_end(line:int)const🔗
Returnstrue
if the given line is a code region end. Seeset_code_region_tags().
boolis_line_code_region_start(line:int)const🔗
Returnstrue
if the given line is a code region start. Seeset_code_region_tags().
boolis_line_executing(line:int)const🔗
Returnstrue
if the given line is marked as executing. Seeset_line_as_executing().
boolis_line_folded(line:int)const🔗
Returnstrue
if the given line is folded. Seefold_line().
Moves all lines down that are selected or have a caret on them.
Moves all lines up that are selected or have a caret on them.
voidremove_comment_delimiter(start_key:String)🔗
Removes the comment delimiter withstart_key
.
voidremove_string_delimiter(start_key:String)🔗
Removes the string delimiter withstart_key
.
voidrequest_code_completion(force:bool = false)🔗
Emitscode_completion_requested, ifforce
istrue
will bypass all checks. Otherwise will check that the caret is in a word or in front of a prefix. Will ignore the request if all current options are of type file path, node path, or signal.
voidset_code_completion_selected_index(index:int)🔗
Sets the current selected completion option.
voidset_code_hint(code_hint:String)🔗
Sets the code hint text. Pass an empty string to clear.
voidset_code_hint_draw_below(draw_below:bool)🔗
Iftrue
, the code hint will draw below the main caret. Iffalse
, the code hint will draw above the main caret. Seeset_code_hint().
voidset_code_region_tags(start:String = "region", end:String = "endregion")🔗
Sets the code region start and end tags (without comment delimiter).
voidset_line_as_bookmarked(line:int, bookmarked:bool)🔗
Sets the given line as bookmarked. Iftrue
andgutters_draw_bookmarks istrue
, draws thebookmark icon in the gutter for this line. Seeget_bookmarked_lines() andis_line_bookmarked().
voidset_line_as_breakpoint(line:int, breakpointed:bool)🔗
Sets the given line as a breakpoint. Iftrue
andgutters_draw_breakpoints_gutter istrue
, draws thebreakpoint icon in the gutter for this line. Seeget_breakpointed_lines() andis_line_breakpointed().
voidset_line_as_executing(line:int, executing:bool)🔗
Sets the given line as executing. Iftrue
andgutters_draw_executing_lines istrue
, draws theexecuting_line icon in the gutter for this line. Seeget_executing_lines() andis_line_executing().
voidset_symbol_lookup_word_as_valid(valid:bool)🔗
Sets the symbol emitted bysymbol_validate as a valid lookup.
voidtoggle_foldable_line(line:int)🔗
Toggle the folding of the code block at the given line.
voidtoggle_foldable_lines_at_carets()🔗
Toggle the folding of the code block on all lines with a caret on them.
Unfolds all lines that are folded.
Unfolds the given line if it is folded or if it is hidden under a folded line.
Unindents all lines that are selected or have a caret on them. Uses spaces or a tab depending onindent_use_spaces. Equivalent to theProjectSettings.input/ui_text_dedent action. Seeindent_lines().
voidupdate_code_completion_options(force:bool)🔗
Submits all completion options added withadd_code_completion_option(). Will try to force the autocomplete menu to popup, ifforce
istrue
.
Note: This will replace all current candidates.
Theme Property Descriptions
Colorbookmark_color =Color(0.5,0.64,1,0.8)
🔗
Color of the bookmark icon for bookmarked lines.
Colorbrace_mismatch_color =Color(1,0.2,0.2,1)
🔗
Color of the text to highlight mismatched braces.
Colorbreakpoint_color =Color(0.9,0.29,0.3,1)
🔗
Color of the breakpoint icon for bookmarked lines.
Colorcode_folding_color =Color(0.8,0.8,0.8,0.8)
🔗
Color for all icons related to line folding.
Colorcompletion_background_color =Color(0.17,0.16,0.2,1)
🔗
Sets the backgroundColor for the code completion popup.
Colorcompletion_existing_color =Color(0.87,0.87,0.87,0.13)
🔗
Background highlightColor for matching text in code completion options.
Colorcompletion_scroll_color =Color(1,1,1,0.29)
🔗
Color of the scrollbar in the code completion popup.
Colorcompletion_scroll_hovered_color =Color(1,1,1,0.4)
🔗
Color of the scrollbar in the code completion popup when hovered.
Colorcompletion_selected_color =Color(0.26,0.26,0.27,1)
🔗
Background highlightColor for the current selected option item in the code completion popup.
Colorexecuting_line_color =Color(0.98,0.89,0.27,1)
🔗
Color of the executing icon for executing lines.
Colorfolded_code_region_color =Color(0.68,0.46,0.77,0.2)
🔗
Color of background line highlight for folded code region.
Colorline_length_guideline_color =Color(0.3,0.5,0.8,0.1)
🔗
Color of the main line length guideline, secondary guidelines will have 50% alpha applied.
Colorline_number_color =Color(0.67,0.67,0.67,0.4)
🔗
Sets theColor of line numbers.
Max number of options to display in the code completion popup at any one time.
Max width of options in the code completion popup. Options longer than this will be cut off.
intcompletion_scroll_width =6
🔗
Width of the scrollbar in the code completion popup.
Sets a customTexture2D to draw in the bookmark gutter for bookmarked lines.
Sets a customTexture2D to draw in the breakpoint gutter for breakpointed lines.
Sets a customTexture2D to draw in the line folding gutter when a line can be folded.
Texture2Dcan_fold_code_region🔗
Sets a customTexture2D to draw in the line folding gutter when a code region can be folded.
Background panel for the color preview box in autocompletion (visible when the color is translucent).
Icon to draw in the executing gutter for executing lines.
Sets a customTexture2D to draw in the line folding gutter when a line is folded and can be unfolded.
Sets a customTexture2D to draw in the line folding gutter when a code region is folded and can be unfolded.
Sets a customTexture2D to draw at the end of a folded line.
StyleBox for the code completion popup.