CodeEdit

Inherits: TextEdit < Control < CanvasItem < Node < Object

Multiline text control intended for editing code.

Description

CodeEdit is a specialised 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.

Methods

void

_confirm_code_completion ( bool replace ) virtual

Array

_filter_code_completion_candidates ( Dictionary[] candidates ) virtual const

void

_request_code_completion ( bool force ) virtual

void

add_auto_brace_completion_pair ( String start_key, String end_key )

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 )

void

add_comment_delimiter ( String start_key, String end_key, bool line_only=false )

void

add_string_delimiter ( String start_key, String end_key, bool line_only=false )

bool

can_fold_line ( int line ) const

void

cancel_code_completion ( )

void

clear_bookmarked_lines ( )

void

clear_breakpointed_lines ( )

void

clear_comment_delimiters ( )

void

clear_executing_lines ( )

void

clear_string_delimiters ( )

void

confirm_code_completion ( bool replace=false )

void

do_indent ( )

void

do_unindent ( )

void

fold_all_lines ( )

void

fold_line ( int line )

String

get_auto_brace_completion_close_key ( String open_key ) const

Array

get_bookmarked_lines ( ) const

Array

get_breakpointed_lines ( ) const

Dictionary

get_code_completion_option ( int index ) const

Dictionary[]

get_code_completion_options ( ) const

int

get_code_completion_selected_index ( ) const

String

get_delimiter_end_key ( int delimiter_index ) const

Vector2

get_delimiter_end_position ( int line, int column ) const

String

get_delimiter_start_key ( int delimiter_index ) const

Vector2

get_delimiter_start_position ( int line, int column ) const

Array

get_executing_lines ( ) const

int[]

get_folded_lines ( ) const

String

get_text_for_code_completion ( ) const

String

get_text_for_symbol_lookup ( )

bool

has_auto_brace_completion_close_key ( String close_key ) const

bool

has_auto_brace_completion_open_key ( String open_key ) const

bool

has_comment_delimiter ( String start_key ) const

bool

has_string_delimiter ( String start_key ) const

void

indent_lines ( )

int

is_in_comment ( int line, int column=-1 ) const

int

is_in_string ( int line, int column=-1 ) const

bool

is_line_bookmarked ( int line ) const

bool

is_line_breakpointed ( int line ) const

bool

is_line_executing ( int line ) const

bool

is_line_folded ( int line ) const

void

remove_comment_delimiter ( String start_key )

void

remove_string_delimiter ( String start_key )

void

request_code_completion ( bool force=false )

void

set_code_completion_selected_index ( int index )

void

set_code_hint ( String code_hint )

void

set_code_hint_draw_below ( bool draw_below )

void

set_line_as_bookmarked ( int line, bool bookmarked )

void

set_line_as_breakpoint ( int line, bool breakpointed )

void

set_line_as_executing ( int line, bool executing )

void

set_symbol_lookup_word_as_valid ( bool valid )

void

toggle_foldable_line ( int line )

void

unfold_all_lines ( )

void

unfold_line ( int line )

void

unindent_lines ( )

void

update_code_completion_options ( bool force )

Theme Properties

Color

background_color

Color(0, 0, 0, 0)

Texture2D

bookmark

Color

bookmark_color

Color(0.5, 0.64, 1, 0.8)

Color

brace_mismatch_color

Color(1, 0.2, 0.2, 1)

Texture2D

breakpoint

Color

breakpoint_color

Color(0.9, 0.29, 0.3, 1)

Texture2D

can_fold

Color

caret_background_color

Color(0, 0, 0, 1)

Color

caret_color

Color(0.88, 0.88, 0.88, 1)

Color

code_folding_color

Color(0.8, 0.8, 0.8, 0.8)

StyleBox

completion

Color

completion_background_color

Color(0.17, 0.16, 0.2, 1)

Color

completion_existing_color

Color(0.87, 0.87, 0.87, 0.13)

Color

completion_font_color

Color(0.67, 0.67, 0.67, 1)

int

completion_lines

7

int

completion_max_width

50

Color

completion_scroll_color

Color(1, 1, 1, 1)

int

completion_scroll_width

3

Color

completion_selected_color

Color(0.26, 0.26, 0.27, 1)

Color

current_line_color

Color(0.25, 0.25, 0.26, 0.8)

Texture2D

executing_line

Color

executing_line_color

Color(0.98, 0.89, 0.27, 1)

StyleBox

focus

Texture2D

folded

Texture2D

folded_eol_icon

Font

font

Color

font_color

Color(0.88, 0.88, 0.88, 1)

Color

