Table of Contents

Class CodeEdit

Namespace
Godot
Assembly
GodotSharp.dll

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

public class CodeEdit : TextEdit, IDisposable
Inheritance
CodeEdit
Implements
Inherited Members

Constructors

CodeEdit()

public CodeEdit()

Properties

AutoBraceCompletionEnabled

Sets whether brace pairs should be autocompleted.

public bool AutoBraceCompletionEnabled { get; set; }

Property Value

bool

AutoBraceCompletionHighlightMatching

Highlight mismatching brace pairs.

public bool AutoBraceCompletionHighlightMatching { get; set; }

Property Value

bool

AutoBraceCompletionPairs

Sets the brace pairs to be autocompleted.

public Dictionary AutoBraceCompletionPairs { get; set; }

Property Value

Dictionary

CodeCompletionEnabled

Sets whether code completion is allowed.

public bool CodeCompletionEnabled { get; set; }

Property Value

bool

CodeCompletionPrefixes

Sets prefixes that will trigger code completion.

public Array<string> CodeCompletionPrefixes { get; set; }

Property Value

Array<string>

DelimiterComments

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

public Array<string> DelimiterComments { get; set; }

Property Value

Array<string>

DelimiterStrings

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

public Array<string> DelimiterStrings { get; set; }

Property Value

Array<string>

GuttersDrawBookmarks

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

public bool GuttersDrawBookmarks { get; set; }

Property Value

bool

GuttersDrawBreakpointsGutter

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

public bool GuttersDrawBreakpointsGutter { get; set; }

Property Value

bool

GuttersDrawExecutingLines

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

public bool GuttersDrawExecutingLines { get; set; }

Property Value

bool

GuttersDrawFoldGutter

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

public bool GuttersDrawFoldGutter { get; set; }

Property Value

bool

GuttersDrawLineNumbers

Sets if line numbers should be drawn in the gutter.

public bool GuttersDrawLineNumbers { get; set; }

Property Value

bool

GuttersZeroPadLineNumbers

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

public bool GuttersZeroPadLineNumbers { get; set; }

Property Value

bool

IndentAutomatic

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

public bool IndentAutomatic { get; set; }

Property Value

bool

IndentAutomaticPrefixes

Prefixes to trigger an automatic indent.

public Array<string> IndentAutomaticPrefixes { get; set; }

Property Value

Array<string>

IndentSize

Size of the tabulation indent (one Tab press) in characters. If IndentUseSpaces is enabled the number of spaces to use.

public int IndentSize { get; set; }

Property Value

int

IndentUseSpaces

Use spaces instead of tabs for indentation.

public bool IndentUseSpaces { get; set; }

Property Value

bool

LineFolding

Sets whether line folding is allowed.

public bool LineFolding { get; set; }

Property Value

bool

LineLengthGuidelines

Draws vertical lines at the provided columns. The first entry is considered a main hard guideline and is draw more prominently.

public Array<int> LineLengthGuidelines { get; set; }

Property Value

Array<int>

SymbolLookupOnClick

Set when a validated word from SymbolValidate is clicked, the SymbolLookup should be emitted.

public bool SymbolLookupOnClick { get; set; }

Property Value

bool

Methods

AddAutoBraceCompletionPair(string, string)

Adds a brace pair.

Both the start and end keys must be symbols. Only the start key has to be unique.

public void AddAutoBraceCompletionPair(string startKey, string endKey)

Parameters

startKey string
endKey string

AddCodeCompletionOption(CodeCompletionKind, string, string, Color?, Resource, Variant?, int)

Submits an item to the queue of potential candidates for the autocomplete menu. Call UpdateCodeCompletionOptions(bool) to update the list.

location indicates location of the option relative to the location of the code completion query. See CodeEdit.CodeCompletionLocation for how to set this value.

Note: This list will replace all current candidates.

