Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
CodeEdit
繼承: TextEdit < Control < CanvasItem < Node < Object
多行文字編輯器,針對編輯程式碼而設計。
說明
CodeEdit 是一種專門用於編輯純文字程式碼檔的 TextEdit。它包含了許多程式碼編輯器中的常見功能,如行號、折行、程式碼補全、縮進管理以及字串/注釋管理。
注意:無論使用什麼區域設定,CodeEdit 預設總是使用從左至右的文字方向來正確顯示原始程式碼。
屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
layout_direction |
|
|
|
||
|
||
|
||
|
||
text_direction |
|
方法
主題屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
訊號
breakpoint_toggled(line: int) 🔗
為某一行新增或移除斷點時觸發。如果通過退格鍵移除該行,則會在原行處觸發一次訊號。
code_completion_requested() 🔗
在使用者請求程式碼補全時發出。如果 _request_code_completion() 被覆蓋或者 code_completion_enabled 為 false,則不會發送該訊號。
symbol_hovered(symbol: String, line: int, column: int) 🔗
當使用者在符號上懸停時發出。該訊號與 Control.mouse_entered 不同,不會立即發出,而是需要游標在符號上停留 ProjectSettings.gui/timers/tooltip_delay_sec 秒。
注意:symbol_tooltip_on_hover 為 true 時才會發出該訊號。
symbol_lookup(symbol: String, line: int, column: int) 🔗
使用者點選有效符號時發出。
symbol_validate(symbol: String) 🔗
使用者將滑鼠懸停在符號上時發出。應該通過呼叫 set_symbol_lookup_word_as_valid() 對該符號進行驗證和響應。
注意:symbol_lookup_on_click 必須為 true 才會發出該訊號。
列舉
enum CodeCompletionKind: 🔗
CodeCompletionKind KIND_CLASS = 0
將該選項標記為類。
CodeCompletionKind KIND_FUNCTION = 1
將該選項標記為函式。
CodeCompletionKind KIND_SIGNAL = 2
將該選項標記為 Godot 訊號。
CodeCompletionKind KIND_VARIABLE = 3
將該選項標記為變數。
CodeCompletionKind KIND_MEMBER = 4
將該選項標記為成員。
CodeCompletionKind KIND_ENUM = 5
將該選項標記為列舉條目。
CodeCompletionKind KIND_CONSTANT = 6
將該選項標記為常數。
CodeCompletionKind KIND_NODE_PATH = 7
將該選項標記為 Godot 節點路徑。
CodeCompletionKind KIND_FILE_PATH = 8
將該選項標記為檔路徑。
CodeCompletionKind KIND_PLAIN_TEXT = 9
將該選項標記為未分類或純文字。
CodeCompletionKind KIND_KEYWORD = 10
將該選項標記為關鍵字。
enum CodeCompletionLocation: 🔗
CodeCompletionLocation LOCATION_LOCAL = 0
該選項是相對於程式碼補全查詢位置的 - 例如區域變數。位置的後續值表示選項來自外部類,確切的值表示它們的距離(就內部類而言)。
CodeCompletionLocation LOCATION_PARENT_MASK = 256
該選項來自於所在的類或父類別,相對於程式碼補全查詢的位置。請使用類的深度進行按位 OR(或)運算(例如 0 表示目前類,1 表示父類別,2 表示父類別的父類別等),從而在目前類或父類別中儲存選項的深度。
CodeCompletionLocation LOCATION_OTHER_USER_CODE = 512
該選項來自使用者程式碼,不是區域,也不是衍生類(例如自動載入單例)。
CodeCompletionLocation LOCATION_OTHER = 1024
該選項來自其他引擎程式碼,未被其他列舉常數覆蓋 - 例如內建類。
屬性說明
bool auto_brace_completion_enabled = false 🔗
如果為 true,則當左括號被鍵入或被自動補全插入時,使用 auto_brace_completion_pairs 自動插入右括號。對左括號使用退格鍵時,也會自動移除右括號。
bool auto_brace_completion_highlight_matching = false 🔗
如果為 true,則當游標在一對括號中任何一個的位置時,使用 auto_brace_completion_pairs 將其醒目標示。配對的括號將新增底線。如果無法配對,則會使用 brace_mismatch_color 著色。
Dictionary auto_brace_completion_pairs = { "\"": "\"", "'": "'", "(": ")", "[": "]", "{": "}" } 🔗
void set_auto_brace_completion_pairs(value: Dictionary)
Dictionary get_auto_brace_completion_pairs()
將括號對設定為自動補全。字典元素中,鍵是左括號、值是對應的右括號。括號是由符號構成的 String。見 auto_brace_completion_enabled 和 auto_brace_completion_highlight_matching。
bool code_completion_enabled = false 🔗
如果為 true,則 ProjectSettings.input/ui_text_completion_query 動作會請求進行程式碼補全。處理請求見 _request_code_completion() 或 code_completion_requested。
Array[String] code_completion_prefixes = [] 🔗
設定將觸發程式碼補全的前綴。
Array[String] delimiter_comments = [] 🔗
設定注釋分隔符號。將刪除所有的現有注釋分隔符號。
Array[String] delimiter_strings = ["' '", "\" \""] 🔗
設定字串分隔符號。將刪除所有的現有字串分隔符號。
bool gutters_draw_bookmarks = false 🔗
如果為 true,則在邊欄中繪製書籤。該邊欄與斷點和執行行共享。見 set_line_as_bookmarked().
bool gutters_draw_breakpoints_gutter = false 🔗
如果為 true,則在邊欄中繪製斷點。該邊欄與書籤和執行行共享。點選邊欄會開關對應行的斷點,見 set_line_as_breakpoint().
bool gutters_draw_executing_lines = false 🔗
如果為 true,則在邊欄中繪製執行行。該邊欄與斷點和書籤共享。見 set_line_as_executing().
bool gutters_draw_fold_gutter = false 🔗
如果為 true,則會繪製折疊欄。該邊欄會為每個能夠折疊的行繪製 can_fold_code_region 圖示(見 can_fold_line()),已折疊的行則繪製 folded_code_region 圖示(見 is_line_folded())。點選這些圖示可以開關折疊狀態,見 toggle_foldable_line()。line_folding 為 true 才會顯示圖示。
bool gutters_draw_line_numbers = false 🔗
如果為 true,則會繪製行號欄。行號從 1 開始,逐行遞增。在行號欄中點選並拖動會選中整行文字。
int gutters_line_numbers_min_digits = 3 🔗
為行號欄預留的最小數字寬度。
bool gutters_zero_pad_line_numbers = false 🔗
如果為 true,在邊欄中繪製的行號會根據總行數用零填充。gutters_draw_line_numbers 須為 true。
bool indent_automatic = false 🔗
如果為 true,新增新行並且存在 indent_automatic_prefixes 中的前綴時會自動插入一級額外的縮進。如果存在括號對中的左括號,就會將對應的右括號移動到新的一行(見 auto_brace_completion_pairs)。
Array[String] indent_automatic_prefixes = [":", "{", "[", "("] 🔗
觸發自動縮進的前綴。indent_automatic 為 true 時使用。
制表縮進的大小(按一次 Tab),以字元為單位。如果啟用 indent_use_spaces,則代表使用的空白數。
bool indent_use_spaces = false 🔗
使用空格代替定位字元進行縮進。
如果為 true,則可以折疊行。否則 fold_line() 等與行折疊相關的方法將無法工作,並且 can_fold_line() 將始終回傳 false。見 gutters_draw_fold_gutter。
Array[int] line_length_guidelines = [] 🔗
在提供的列上繪製垂直線。第一個條目被認為是主要的硬參考線,會繪製得更顯眼。
bool symbol_lookup_on_click = false 🔗
設定當來自 symbol_validate 的驗證詞被點選時,應發出 symbol_lookup。
bool symbol_tooltip_on_hover = false 🔗
如果為 true,則懸停在單詞上時會發出 symbol_hovered 訊號。
方法說明
void _confirm_code_completion(replace: bool) virtual 🔗
覆蓋此方法以定義所選條目應如何插入。如果 replace 為 true,任何現有的文字都應該被替換。
Array[Dictionary] _filter_code_completion_candidates(candidates: Array[Dictionary]) virtual const 🔗
覆蓋此方法以確定應該顯示 candidates 中的哪些項。
參數 candidates 和回傳值都是一個 Array 的 Dictionary,而 Dictionary 的鍵值,詳見 get_code_completion_option()。
void _request_code_completion(force: bool) virtual 🔗
覆蓋此方法以定義當使用者請求程式碼完成時發生的情況。如果 force 為 true,會繞過任何檢查。
void add_auto_brace_completion_pair(start_key: String, end_key: String) 🔗
新增一對括弧。
開始和結束鍵都必須是符號。只有開始鍵必須是唯一的。
void add_code_completion_option(type: CodeCompletionKind, display_text: String, insert_text: String, text_color: Color = Color(1, 1, 1, 1), icon: Resource = null, value: Variant = null, location: int = 1024) 🔗
向自動補全功能表的潛在候選佇列提交條目。請呼叫 update_code_completion_options() 來更新列表。
location 指示的是該選項相對於程式碼補全請求位置的位置。這個值如何設定見 CodeCompletionLocation。
注意:這個列表將替換所有目前候選。
void add_comment_delimiter(start_key: String, end_key: String, line_only: bool = false) 🔗
新增從 start_key 到 end_key 的注釋分隔符。兩個鍵都應該是符號,並且 start_key 不得與其他分隔符共享。
如果 line_only 為 true 或 end_key 為空 String,則該區塊不會延續到下一行。
void add_string_delimiter(start_key: String, end_key: String, line_only: bool = false) 🔗
定義從 start_key 到 end_key 的字串分隔符。兩個鍵都應該是符號,並且 start_key 不得與其他分隔符共享。
如果 line_only 為 true 或 end_key 為空 String,則該區塊不會延續到下一行。
bool can_fold_line(line: int) const 🔗
如果給定的行可折疊則回傳 true。可折疊的情況有:這一行是有效程式碼區塊的開頭(見 get_code_region_start_tag()),這一行是注釋或字串塊的開頭,以及後續非空行的縮處理程序度更高(見 TextEdit.get_indent_level())。
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(replace: bool = false) 🔗
將選定的條目插入到文字中。如果 replace 為 true,任何現有的文字都會被替換,而不是被合併。
void convert_indent(from_line: int = -1, to_line: int = -1) 🔗
將 from_line 和 to_line 之間的行縮進,轉換為 indent_use_spaces 設定的定位字元或空格。
值均為 -1 將轉換整個文字。
void create_code_region() 🔗
使用選擇建立一個新的程式碼區域。至少必須定義一個單行註解分隔符號(請參閱add_comment_delimiter())。
程式碼區域是程式碼的一部分,在折疊時會被反白顯示,可以幫助組織腳本。
程式碼區域的開始和結束標記可以自訂(請參閱set_code_region_tags())。
程式碼區域使用開始和結束標記(預設分別為 region 和 endregion)進行分隔,前面有一行註解分隔符號。 (例如 #region 和 #endregion)
void delete_lines() 🔗
刪除所選行以及有游標停留的行。
void do_indent() 🔗
如果沒有選中內容,則在游標處插入縮進。否則會將所選行縮進一級,與 indent_lines() 類似。等價於 ProjectSettings.input/ui_text_indent 動作。所使用的縮進字元取決於 indent_use_spaces 和 indent_size。
void duplicate_lines() 🔗
複製所有目前使用任何脫字元號選擇的行。無論脫字元號位於行內的何處,複製目前行下方的整行。
void duplicate_selection() 🔗
製作所有選中文字的副本並製作所有游標所在行的副本。
void fold_all_lines() 🔗
折疊所有可能被折疊的行(參見 can_fold_line())。
如果可能,折疊給定的行(參見 can_fold_line())。
String get_auto_brace_completion_close_key(open_key: String) const 🔗
取得 open_key 相配對的括弧自動閉合鍵。
PackedInt32Array get_bookmarked_lines() const 🔗
取得所有書籤行。
PackedInt32Array get_breakpointed_lines() const 🔗
取得所有中斷點行。
Dictionary get_code_completion_option(index: int) const 🔗
取得在 index 處的補全選項。返回的 Dictionary 有以下鍵值。
kind:CodeCompletionKind
display_text :在自動補全功能表上顯示的文字。
insert_text :當選中這個選項時要插入的文字。
font_color:自動補全功能表上文字的顏色。
icon :在自動補全功能表上繪製的圖示。
default_value:符號的值。
Array[Dictionary] get_code_completion_options() const 🔗
取得所有補全選項,返回值見 get_code_completion_option()。
int get_code_completion_selected_index() const 🔗
取得目前已選定補全項的索引。
String get_code_region_end_tag() const 🔗
返回該地區的導覽層。
String get_code_region_start_tag() const 🔗
返回選區的原始起始列。
String get_delimiter_end_key(delimiter_index: int) const 🔗
取得字串或注釋塊索引的結束鍵。
Vector2 get_delimiter_end_position(line: int, column: int) const 🔗
如果 line column 是在一個字串或注釋中,則返回該區域的結束位元置。如果不在或未找到結束位置,則 Vector2 的兩個值都將是 -1 。
String get_delimiter_start_key(delimiter_index: int) const 🔗
取得字串或注釋塊索引的開始鍵。
Vector2 get_delimiter_start_position(line: int, column: int) const 🔗
如果 line column 是在一個字串或注釋中,則返回該區域的起始位元置。如果不在或未找到開始位置,則 Vector2 的兩個值都將是 -1 。
PackedInt32Array get_executing_lines() const 🔗
取得所有正在執行的行。
Array[int] get_folded_lines() const 🔗
回傳目前所有折疊的行。
String get_text_for_code_completion() const 🔗
返回在插入符號位置帶有 0xFFFF 字元的全文。
String get_text_for_symbol_lookup() const 🔗
返回在游標位置處帶有 0xFFFF 字元的全文。
String get_text_with_cursor_char(line: int, column: int) const 🔗
返回在插入符號位置帶有 0xFFFF 字元的全文。
bool has_auto_brace_completion_close_key(close_key: String) const 🔗
如果關閉鍵 close_key 存在,則返回 true。
bool has_auto_brace_completion_open_key(open_key: String) const 🔗
如果打開鍵 open_key 存在,則返回 true。
bool has_comment_delimiter(start_key: String) const 🔗
如果注釋的 start_key 存在,返回 true 。
bool has_string_delimiter(start_key: String) const 🔗
如果字串的 start_key 存在,返回 true 。
void indent_lines() 🔗
縮進所有選中的行或游標所在的行。使用空白還是制表符取決於 indent_use_spaces。見 unindent_lines()。
int is_in_comment(line: int, column: int = -1) const 🔗
如果 line column 在一條注釋中,則返回分隔符號索引。如果沒有提供 column,且整個 line 是一條注釋,則將返回分隔符號索引。否則返回 -1。
int is_in_string(line: int, column: int = -1) const 🔗
如果 line column 在一條字串中,則返回分隔符號索引。如果沒有提供 column,且整個 line 是一個字串,則將返回分隔符號索引。否則返回 -1。
bool is_line_bookmarked(line: int) const 🔗
如果給定的行設定了書籤,則回傳 true。見 set_line_as_bookmarked()。
bool is_line_breakpointed(line: int) const 🔗
如果給定的行設定了斷點,則回傳 true。見 set_line_as_breakpoint()。
bool is_line_code_region_end(line: int) const 🔗
如果給定的行是程式碼區塊的結尾,則回傳 true。見 set_code_region_tags()。
bool is_line_code_region_start(line: int) const 🔗
如果給定的行是程式碼區塊的開頭,則回傳 true。見 set_code_region_tags()。
bool is_line_executing(line: int) const 🔗
如果給定的行被標記為正在執行,則回傳 true。見 set_line_as_executing()。
bool is_line_folded(line: int) const 🔗
如果給定的行已折疊,則回傳 true。見 fold_line()。
void join_lines(line_ending: String = " ") 🔗
將所有選中的行,或者包含游標的行,與其下一行合併。行間的空白字元將被移除。如果下一行含有內容,則會在兩行之間插入 line_ending。
void move_lines_down() 🔗
將所選行以及有游標停留的行向下移動。
void move_lines_up() 🔗
將所選行以及有游標停留的行向上移動。
void remove_comment_delimiter(start_key: String) 🔗
移除帶有 start_key 的注釋分隔符號。
void remove_string_delimiter(start_key: String) 🔗
移除帶有 start_key 的字串分隔符號。
void request_code_completion(force: bool = false) 🔗
發出 code_completion_requested,如果 force 為 true 則會繞過所有檢查。否則,將檢查游標是否在一個詞中或在一個前綴的前面。如果目前所有選項都是檔案路徑、節點路徑或訊號型別,將忽略該請求。
void set_code_completion_selected_index(index: int) 🔗
設定目前選定的補全選項。
void set_code_hint(code_hint: String) 🔗
設定程式碼提示文字。傳遞一個空字串來清除。
void set_code_hint_draw_below(draw_below: bool) 🔗
如果為 true,則會在主游標下方繪製程式碼提示。如果為 false,則會在主游標上方繪製程式碼提示。見 set_code_hint()。
void set_code_region_tags(start: String = "region", end: String = "endregion") 🔗
設定程式碼區域開始和結束標記(無註解分隔符號)。
void set_line_as_bookmarked(line: int, bookmarked: bool) 🔗
為給定的行設定書籤。如果為 true 並且 gutters_draw_bookmarks 為 true,則會在邊欄中為該行繪製 bookmark 圖示。見 get_bookmarked_lines() 和 is_line_bookmarked()。
void set_line_as_breakpoint(line: int, breakpointed: bool) 🔗
為給定的行設定斷點。如果為 true 並且 gutters_draw_breakpoints_gutter 為 true,則會在邊欄中為該行繪製 breakpoint 圖示。見 get_breakpointed_lines() 和 is_line_breakpointed()。
void set_line_as_executing(line: int, executing: bool) 🔗
將給定的行設定為正在執行。如果為 true 並且 gutters_draw_executing_lines 為 true,則會在邊欄中為該行繪製 executing_line 圖示。見 get_executing_lines() 和 is_line_executing()。
void set_symbol_lookup_word_as_valid(valid: bool) 🔗
將 symbol_validate 發出的符號設定為有效搜尋。
void toggle_foldable_line(line: int) 🔗
在給定行切換程式碼塊的折疊。
void toggle_foldable_lines_at_carets() 🔗
在所有帶有游標的行上切換程式碼塊的折疊。
void unfold_all_lines() 🔗
展開所有已折疊的行。
如果給定的行處於折疊狀態,或被隱藏在折疊行下,則展開該行。
void unindent_lines() 🔗
將所選行或游標所在行取消一級縮進。會根據 indent_use_spaces 決定使用空白還是制表符。等價於 ProjectSettings.input/ui_text_dedent 動作。見 indent_lines()。
void update_code_completion_options(force: bool) 🔗
提交所有用 add_code_completion_option() 新增的補全選項。如果 force 是 true,將嘗試強制彈出自動補全功能表 。
注意:這將取代所有目前的候補選項。
主題屬性說明
Color bookmark_color = Color(0.5, 0.64, 1, 0.8) 🔗
書籤圖示的 Color,用於標記了書籤的行。
Color brace_mismatch_color = Color(1, 0.2, 0.2, 1) 🔗
用於高亮不配對括弧文字的 Color。
Color breakpoint_color = Color(0.9, 0.29, 0.3, 1) 🔗
書籤行的中斷點圖示的 Color。
Color code_folding_color = Color(0.8, 0.8, 0.8, 0.8) 🔗
所有與折疊行相關的圖示的 Color。
Color completion_background_color = Color(0.17, 0.16, 0.2, 1) 🔗
設定程式碼補全快顯視窗的背景色 Color。
Color completion_existing_color = Color(0.87, 0.87, 0.87, 0.13) 🔗
用於配對程式碼補全選項中的文字的背景高亮的 Color。
Color completion_scroll_color = Color(1, 1, 1, 0.29) 🔗
程式碼補全快顯視窗中捲軸的 Color。
Color completion_scroll_hovered_color = Color(1, 1, 1, 0.4) 🔗
程式碼補全快顯視窗中捲軸在懸停狀態的 Color。
Color completion_selected_color = Color(0.26, 0.26, 0.27, 1) 🔗
程式碼補全快顯視窗中,目前選定選項的背景高亮的 Color。
Color executing_line_color = Color(0.98, 0.89, 0.27, 1) 🔗
執行行執行圖示的 Color。
Color folded_code_region_color = Color(0.68, 0.46, 0.77, 0.2) 🔗
折疊程式碼區域的背景線所反白的Color。
Color line_length_guideline_color = Color(0.3, 0.5, 0.8, 0.1) 🔗
主行長度輔助線的 Color,次要輔助線將套用 50% 的 Alpha。
Color line_number_color = Color(0.67, 0.67, 0.67, 0.4) 🔗
設定行號的顏色 Color。
同時在程式碼補全快顯視窗中顯示的最大選項數。
int completion_max_width = 50 🔗
程式碼補全彈出視窗中選項的最大寬度。超過此長度的選項將被截斷。
int completion_scroll_width = 6 🔗
程式碼補全快顯視窗中捲軸的寬度。
設定書籤行的自訂 Texture2D,會在書籤欄中繪製。
設定中斷點行的自訂 Texture2D,會在中斷點欄中繪製。
設定可折疊行的自訂 Texture2D,會在折疊行欄中繪製。
Texture2D can_fold_code_region 🔗
設定可折疊行的自訂 Texture2D,會在折疊行欄中繪製。
Texture2D completion_color_bg 🔗
自動補全時顏色預覽框的背景面板(顏色半透明時可見)。
執行行的圖示,會在執行欄中繪製。
當行被折疊且可以展開時,設定要在行折疊裝訂線中繪製的一個自訂 Texture2D。
Texture2D folded_code_region 🔗
當行被折疊且可以展開時,設定要在行折疊裝訂線中繪製的一個自訂 Texture2D。
設定要繪製在折疊行末尾的一個自訂 Texture2D。
用於程式碼補全彈窗的 StyleBox。