font_outline_color

Color(1, 1, 1, 1)

Color

font_readonly_color

Color(0.88, 0.88, 0.88, 0.5)

Color

font_selected_color

Color(0, 0, 0, 1)

int

font_size

Color

line_length_guideline_color

Color(0.3, 0.5, 0.8, 0.1)

Color

line_number_color

Color(0.67, 0.67, 0.67, 0.4)

int

line_spacing

4

StyleBox

normal

int

outline_size

0

StyleBox

read_only

Color

search_result_border_color

Color(0.3, 0.3, 0.3, 0.4)

Color

search_result_color

Color(0.3, 0.3, 0.3, 1)

Color

selection_color

Color(0.49, 0.49, 0.49, 1)

Texture2D

space

Texture2D

tab

Color

word_highlighted_color

Color(0.8, 0.9, 0.9, 0.15)

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.


  • request_code_completion ( )

Emitted when the user requests code completion.


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:

  • KIND_CLASS = 0 --- Marks the option as a class.

  • KIND_FUNCTION = 1 --- Marks the option as a function.

  • KIND_SIGNAL = 2 --- Marks the option as a Godot signal.

  • KIND_VARIABLE = 3 --- Marks the option as a variable.

  • KIND_MEMBER = 4 --- Marks the option as a member.

  • KIND_ENUM = 5 --- Marks the option as a enum entry.

  • KIND_CONSTANT = 6 --- Marks the option as a constant.

  • KIND_NODE_PATH = 7 --- Marks the option as a Godot node path.

  • KIND_FILE_PATH = 8 --- Marks the option as a file path.

  • KIND_PLAIN_TEXT = 9 --- Marks the option as unclassified or plain text.

Property Descriptions

  • bool auto_brace_completion_enabled

Default

false

Setter

set_auto_brace_completion_enabled(value)

Getter

is_auto_brace_completion_enabled()

Sets whether brace pairs should be autocompleted.


  • bool auto_brace_completion_highlight_matching

Default

false

Setter

set_highlight_matching_braces_enabled(value)

Getter

is_highlight_matching_braces_enabled()

Highlight mismatching brace pairs.


Default

{"\"": "\"","'": "'","(": ")","[": "]","{": "}"}

Setter

set_auto_brace_completion_pairs(value)

Getter

get_auto_brace_completion_pairs()

Sets the brace pairs to be autocompleted.


  • bool code_completion_enabled

Default

false

Setter

set_code_completion_enabled(value)

Getter

is_code_completion_enabled()

Sets whether code completion is allowed.


Default

[]

Setter

set_code_completion_prefixes(value)

Getter

get_code_comletion_prefixes()

Sets prefixes that will trigger code completion.


Default

[]

Setter

set_comment_delimiters(value)

Getter

get_comment_delimiters()

Sets the comment delimiters. All existing comment delimiters will be removed.


Default

["' '", "\" \""]

Setter

set_string_delimiters(value)

Getter

get_string_delimiters()

Sets the string delimiters. All existing string delimiters will be removed.


  • bool gutters_draw_bookmarks

Default

false

Setter

set_draw_bookmarks_gutter(value)

Getter

is_drawing_bookmarks_gutter()

Sets if bookmarked should be drawn in the gutter. This gutter is shared with breakpoints and executing lines.


  • bool gutters_draw_breakpoints_gutter

Default

false

Setter

set_draw_breakpoints_gutter(value)

Getter

is_drawing_breakpoints_gutter()

Sets if breakpoints should be drawn in the gutter. This gutter is shared with bookmarks and executing lines.


  • bool gutters_draw_executing_lines

Default

false

Setter

set_draw_executing_lines_gutter(value)

Getter

is_drawing_executing_lines_gutter()

Sets if executing lines should be marked in the gutter. This gutter is shared with breakpoints and bookmarks lines.


  • bool gutters_draw_fold_gutter

Default

false

Setter

set_draw_fold_gutter(value)

Getter

is_drawing_fold_gutter()

Sets if foldable lines icons should be drawn in the gutter.


  • bool gutters_draw_line_numbers

Default

false

Setter

set_draw_line_numbers(value)

Getter

is_draw_line_numbers_enabled()

Sets if line numbers should be drawn in the gutter.


  • bool gutters_zero_pad_line_numbers

Default

false

Setter

set_line_numbers_zero_padded(value)

Getter

is_line_numbers_zero_padded()

Sets if line numbers drawn in the gutter are zero padded.


  • bool indent_automatic

Default

false

Setter

set_auto_indent_enabled(value)

Getter

is_auto_indent_enabled()

