The Script Editor system provides code editing capabilities within the Godot Editor. It is built upon the TextEdit and CodeEdit GUI controls to provide syntax highlighting, code completion, debugging integration, breakpoint management, and script file handling. The primary orchestrator is the ScriptEditor plugin, which manages multiple script instances and provides the surrounding UI like the members overview and file list.
For information about the broader editor plugin system, see EditorPlugin System. For details about text rendering and shaping, see Text Shaping System. For GDScript-specific analysis and compilation, see GDScript System.
The Script Editor is built as a layered system where specialized code editing controls are integrated into the editor's plugin architecture. The ScriptEditor class acts as the central container for various ScriptEditorBase implementations (like ScriptTextEditor for text scripts).
Title: Script Editor Component Hierarchy
Sources: editor/script/script_editor_plugin.h83-214 editor/script/script_text_editor.h57-142 editor/gui/code_editor.h184-210
The ScriptEditor class (editor/script/script_editor_plugin.h83) is a PanelContainer that manages the script editing workspace. It handles file operations (Open, Save, Close), script history, and the overall layout including the sidebar docks.
Key UI Elements:
ItemList showing all open scripts editor/script/script_editor_plugin.h168Tree or ItemList showing functions and variables in the current script editor/script/script_editor_plugin.h170ScriptEditorQuickOpen for jumping to functions editor/script/script_editor_plugin.cpp148-170Sources: editor/script/script_editor_plugin.h83-214 editor/script/script_editor_plugin.cpp148-170
ScriptTextEditor (editor/script/script_text_editor.h57) is the specific implementation for text-based scripts. It encapsulates a CodeTextEditor, which in turn wraps a CodeEdit control.
Functionality:
ConnectionInfoDialog editor/script/script_text_editor.cpp67-103EditorSyntaxHighlighter resources editor/script/script_text_editor.cpp52Sources: editor/script/script_text_editor.h57-195 editor/script/script_text_editor.cpp31-103
CodeEdit extends TextEdit with features specifically for code editing, such as line numbers, code folding, and auto-indentation.
| Feature | Description |
|---|---|
| Syntax Highlighting | Pluggable system via SyntaxHighlighter scene/resources/syntax_highlighter.cpp37-53 |
| Code Completion | Suggests symbols via _code_complete_script editor/script/script_text_editor.h168-170 |
| Find/Replace | Integrated FindReplaceBar for searching within a file editor/gui/code_editor.cpp141-173 |
| Go to Line | GotoLinePopup for rapid navigation editor/gui/code_editor.cpp53-69 |
Sources: editor/gui/code_editor.h35-150 editor/gui/code_editor.cpp31-173 scene/resources/syntax_highlighter.cpp37-53
The Script Editor relies on the base text controls for its rendering and input handling.
TextEdit (scene/gui/text_edit.cpp40) is the multiline text editor control. It handles the core logic for text storage, carets, and selection. It uses an internal Text structure to manage line data and TextParagraph for shaping scene/gui/text_edit.h136-168
Key Caret Management:
add_caret(line, column): Adds a new caret doc/classes/TextEdit.xml62-69remove_secondary_carets(): Clears all but the main caret doc/classes/TextEdit.xml274-279RichTextLabel (scene/gui/rich_text_label.cpp50) is used within the editor for displaying formatted text, such as documentation or output logs. It parses BBCode and manages a tag stack doc/classes/RichTextLabel.xml7-13
Sources: scene/gui/text_edit.cpp31-127 scene/gui/rich_text_label.cpp31-210 doc/classes/TextEdit.xml1-145
Godot uses a flexible highlighting system where different languages implement their own logic by extending SyntaxHighlighter or CodeHighlighter.
Title: Highlighting Logic Flow
Sources: scene/resources/syntax_highlighter.h33-40 modules/gdscript/editor/gdscript_highlighter.h35-36
The GDScriptSyntaxHighlighter (modules/gdscript/editor/gdscript_highlighter.cpp42) provides advanced highlighting by tracking the context of the code. It implements _get_line_syntax_highlighting_impl to implement GDScript-specific logic modules/gdscript/editor/gdscript_highlighter.cpp42
Context Tracking Variables:
in_function_declaration: Identifies when the parser is after the func keyword modules/gdscript/editor/gdscript_highlighter.cpp68in_region: Tracks if the current line is inside a multi-line string or comment modules/gdscript/editor/gdscript_highlighter.cpp83expect_type: Tracks if the next word should be highlighted as a type (e.g., after a colon) modules/gdscript/editor/gdscript_highlighter.cpp73Sources: modules/gdscript/editor/gdscript_highlighter.cpp42-105 modules/gdscript/editor/gdscript_highlighter.h35-118
The FindInFiles system (editor/script/find_in_files.cpp) allows searching across the entire project. The FindInFilesSearch class (editor/script/find_in_files.h38) performs the actual search operations.
Search Process:
FindInFilesSearch::start() initializes parameters editor/script/find_in_files.cpp139-150_process() method calls _iterate() repeatedly editor/script/find_in_files.cpp161-170_scan_file() reads file content and performs pattern matching editor/script/find_in_files.cpp207-210Title: Find In Files Search Logic
Sources: editor/script/find_in_files.cpp62-213 editor/script/find_in_files.h38-87
The EditorLog (editor/editor_log.cpp54) captures engine and script errors, warnings, and standard output. It uses a RichTextLabel to display messages with clickable file references editor/editor_log.cpp61-64
Sources: editor/editor_log.cpp31-135 editor/editor_log.h35-80
Title: Script Loading and Editing Flow
Key Lifecycle Methods:
ScriptEditor::save_all_scripts(): Persists all dirty buffers to disk doc/classes/ScriptEditor.xml122-127ScriptEditor::reload_open_files(): Refreshes script content from disk doc/classes/ScriptEditor.xml116-121ScriptEditor::goto_line(int p_line): Navigates the current editor to a specific line doc/classes/ScriptEditor.xml93-99Sources: editor/script/script_editor_plugin.cpp146-170 doc/classes/ScriptEditor.xml1-158
Refresh this wiki
This wiki was recently refreshed. Please wait 4 days to refresh again.