Work in progress
Godot documentation is being updated to reflect the latest changes in version
4.0
. Some documentation pages may
still state outdated information. This banner will tell you if you're reading one of such pages.
The contents of this page are up to date. If you can still find outdated information, please open an issue.
CodeEdit¶
Inherits: TextEdit < Control < CanvasItem < Node < Object
Multiline text control intended for editing code.
Description¶
CodeEdit is a specialized TextEdit designed for editing plain text code files. It contains a bunch of features commonly found in code editors such as line numbers, line folding, code completion, indent management and string / comment management.
Note: By default CodeEdit always use left-to-right text direction to correctly display source code.
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
layout_direction |
|
|
|
||
|
||
|
||
text_direction |
|
Methods¶
Theme Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Signals¶
breakpoint_toggled ( int line )
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.
symbol_lookup ( String symbol, int line, int column )
Emitted when the user has clicked on a valid symbol.
symbol_validate ( String symbol )
Emitted when the user hovers over a symbol. The symbol should be validated and responded to, by calling set_symbol_lookup_word_as_valid.
Enumerations¶
enum CodeCompletionKind:
CodeCompletionKind KIND_CLASS = 0
Marks the option as a class.
CodeCompletionKind KIND_FUNCTION = 1
Marks the option as a function.
CodeCompletionKind KIND_SIGNAL = 2
Marks the option as a Godot signal.
CodeCompletionKind KIND_VARIABLE = 3
Marks the option as a variable.
CodeCompletionKind KIND_MEMBER = 4
Marks the option as a member.
CodeCompletionKind KIND_ENUM = 5
Marks the option as a enum entry.
CodeCompletionKind KIND_CONSTANT = 6
Marks the option as a constant.
CodeCompletionKind KIND_NODE_PATH = 7
Marks the option as a Godot node path.
CodeCompletionKind KIND_FILE_PATH = 8
Marks the option as a file path.
CodeCompletionKind KIND_PLAIN_TEXT = 9
Marks the option as unclassified or plain text.
Property Descriptions¶
bool auto_brace_completion_enabled = false
Sets whether brace pairs should be autocompleted.
bool auto_brace_completion_highlight_matching = false
void set_highlight_matching_braces_enabled ( bool value )
bool is_highlight_matching_braces_enabled ( )
Highlight mismatching brace pairs.
Dictionary auto_brace_completion_pairs = { "\"": "\"", "'": "'", "(": ")", "[": "]", "{": "}" }
void set_auto_brace_completion_pairs ( Dictionary value )
Dictionary get_auto_brace_completion_pairs ( )
Sets the brace pairs to be autocompleted.
bool code_completion_enabled = false
Sets whether code completion is allowed.
String[] code_completion_prefixes = []
Sets prefixes that will trigger code completion.
String[] delimiter_comments = []
Sets the comment delimiters. All existing comment delimiters will be removed.
String[] delimiter_strings = ["' '", "\" \""]
Sets the string delimiters. All existing string delimiters will be removed.
bool gutters_draw_bookmarks = false
Sets if bookmarked should be drawn in the gutter. This gutter is shared with breakpoints and executing lines.
bool gutters_draw_breakpoints_gutter = false
Sets if breakpoints should be drawn in the gutter. This gutter is shared with bookmarks and executing lines.
bool gutters_draw_executing_lines = false
Sets if executing lines should be marked in the gutter. This gutter is shared with breakpoints and bookmarks lines.
bool gutters_draw_fold_gutter = false
Sets if foldable lines icons should be drawn in the gutter.
bool gutters_draw_line_numbers = false
Sets if line numbers should be drawn in the gutter.
bool gutters_zero_pad_line_numbers = false
Sets if line numbers drawn in the gutter are zero padded.
bool indent_automatic = false
Sets whether automatic indent are enabled, this will add an extra indent if a prefix or brace is found.
String[] indent_automatic_prefixes = [":", "{", "[", "("]
Prefixes to trigger an automatic indent.
int indent_size = 4
Size of tabs, if indent_use_spaces
is enabled the number of spaces to use.
bool indent_use_spaces = false
Use spaces instead of tabs for indentation.
bool line_folding = false
Sets whether line folding is allowed.
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.
bool symbol_lookup_on_click = false
Set when a validated word from symbol_validate is clicked, the symbol_lookup should be emitted.
Method Descriptions¶
void _confirm_code_completion ( bool replace ) virtual
Override this method to define how the selected entry should be inserted. If replace
is true, any existing text should be replaced.
Dictionary[] _filter_code_completion_candidates ( Dictionary[] candidates ) virtual const
Override this method to define what items in candidates
should be displayed.
Both candidates
and the return is a Array of Dictionary, see get_code_completion_option for Dictionary content.
void _request_code_completion ( bool force ) virtual
Override this method to define what happens when the user requests code completion. If force
is true, any checks should be bypassed.
void add_auto_brace_completion_pair ( String start_key, String end_key )
Adds a brace pair.
Both the start and end keys must be symbols. Only the start key has to be unique.
void add_code_completion_option ( CodeCompletionKind type, String display_text, String insert_text, Color text_color=Color(1, 1, 1, 1), Resource icon=null, Variant value=0 )
Submits an item to the queue of potential candidates for the autocomplete menu. Call update_code_completion_options to update the list.
Note: This list will replace all current candidates.
void add_comment_delimiter ( String start_key, String end_key, bool line_only=false )
Adds a comment delimiter.
Both the start and end keys must be symbols. Only the start key has to be unique.
line_only
denotes if the region should continue until the end of the line or carry over on to the next line. If the end key is blank this is automatically set to true
.
void add_string_delimiter ( String start_key, String end_key, bool line_only=false )
Adds a string delimiter.
Both the start and end keys must be symbols. Only the start key has to be unique.
line_only
denotes if the region should continue until the end of the line or carry over on to the next line. If the end key is blank this is automatically set to true
.
bool can_fold_line ( int line ) const
Returns if the given line is foldable, that is, it has indented lines right below it or a comment / string block.
void cancel_code_completion ( )
Cancels the autocomplete menu.
void clear_bookmarked_lines ( )
Clears all bookmarked lines.
void clear_breakpointed_lines ( )
Clears all breakpointed lines.
void clear_comment_delimiters ( )
Removes all comment delimiters.
void clear_executing_lines ( )
Clears all executed lines.
void clear_string_delimiters ( )
Removes all string delimiters.
void confirm_code_completion ( bool replace=false )
Inserts the selected entry into the text. If replace
is true, any existing text is replaced rather then merged.
void do_indent ( )
Perform an indent as if the user activated the "ui_text_indent" action.
void fold_all_lines ( )
Folds all lines that are possible to be folded (see can_fold_line).
void fold_line ( int line )
Folds the given line, if possible (see can_fold_line).
String get_auto_brace_completion_close_key ( String open_key ) const
Gets the matching auto brace close key for open_key
.
PackedInt32Array get_bookmarked_lines ( ) const
Gets all bookmarked lines.
PackedInt32Array get_breakpointed_lines ( ) const
Gets all breakpointed lines.
Dictionary get_code_completion_option ( int index ) const
Gets the completion option at index
. The return Dictionary 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.
Dictionary[] get_code_completion_options ( ) const
Gets all completion options, see get_code_completion_option for return content.
int get_code_completion_selected_index ( ) const
Gets the index of the current selected completion option.
String get_delimiter_end_key (