Sets whether automatic indent are enabled, this will add an extra indent if a prefix or brace is found.


Default

["(", ":", "[", "{"]

Setter

set_auto_indent_prefixes(value)

Getter

get_auto_indent_prefixes()

Prefixes to trigger an automatic indent.


  • int indent_size

Default

4

Setter

set_indent_size(value)

Getter

get_indent_size()

Size of tabs, if indent_use_spaces is enabled the amount of spaces to use.


  • bool indent_use_spaces

Default

false

Setter

set_indent_using_spaces(value)

Getter

is_indent_using_spaces()

Use spaces instead of tabs for indentation.


Default

false

Setter

set_line_folding_enabled(value)

Getter

is_line_folding_enabled()

Sets whether line folding is allowed.


  • int[] line_length_guidelines

Default

[]

Setter

set_line_length_guidelines(value)

Getter

get_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

Default

false

Setter

set_symbol_lookup_on_click_enabled(value)

Getter

is_symbol_lookup_on_click_enabled()

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.


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.


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 do_unindent ( )

Perform an unindent as if the user activated the "ui_text_unindent" 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.


  • Array get_bookmarked_lines ( ) const

Gets all bookmarked lines.


  • Array get_breakpointed_lines ( ) const

Gets all breakpointed lines.


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.


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 ( int delimiter_index ) const

Gets the end key for a string or comment region index.


  • Vector2 get_delimiter_end_position ( int line, int column ) const

If line column is in a string or comment, returns the end position of the region. If not or no end could be found, both Vector2 values will be -1.


  • String get_delimiter_start_key ( int delimiter_index ) const

Gets the start key for a string or comment region index.


  • Vector2 get_delimiter_start_position ( int line, int column ) const

If line column is in a string or comment, returns the start position of the region. If not or no start could be found, both Vector2 values will be -1.


  • Array get_executing_lines ( ) const

Gets all executing lines.


  • int[] get_folded_lines ( ) const

Return all lines that are current folded.


  • String get_text_for_code_completion ( ) const

Returns the full text with char 0xFFFF at the caret location.


  • String get_text_for_symbol_lookup ( )

Returns the full text with char 0xFFFF at the cursor location.


  • bool has_auto_brace_completion_close_key ( String close_key ) const

Returns true if close key close_key exists.


  • bool has_auto_brace_completion_open_key ( String open_key ) const

Returns true if open key open_key exists.


  • bool has_comment_delimiter ( String start_key ) const

Returns true if comment start_key exists.


  • bool has_string_delimiter ( String start_key ) const

Returns true if string start_key exists.


  • void indent_lines ( )

Indents selected lines, or in the case of no selection the caret line by one.


  • int is_in_comment ( int line, int column=-1 ) const

Return delimiter index if line column is in a comment. If column is not provided, will return delimiter index if the entire line is a comment. Otherwise -1.


  • int is_in_string ( int line, int column=-1 ) const

Return the delimiter index if line column is in a string. If column is not provided, will return the delimiter index if the entire line is a string. Otherwise -1.


  • bool is_line_bookmarked ( int line ) const

Returns whether the line at the specified index is bookmarked or not.


  • bool is_line_breakpointed ( int line ) const

Returns whether the line at the specified index is breakpointed or not.


  • bool is_line_executing ( int line ) const

Returns whether the line at the specified index is marked as executing or not.


  • bool is_line_folded ( int line ) const

Returns whether the line at the specified index is folded or not.


  • void remove_comment_delimiter ( String start_key )

Removes the comment delimiter with start_key.


  • void remove_string_delimiter ( String start_key )

Removes the string delimiter with start_key.


  • void request_code_completion ( bool force=false )

Emits request_code_completion, if force is true 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.


  • void set_code_completion_selected_index ( int index )

Sets the current selected completion option.


  • void set_code_hint ( String code_hint )

Sets the code hint text. Pass an empty string to clear.


  • void set_code_hint_draw_below ( bool draw_below )

Sets if the code hint should draw below the text.


  • void set_line_as_bookmarked ( int line, bool bookmarked )

Sets the line as bookmarked.


  • void set_line_as_breakpoint ( int line, bool breakpointed )

Sets the line as breakpointed.


  • void set_line_as_executing ( int line, bool executing )

Sets the line as executing.


  • void set_symbol_lookup_word_as_valid ( bool valid )

Sets the symbol emitted by symbol_validate as a valid lookup.


  • void toggle_foldable_line ( int line )

Toggle the folding of the code block at the given line.


  • void unfold_all_lines ( )

Unfolds all lines, folded or not.


  • void unfold_line ( int line )