public void AddCodeCompletionOption(CodeEdit.CodeCompletionKind type, string displayText, string insertText, Color? textColor = null, Resource icon = null, Variant? value = null, int location = 1024)

Parameters

type CodeEdit.CodeCompletionKind
displayText string
insertText string
textColor Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

icon Resource
value Variant?

If the parameter is null, then the default value is (Variant)(0).

location int

AddCommentDelimiter(string, string, bool)

Adds a comment delimiter.

Both the start and end keys must be symbols. Only the start key has to be unique.

lineOnly 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.

public void AddCommentDelimiter(string startKey, string endKey, bool lineOnly = false)

Parameters

startKey string
endKey string
lineOnly bool

AddStringDelimiter(string, string, bool)

Adds a string delimiter.

Both the start and end keys must be symbols. Only the start key has to be unique.

lineOnly 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.

public void AddStringDelimiter(string startKey, string endKey, bool lineOnly = false)

Parameters

startKey string
endKey string
lineOnly bool

CanFoldLine(int)

Returns if the given line is foldable, that is, it has indented lines right below it or a comment / string block.

public bool CanFoldLine(int line)

Parameters

line int

Returns

bool

CancelCodeCompletion()

Cancels the autocomplete menu.

public void CancelCodeCompletion()

ClearBookmarkedLines()

Clears all bookmarked lines.

public void ClearBookmarkedLines()

ClearBreakpointedLines()

Clears all breakpointed lines.

public void ClearBreakpointedLines()

ClearCommentDelimiters()

Removes all comment delimiters.

public void ClearCommentDelimiters()

ClearExecutingLines()

Clears all executed lines.

public void ClearExecutingLines()

ClearStringDelimiters()

Removes all string delimiters.

public void ClearStringDelimiters()

ConfirmCodeCompletion(bool)

Inserts the selected entry into the text. If replace is true, any existing text is replaced rather than merged.

public void ConfirmCodeCompletion(bool replace = false)

Parameters

replace bool

ConvertIndent(int, int)

Converts the indents of lines between fromLine and toLine to tabs or spaces as set by IndentUseSpaces.

Values of -1 convert the entire text.

public void ConvertIndent(int fromLine = -1, int toLine = -1)

Parameters

fromLine int
toLine int

CreateCodeRegion()

Creates a new code region with the selection. At least one single line comment delimiter have to be defined (see AddCommentDelimiter(string, string, bool)).

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 (see SetCodeRegionTags(string, string)).

