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
AutoBraceCompletionHighlightMatching
Highlight mismatching brace pairs.
public bool AutoBraceCompletionHighlightMatching { get; set; }
Property Value
AutoBraceCompletionPairs
Sets the brace pairs to be autocompleted.
public Dictionary AutoBraceCompletionPairs { get; set; }
Property Value
CodeCompletionEnabled
Sets whether code completion is allowed.
public bool CodeCompletionEnabled { get; set; }
Property Value
CodeCompletionPrefixes
Sets prefixes that will trigger code completion.
public Array<string> CodeCompletionPrefixes { get; set; }
Property Value
DelimiterComments
Sets the comment delimiters. All existing comment delimiters will be removed.
public Array<string> DelimiterComments { get; set; }
Property Value
DelimiterStrings
Sets the string delimiters. All existing string delimiters will be removed.
public Array<string> DelimiterStrings { get; set; }
Property Value
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
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
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
GuttersDrawFoldGutter
Sets if foldable lines icons should be drawn in the gutter.
public bool GuttersDrawFoldGutter { get; set; }
Property Value
GuttersDrawLineNumbers
Sets if line numbers should be drawn in the gutter.
public bool GuttersDrawLineNumbers { get; set; }
Property Value
GuttersZeroPadLineNumbers
Sets if line numbers drawn in the gutter are zero padded.
public bool GuttersZeroPadLineNumbers { get; set; }
Property Value
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
IndentAutomaticPrefixes
Prefixes to trigger an automatic indent.
public Array<string> IndentAutomaticPrefixes { get; set; }
Property Value
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
IndentUseSpaces
Use spaces instead of tabs for indentation.
public bool IndentUseSpaces { get; set; }
Property Value
LineFolding
Sets whether line folding is allowed.
public bool LineFolding { get; set; }
Property Value
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
SymbolLookupOnClick
Set when a validated word from SymbolValidate is clicked, the SymbolLookup should be emitted.
public bool SymbolLookupOnClick { get; set; }
Property Value
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
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
typeCodeEdit.CodeCompletionKinddisplayTextstringinsertTextstringtextColorColor?If the parameter is null, then the default value is
new Color(1, 1, 1, 1).iconResourcevalueVariant?If the parameter is null, then the default value is
(Variant)(0).locationint
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
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
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
lineint
Returns
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
replacebool
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
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
lineint
GetAutoBraceCompletionCloseKey(string)
Gets the matching auto brace close key for openKey.
public string GetAutoBraceCompletionCloseKey(string openKey)
Parameters
openKeystring
Returns
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
indexint
Returns
GetCodeCompletionOptions()
Gets all completion options, see GetCodeCompletionOption(int) for return content.
public Array<Dictionary> GetCodeCompletionOptions()
Returns
GetCodeCompletionSelectedIndex()
Gets the index of the current selected completion option.
public int GetCodeCompletionSelectedIndex()
Returns
GetCodeRegionEndTag()
Returns the code region end tag (without comment delimiter).
public string GetCodeRegionEndTag()
Returns
GetCodeRegionStartTag()
Returns the code region start tag (without comment delimiter).
public string GetCodeRegionStartTag()
Returns
GetDelimiterEndKey(int)
Gets the end key for a string or comment region index.
public string GetDelimiterEndKey(int delimiterIndex)
Parameters
delimiterIndexint
Returns
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
Returns
GetDelimiterStartKey(int)
Gets the start key for a string or comment region index.
public string GetDelimiterStartKey(int delimiterIndex)
Parameters
delimiterIndexint
Returns
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
Returns
GetExecutingLines()
Gets all executing lines.
public int[] GetExecutingLines()
Returns
- int[]
GetFoldedLines()
Returns all lines that are current folded.
public Array<int> GetFoldedLines()
Returns
GetTextForCodeCompletion()
Returns the full text with char 0xFFFF at the caret location.
public string GetTextForCodeCompletion()
Returns
GetTextForSymbolLookup()
Returns the full text with char 0xFFFF at the cursor location.
public string GetTextForSymbolLookup()
Returns
GetTextWithCursorChar(int, int)
Returns the full text with char 0xFFFF at the specified location.
public string GetTextWithCursorChar(int line, int column)
Parameters
Returns
HasAutoBraceCompletionCloseKey(string)
Returns true if close key closeKey exists.
public bool HasAutoBraceCompletionCloseKey(string closeKey)
Parameters
closeKeystring
Returns
HasAutoBraceCompletionOpenKey(string)
Returns true if open key openKey exists.
public bool HasAutoBraceCompletionOpenKey(string openKey)
Parameters
openKeystring
Returns
HasCommentDelimiter(string)
Returns true if comment startKey exists.
public bool HasCommentDelimiter(string startKey)
Parameters
startKeystring
Returns
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
methodgodot_string_nameName of the method to check for.
Returns
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
signalgodot_string_nameName of the signal to check for.
Returns
HasStringDelimiter(string)
Returns true if string startKey exists.
public bool HasStringDelimiter(string startKey)
Parameters
startKeystring
Returns
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
methodgodot_string_nameName of the method to invoke.
argsNativeVariantPtrArgsArguments to use with the invoked method.
retgodot_variantValue returned by the invoked method.
Returns
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
Returns
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
Returns
IsLineBookmarked(int)
Returns whether the line at the specified index is bookmarked or not.
public bool IsLineBookmarked(int line)
Parameters
lineint
Returns
IsLineBreakpointed(int)
Returns whether the line at the specified index is breakpointed or not.
public bool IsLineBreakpointed(int line)
Parameters
lineint
Returns
IsLineCodeRegionEnd(int)
Returns whether the line at the specified index is a code region end.
public bool IsLineCodeRegionEnd(int line)
Parameters
lineint
Returns
IsLineCodeRegionStart(int)
Returns whether the line at the specified index is a code region start.
public bool IsLineCodeRegionStart(int line)
Parameters
lineint
Returns
IsLineExecuting(int)
Returns whether the line at the specified index is marked as executing or not.
public bool IsLineExecuting(int line)
Parameters
lineint
Returns
IsLineFolded(int)
Returns whether the line at the specified index is folded or not.
public bool IsLineFolded(int line)
Parameters
lineint
Returns
RemoveCommentDelimiter(string)
Removes the comment delimiter with startKey.
public void RemoveCommentDelimiter(string startKey)
Parameters
startKeystring
RemoveStringDelimiter(string)
Removes the string delimiter with startKey.
public void RemoveStringDelimiter(string startKey)
Parameters
startKeystring
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
forcebool
SetCodeCompletionSelectedIndex(int)
Sets the current selected completion option.
public void SetCodeCompletionSelectedIndex(int index)
Parameters
indexint
SetCodeHint(string)
Sets the code hint text. Pass an empty string to clear.
public void SetCodeHint(string codeHint)
Parameters
codeHintstring
SetCodeHintDrawBelow(bool)
Sets if the code hint should draw below the text.
public void SetCodeHintDrawBelow(bool drawBelow)
Parameters
drawBelowbool
SetCodeRegionTags(string, string)
Sets the code region start and end tags (without comment delimiter).
public void SetCodeRegionTags(string start = "region", string end = "endregion")
Parameters
SetLineAsBookmarked(int, bool)
Sets the line as bookmarked.
public void SetLineAsBookmarked(int line, bool bookmarked)
Parameters
SetLineAsBreakpoint(int, bool)
Sets the line as breakpointed.
public void SetLineAsBreakpoint(int line, bool breakpointed)
Parameters
SetLineAsExecuting(int, bool)
Sets the line as executing.
public void SetLineAsExecuting(int line, bool executing)
Parameters
SetSymbolLookupWordAsValid(bool)
Sets the symbol emitted by SymbolValidate as a valid lookup.
public void SetSymbolLookupWordAsValid(bool valid)
Parameters
validbool
ToggleFoldableLine(int)
Toggle the folding of the code block at the given line.
public void ToggleFoldableLine(int line)
Parameters
lineint
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
lineint
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
forcebool
_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
replacebool
_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
candidatesArray<Dictionary>
Returns
_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
forcebool
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
CodeCompletionRequested
Emitted when the user requests code completion.
public event Action CodeCompletionRequested
Event Type
SymbolLookup
Emitted when the user has clicked on a valid symbol.
public event CodeEdit.SymbolLookupEventHandler SymbolLookup
Event Type
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