Unfolds all lines that were previously folded.


  • void unindent_lines ( )

Unindents selected lines, or in the case of no selection the caret line by one.


  • void update_code_completion_options ( bool force )

Submits all completion options added with add_code_completion_option. Will try to force the autoccomplete menu to popup, if force is true.

Note: This will replace all current candidates.

Theme Property Descriptions

Default

Color(0, 0, 0, 0)

Sets the background Color.


Sets a custom Texture2D to draw in the bookmark gutter for bookmarked lines.


Default

Color(0.5, 0.64, 1, 0.8)

Color of the bookmark icon for bookmarked lines.


  • Color brace_mismatch_color

Default

Color(1, 0.2, 0.2, 1)

Color of the text to highlight mismatched braces.


Sets a custom Texture2D to draw in the breakpoint gutter for breakpointed lines.


Default

Color(0.9, 0.29, 0.3, 1)

Color of the breakpoint icon for bookmarked lines.


Sets a custom Texture2D to draw in the line folding gutter when a line can be folded.


  • Color caret_background_color

Default

Color(0, 0, 0, 1)

Color of the text behind the caret when block caret is enabled.


Default

Color(0.88, 0.88, 0.88, 1)

Color of the caret.


  • Color code_folding_color

Default

Color(0.8, 0.8, 0.8, 0.8)

Color for all icons related to line folding.


StyleBox for the code completion popup.


  • Color completion_background_color

Default

Color(0.17, 0.16, 0.2, 1)

Sets the background Color for the code completion popup.


  • Color completion_existing_color

Default

Color(0.87, 0.87, 0.87, 0.13)

Background highlight Color for matching text in code completion options.


  • Color completion_font_color

Default

Color(0.67, 0.67, 0.67, 1)

Font Color for the code completion popup.


  • int completion_lines

Default

7

Max number of options to display in the code completion popup at any one time.


  • int completion_max_width

Default

50

Max width of options in the code completion popup. Options longer then this will be cut off.


  • Color completion_scroll_color

Default

Color(1, 1, 1, 1)

Color of the scrollbar in the code completion popup.


  • int completion_scroll_width

Default

3

Width of the scrollbar in the code completion popup.


  • Color completion_selected_color

Default

Color(0.26, 0.26, 0.27, 1)

Background highlight Color for the current selected option item in the code completion popup.


  • Color current_line_color

Default

Color(0.25, 0.25, 0.26, 0.8)

Background Color of the line containing the caret.


Icon to draw in the executing gutter for executing lines.


  • Color executing_line_color

Default

Color(0.98, 0.89, 0.27, 1)

Color of the executing icon for executing lines.


Sets the StyleBox when in focus.


Sets a custom Texture2D to draw in the line folding gutter when a line is folded and can be unfolded.


Sets a custom Texture2D to draw at the end of a folded line.


Sets the default Font.


Default

Color(0.88, 0.88, 0.88, 1)

Sets the font Color.


  • Color font_outline_color

Default

Color(1, 1, 1, 1)

The tint of text outline of the CodeEdit.


  • Color font_readonly_color

Default

Color(0.88, 0.88, 0.88, 0.5)

Sets the font Color when TextEdit.editable is disabled.


  • Color font_selected_color

Default

Color(0, 0, 0, 1)

Sets the Color of the selected text. TextEdit.override_selected_font_color has to be enabled.


  • int font_size

Sets default font size.


  • Color line_length_guideline_color

Default

Color(0.3, 0.5, 0.8, 0.1)

Color of the main line length guideline, secondary guidelines will have 50% alpha applied.


  • Color line_number_color

Default

Color(0.67, 0.67, 0.67, 0.4)

Sets the Color of line numbers.


  • int line_spacing

Default

4

Sets the spacing between the lines.


Sets the StyleBox.


  • int outline_size

Default

0

The size of the text outline.


Sets the StyleBox when TextEdit.editable is disabled.


  • Color search_result_border_color

Default

Color(0.3, 0.3, 0.3, 0.4)

Color of the border around text that matches the search query.


  • Color search_result_color

Default

Color(0.3, 0.3, 0.3, 1)

Color behind the text that matches the search query.


Default

Color(0.49, 0.49, 0.49, 1)

Sets the highlight Color of text selections.


Sets a custom Texture2D for space text characters.


Sets a custom Texture2D for tab text characters.


  • Color word_highlighted_color

Default

Color(0.8, 0.9, 0.9, 0.15)

Sets the highlight Color of multiple occurrences. TextEdit.highlight_all_occurrences has to be enabled.