Code regions are delimited using start and end tags (respectively region and endregion by default) preceded by one line comment delimiter. (eg. #region and #endregion)

public void CreateCodeRegion()

DoIndent()

Perform an indent as if the user activated the "ui_text_indent" action.

public void DoIndent()

DuplicateLines()

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.

public void DuplicateLines()

FoldAllLines()

Folds all lines that are possible to be folded (see CanFoldLine(int)).

public void FoldAllLines()

FoldLine(int)

Folds the given line, if possible (see CanFoldLine(int)).

public void FoldLine(int line)

Parameters

line int

GetAutoBraceCompletionCloseKey(string)

Gets the matching auto brace close key for openKey.

public string GetAutoBraceCompletionCloseKey(string openKey)

Parameters

openKey string

Returns

string

GetBookmarkedLines()

Gets all bookmarked lines.

public int[] GetBookmarkedLines()

Returns

int[]

GetBreakpointedLines()

Gets all breakpointed lines.

public int[] GetBreakpointedLines()

Returns

int[]

GetCodeCompletionOption(int)

Gets the completion option at index. The return Dictionary has the following key-values:

kind: CodeEdit.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.

public Dictionary GetCodeCompletionOption(int index)

Parameters

index int

Returns

Dictionary

GetCodeCompletionOptions()

Gets all completion options, see GetCodeCompletionOption(int) for return content.

public Array<Dictionary> GetCodeCompletionOptions()

Returns

Array<Dictionary>

GetCodeCompletionSelectedIndex()

Gets the index of the current selected completion option.

public int GetCodeCompletionSelectedIndex()

Returns

int

GetCodeRegionEndTag()

Returns the code region end tag (without comment delimiter).

public string GetCodeRegionEndTag()

Returns

string

GetCodeRegionStartTag()

Returns the code region start tag (without comment delimiter).

public string GetCodeRegionStartTag()

Returns

string

GetDelimiterEndKey(int)

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

public string GetDelimiterEndKey(int delimiterIndex)

Parameters

delimiterIndex int

Returns

string

GetDelimiterEndPosition(int, int)

If linecolumn 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.

public Vector2 GetDelimiterEndPosition(int line, int column)

Parameters

line int
column int

Returns

Vector2

GetDelimiterStartKey(int)

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

public string GetDelimiterStartKey(int delimiterIndex)

Parameters

delimiterIndex int

Returns

string

GetDelimiterStartPosition(int, int)

If linecolumn 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.

public Vector2 GetDelimiterStartPosition(int line, int column)

Parameters

line int
column int

Returns

Vector2

GetExecutingLines()

Gets all executing lines.

public int[] GetExecutingLines()

Returns

int[]

GetFoldedLines()

Returns all lines that are current folded.

public Array<int> GetFoldedLines()

Returns

Array<int>

GetTextForCodeCompletion()

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

public string GetTextForCodeCompletion()

Returns

string

GetTextForSymbolLookup()

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

public string GetTextForSymbolLookup()

Returns

string

GetTextWithCursorChar(int, int)

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

public string GetTextWithCursorChar(int line, int column)

Parameters

line int
column int

Returns

string

HasAutoBraceCompletionCloseKey(string)

Returns true if close key closeKey exists.

public bool HasAutoBraceCompletionCloseKey(string closeKey)

Parameters

closeKey string

Returns

bool

HasAutoBraceCompletionOpenKey(string)

Returns true if open key openKey exists.

public bool HasAutoBraceCompletionOpenKey(string openKey)

Parameters

openKey string

Returns

bool

HasCommentDelimiter(string)

Returns true if comment startKey exists.

public bool HasCommentDelimiter(string startKey)

Parameters

startKey string

Returns

bool

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

HasStringDelimiter(string)

Returns true if string startKey exists.

public bool HasStringDelimiter(string startKey)

Parameters

startKey string

Returns

bool

IndentLines()

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

public void IndentLines()

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

IsInComment(int, int)

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

public int IsInComment(int line, int column = -1)

Parameters

line int
column int

Returns

int

IsInString(int, int)

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

public int IsInString(int line, int column = -1)

Parameters

line int
column int

Returns

int

IsLineBookmarked(int)

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

public bool IsLineBookmarked(int line)

Parameters

line int

Returns

bool

IsLineBreakpointed(int)

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

public bool IsLineBreakpointed(int line)

Parameters

line int

Returns

bool

IsLineCodeRegionEnd(int)

Returns whether the line at the specified index is a code region end.

public bool IsLineCodeRegionEnd(int line)

Parameters

line int

Returns

bool

IsLineCodeRegionStart(int)

Returns whether the line at the specified index is a code region start.

public bool IsLineCodeRegionStart(int line)

Parameters

line int

Returns

bool

IsLineExecuting(int)

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

public bool IsLineExecuting(int line)

Parameters

line int

Returns

bool

IsLineFolded(int)

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

public bool IsLineFolded(int line)

Parameters

line int

Returns

bool

RemoveCommentDelimiter(string)

Removes the comment delimiter with startKey.

public void RemoveCommentDelimiter(string startKey)

Parameters

startKey string

RemoveStringDelimiter(string)

Removes the string delimiter with startKey.

public void RemoveStringDelimiter(string startKey)

Parameters

startKey string

RequestCodeCompletion(bool)

Emits CodeCompletionRequested, 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.

public void RequestCodeCompletion(bool force = false)

Parameters

force bool

SetCodeCompletionSelectedIndex(int)

Sets the current selected completion option.

public void SetCodeCompletionSelectedIndex(int index)

Parameters

index int

SetCodeHint(string)

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

public void SetCodeHint(string codeHint)

Parameters

codeHint string

SetCodeHintDrawBelow(bool)

Sets if the code hint should draw below the text.

public void SetCodeHintDrawBelow(bool drawBelow)

Parameters

drawBelow bool

SetCodeRegionTags(string, string)

Sets the code region start and end tags (without comment delimiter).

public void SetCodeRegionTags(string start = "region", string end = "endregion")

Parameters

start string
end string

SetLineAsBookmarked(int, bool)

Sets the line as bookmarked.

public void SetLineAsBookmarked(int line, bool bookmarked)

Parameters

line int
bookmarked bool

SetLineAsBreakpoint(int, bool)

Sets the line as breakpointed.

public void SetLineAsBreakpoint(int line, bool breakpointed)

Parameters

line int
breakpointed bool

SetLineAsExecuting(int, bool)

Sets the line as executing.

public void SetLineAsExecuting(int line, bool executing)

Parameters

line int
executing bool

SetSymbolLookupWordAsValid(bool)

Sets the symbol emitted by SymbolValidate as a valid lookup.

public void SetSymbolLookupWordAsValid(bool valid)

Parameters

valid bool

ToggleFoldableLine(int)

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

public void ToggleFoldableLine(int line)

Parameters

line int

UnfoldAllLines()

Unfolds all lines, folded or not.

public void UnfoldAllLines()

UnfoldLine(int)

Unfolds all lines that were previously folded.

public void UnfoldLine(int line)

Parameters

line int

UnindentLines()

Unindents selected lines, or in the case of no selection the caret line by one. Same as performing "ui_text_unindent" action.

public void UnindentLines()

UpdateCodeCompletionOptions(bool)

Submits all completion options added with AddCodeCompletionOption(CodeCompletionKind, string, string, Color?, Resource, Variant?, int). Will try to force the autocomplete menu to popup, if force is true.

Note: This will replace all current candidates.

public void UpdateCodeCompletionOptions(bool force)

Parameters

force bool

_ConfirmCodeCompletion(bool)

Override this method to define how the selected entry should be inserted. If replace is true, any existing text should be replaced.

public virtual void _ConfirmCodeCompletion(bool replace)

Parameters

replace bool

_FilterCodeCompletionCandidates(Array<Dictionary>)

Override this method to define what items in candidates should be displayed.

Both candidates and the return is a Array of Dictionary, see GetCodeCompletionOption(int) for Dictionary content.

public virtual Array<Dictionary> _FilterCodeCompletionCandidates(Array<Dictionary> candidates)

Parameters

candidates Array<Dictionary>

Returns

Array<Dictionary>

_RequestCodeCompletion(bool)

Override this method to define what happens when the user requests code completion. If force is true, any checks should be bypassed.

public virtual void _RequestCodeCompletion(bool force)

Parameters

force bool

Events

BreakpointToggled

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.

public event CodeEdit.BreakpointToggledEventHandler BreakpointToggled

Event Type

CodeEdit.BreakpointToggledEventHandler

CodeCompletionRequested

Emitted when the user requests code completion.

public event Action CodeCompletionRequested

Event Type

Action

SymbolLookup

Emitted when the user has clicked on a valid symbol.

public event CodeEdit.SymbolLookupEventHandler SymbolLookup

Event Type

CodeEdit.SymbolLookupEventHandler

SymbolValidate

Emitted when the user hovers over a symbol. The symbol should be validated and responded to, by calling SetSymbolLookupWordAsValid(bool).

public event CodeEdit.SymbolValidateEventHandler SymbolValidate

Event Type

CodeEdit.SymbolValidateEventHandler