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...
TextEdit
繼承: Control < CanvasItem < Node < Object
被繼承: CodeEdit
多行文字編輯器。
說明
多行文字編輯器,還提供了一部分用於編輯程式碼的工具,例如對語法醒目標示的支援。如果需要更進階的程式碼編輯工具,見 CodeEdit。
輸入文字時,可以使用 Unicode、OEM、Windows Alt 程式碼來插入特殊字元:
輸入 Unicode 碼位時,請按住 Alt 並通過小鍵盤輸入碼位。例如要輸入字元
á(U+00E1),請按住 Alt 並使用小鍵盤輸入 +E1(前置的零可以省略)。輸入 OEM 碼位時,請按住 Alt 並通過小鍵盤輸入碼位。例如要輸入字元
á(OEM 160),請按住 Alt 並使用小鍵盤輸入160。輸入 Windows 碼位時,請按住 Alt 並通過小鍵盤輸入碼位。例如要輸入字元
á(Windows 0225)請按住 Alt 並使用小鍵盤輸入 0、2、2、5 。前置的零不能省略,因為 Windows 碼位需要用這些零來和 OEM 碼位進行區分。
注意:大多數與視埠、文字游標、編輯相關的方法都包含一個名叫 caret_index 的游標索引參數,用於支援 caret_multiple。該參數的取值應為:-1 表示所有游標,0 表示主游標,大於 0 表示次級游標,取建立順序。
注意:按住 Alt 時,垂直滾輪的捲動速度為原來的 5 倍。同樣適用於 Godot 的腳本編輯器。
屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
focus_mode |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
mouse_default_cursor_shape |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
void |
_backspace(caret_index: int) virtual |
void |
|
void |
|
void |
_handle_unicode_input(unicode_char: int, caret_index: int) virtual |
void |
|
void |
_paste_primary_clipboard(caret_index: int) virtual |
void |
add_caret_at_carets(below: bool) |
void |
add_gutter(at: int = -1) |
void |
|
void |
adjust_carets_after_edit(caret: int, from_line: int, from_col: int, to_line: int, to_col: int) |
void |
adjust_viewport_to_caret(caret_index: int = 0) |
void |
|
void |
|
void |
|
void |
|
void |
|
void |
center_viewport_to_caret(caret_index: int = 0) |
void |
clear() |
void |
|
void |
collapse_carets(from_line: int, from_column: int, to_line: int, to_column: int, inclusive: bool = false) |
void |
|
void |
|
void |
delete_selection(caret_index: int = -1) |
void |
|
void |
|
void |
|
void |
|
get_caret_column(caret_index: int = 0) const |
|
get_caret_count() const |
|
get_caret_draw_pos(caret_index: int = 0) const |
|
get_caret_line(caret_index: int = 0) const |
|
get_caret_wrap_index(caret_index: int = 0) const |
|
get_first_non_whitespace_column(line: int) const |
|
get_first_visible_line() const |
|
get_gutter_count() const |
|
get_gutter_name(gutter: int) const |
|
get_gutter_type(gutter: int) const |
|
get_gutter_width(gutter: int) const |
|
get_h_scroll_bar() const |
|
get_indent_level(line: int) const |
|
get_last_full_visible_line() const |
|
get_last_unhidden_line() const |
|
get_line_background_color(line: int) const |
|
get_line_column_at_pos(position: Vector2i, clamp_line: bool = true, clamp_column: bool = true) const |
|
get_line_count() const |
|
get_line_gutter_icon(line: int, gutter: int) const |
|
get_line_gutter_item_color(line: int, gutter: int) const |
|
get_line_gutter_metadata(line: int, gutter: int) const |
|
get_line_gutter_text(line: int, gutter: int) const |
|
get_line_height() const |
|
get_line_ranges_from_carets(only_selections: bool = false, merge_adjacent: bool = true) const |
|
get_line_width(line: int, wrap_index: int = -1) const |
|
get_line_with_ime(line: int) const |
|
get_line_wrap_count(line: int) const |
|
get_line_wrap_index_at_column(line: int, column: int) const |
|
get_line_wrapped_text(line: int) const |
|
get_local_mouse_pos() const |
|
get_menu() const |
|
get_minimap_line_at_pos(position: Vector2i) const |
|
get_minimap_visible_lines() const |
|
get_next_composite_character_column(line: int, column: int) const |
|
get_next_visible_line_index_offset_from(line: int, wrap_index: int, visible_amount: int) const |
|
get_next_visible_line_offset_from(line: int, visible_amount: int) const |
|
get_pos_at_line_column(line: int, column: int) const |
|
get_previous_composite_character_column(line: int, column: int) const |
|
get_rect_at_line_column(line: int, column: int) const |
|
get_saved_version() const |
|
get_scroll_pos_for_line(line: int, wrap_index: int = 0) const |
|
get_selected_text(caret_index: int = -1) |
|
get_selection_at_line_column(line: int, column: int, include_edges: bool = true, only_selections: bool = true) const |
|
get_selection_column(caret_index: int = 0) const |
|
get_selection_from_column(caret_index: int = 0) const |
|
get_selection_from_line(caret_index: int = 0) const |
|
get_selection_line(caret_index: int = 0) const |
|
get_selection_mode() const |
|
get_selection_origin_column(caret_index: int = 0) const |
|
get_selection_origin_line(caret_index: int = 0) const |
|
get_selection_to_column(caret_index: int = 0) const |
|
get_selection_to_line(caret_index: int = 0) const |
|
get_sorted_carets(include_ignored_carets: bool = false) const |
|
get_tab_size() const |
|
get_total_gutter_width() const |
|
get_total_visible_line_count() const |
|
get_v_scroll_bar() const |
|
get_version() const |
|
get_visible_line_count() const |
|
get_visible_line_count_in_range(from_line: int, to_line: int) const |
|
get_word_at_pos(position: Vector2) const |
|
get_word_under_caret(caret_index: int = -1) const |
|
has_ime_text() const |
|
has_redo() const |
|
has_selection(caret_index: int = -1) const |
|
has_undo() const |
|
void |
insert_line_at(line: int, text: String) |
void |
insert_text(text: String, line: int, column: int, before_selection_begin: bool = true, before_selection_end: bool = false) |
void |
insert_text_at_caret(text: String, caret_index: int = -1) |
is_caret_after_selection_origin(caret_index: int = 0) const |
|
is_caret_visible(caret_index: int = 0) const |
|
is_dragging_cursor() const |
|
is_gutter_clickable(gutter: int) const |
|
is_gutter_drawn(gutter: int) const |
|
is_gutter_overwritable(gutter: int) const |
|
is_in_mulitcaret_edit() const |
|
is_line_gutter_clickable(line: int, gutter: int) const |
|
is_line_in_viewport(line: int) const |
|
is_line_wrapped(line: int) const |
|
is_menu_visible() const |
|
is_mouse_over_selection(edges: bool, caret_index: int = -1) const |
|
is_overtype_mode_enabled() const |
|
void |
menu_option(option: int) |
void |
merge_gutters(from_line: int, to_line: int) |
void |
|
multicaret_edit_ignore_caret(caret_index: int) const |
|
void |
|
void |
paste_primary_clipboard(caret_index: int = -1) |
void |
redo() |
void |
remove_caret(caret: int) |
void |
remove_gutter(gutter: int) |
void |
remove_line_at(line: int, move_carets_down: bool = true) |
void |
|
void |
remove_text(from_line: int, from_column: int, to_line: int, to_column: int) |
search(text: String, flags: int, from_line: int, from_column: int) const |
|
void |
select(origin_line: int, origin_column: int, caret_line: int, caret_column: int, caret_index: int = 0) |
void |
|
void |
select_word_under_caret(caret_index: int = -1) |
void |
set_caret_column(column: int, adjust_viewport: bool = true, caret_index: int = 0) |
void |
set_caret_line(line: int, adjust_viewport: bool = true, can_be_hidden: bool = true, wrap_index: int = 0, caret_index: int = 0) |
void |
set_gutter_clickable(gutter: int, clickable: bool) |
void |
set_gutter_custom_draw(column: int, draw_callback: Callable) |
void |
set_gutter_draw(gutter: int, draw: bool) |
void |
set_gutter_name(gutter: int, name: String) |
void |
set_gutter_overwritable(gutter: int, overwritable: bool) |
void |
set_gutter_type(gutter: int, type: GutterType) |
void |
set_gutter_width(gutter: int, width: int) |
void |
|
void |
set_line_as_center_visible(line: int, wrap_index: int = 0) |
void |
set_line_as_first_visible(line: int, wrap_index: int = 0) |
void |
set_line_as_last_visible(line: int, wrap_index: int = 0) |
void |
set_line_background_color(line: int, color: Color) |
void |
set_line_gutter_clickable(line: int, gutter: int, clickable: bool) |
void |
set_line_gutter_icon(line: int, gutter: int, icon: Texture2D) |
void |
set_line_gutter_item_color(line: int, gutter: int, color: Color) |
void |
set_line_gutter_metadata(line: int, gutter: int, metadata: Variant) |
void |
set_line_gutter_text(line: int, gutter: int, text: String) |
void |
set_overtype_mode_enabled(enabled: bool) |
void |
set_search_flags(flags: int) |
void |
set_search_text(search_text: String) |
void |
set_selection_mode(mode: SelectionMode) |
void |
set_selection_origin_column(column: int, caret_index: int = 0) |
void |
set_selection_origin_line(line: int, can_be_hidden: bool = true, wrap_index: int = -1, caret_index: int = 0) |
void |
set_tab_size(size: int) |
void |
set_tooltip_request_func(callback: Callable) |
void |
|
void |
start_action(action: EditAction) |
void |
swap_lines(from_line: int, to_line: int) |
void |
|
void |
undo() |
主題屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
訊號
caret_changed() 🔗
當任何游標改變位置時發出。
gutter_added() 🔗
新增邊欄時發出。
gutter_clicked(line: int, gutter: int) 🔗
點選邊欄時發出。
gutter_removed() 🔗
移除邊欄時發出。
lines_edited_from(from_line: int, to_line: int) 🔗
文字改變時立即發出。
新增文字時 from_line 小於 to_line。移除文字時 to_line 小於 from_line。
text_changed() 🔗
當文字更改時觸發。
text_set() 🔗
列舉
剪切(複製並刪除)選中的文字。
複製選中的文字。
將剪貼簿上的文字貼上在選定的文字上(或游標的位置)。
擦除整個 TextEdit 文字。
選擇整個 TextEdit 文字。
復原之前的操作。
重做前一個動作。
“文字書寫方向”子功能表的 ID。
將文字方向設定為繼承。
將文字方向設定為自動。
將文字方向設定為從左至右。
將文字方向設定為從右至左。
切換控制字元的顯示。
“插入控制字元”子功能表的 ID。
插入從左至右旗標(LRM)字元。
插入從右至左旗標(LRM)字元。
插入開始從左至右嵌入(LRE)字元。
插入開始從右至左嵌入(RLE)字元。
插入開始從左至右強制(LRO)字元。
插入開始從右至左嵌入(RLE)字元。
插入退出方向格式化(PDF)字元。
插入阿拉伯字母標記(ALM)字元。
插入從左至右隔離(LRI)字元。
插入從右至左隔離(RLI)字元。
插入第一個強隔離(FSI)字元。
插入退出方向隔離(PDI)字元。
插入零寬連接子(ZWJ)字元。
插入零寬非連接子(ZWNJ)字元。
插入文字連接子(WJ)字元。
插入軟連字號(SHY)字元。
打開系統 Emoji 和符號拾取器。
代表 MenuItems 列舉的大小。
enum EditAction: 🔗
EditAction ACTION_NONE = 0
無目前動作。
EditAction ACTION_TYPING = 1
打字動作。
EditAction ACTION_BACKSPACE = 2
向後刪除動作。
EditAction ACTION_DELETE = 3
向前刪除動作。
enum SearchFlags: 🔗
SearchFlags SEARCH_MATCH_CASE = 1
搜尋時配對大小寫。
SearchFlags SEARCH_WHOLE_WORDS = 2
搜尋時配對整個單詞。
SearchFlags SEARCH_BACKWARDS = 4
從頭到尾搜尋。
enum CaretType: 🔗
CaretType CARET_TYPE_LINE = 0
垂直線游標。
CaretType CARET_TYPE_BLOCK = 1
方塊游標。
enum SelectionMode: 🔗
SelectionMode SELECTION_MODE_NONE = 0
不選擇。
SelectionMode SELECTION_MODE_SHIFT = 1
就像按下 shift 一樣進行選擇。
SelectionMode SELECTION_MODE_POINTER = 2
選擇單個字元,就像使用者按一下一樣。
SelectionMode SELECTION_MODE_WORD = 3
選擇整個單詞,就像使用者雙擊一樣。
SelectionMode SELECTION_MODE_LINE = 4
選擇整行文字,就像使用者三擊一樣。
enum LineWrappingMode: 🔗
LineWrappingMode LINE_WRAPPING_NONE = 0
換行被停用。
LineWrappingMode LINE_WRAPPING_BOUNDARY = 1
換行發生在控制項邊界,超出通常可見的範圍。
enum GutterType: 🔗
GutterType GUTTER_TYPE_STRING = 0
當使用 set_gutter_type() 將邊欄設定為字串時,它被用於包含通過 set_line_gutter_text() 方法設定的文字。
GutterType GUTTER_TYPE_ICON = 1
當使用 set_gutter_type() 將邊欄設定為圖示時,它被用於包含通過 set_line_gutter_icon() 方法設定的圖示。
GutterType GUTTER_TYPE_CUSTOM = 2
當使用 set_gutter_type() 將邊欄設定為自訂時,它被用於包含由通過 set_gutter_custom_draw() 方法設定的回呼方法控制的自訂視覺效果。
屬性說明
AutowrapMode autowrap_mode = 3 🔗
void set_autowrap_mode(value: AutowrapMode)
AutowrapMode get_autowrap_mode()
如果 wrap_mode 設定為 LINE_WRAPPING_BOUNDARY,則設定文字換行模式。
bool backspace_deletes_composite_character_enabled = false 🔗
void set_backspace_deletes_composite_character_enabled(value: bool)
bool is_backspace_deletes_composite_character_enabled()
如果為 true 且 caret_mid_grapheme 為 false,則退格鍵會刪除完整的組合字元,例如 ❤️🩹,而不是刪除組合字元中的一部分。
如果為 true,則文字游標會閃爍。
float caret_blink_interval = 0.65 🔗
文字游標的閃爍間隔(單位為秒)。
bool caret_draw_when_editable_disabled = false 🔗
void set_draw_caret_when_editable_disabled(value: bool)
bool is_drawing_caret_when_editable_disabled()
如果為 true,則停用 editable 時游標可見。
bool caret_mid_grapheme = false 🔗
允許在單個複合字元的元件中進行移動游標、選中、刪除的操作。
注意:倒退鍵 Backspace 始終按複合字元的元件刪除。
bool caret_move_on_right_click = true 🔗
如果為 true,則按一下右鍵時會先將文字游標移動到滑鼠位置,然後再顯示情境選單。
如果為 false,則情境選單將忽略滑鼠位置。
如果為 true,則允許多游標。按住 Alt 按一下左鍵會新增一個新的游標。見 add_caret() 和 get_caret_count()。
設定要繪製的文字游標的型別。
為 true 時按右鍵會顯示本文功能表。
String custom_word_separators = "" 🔗
use_custom_word_separators 為 true 時作為分詞符的字元。定義時,字元之間不應留空,例如 #_!。
bool deselect_on_focus_loss_enabled = true 🔗
如果為 true,則在丟失焦點時會取消選中文字。
bool drag_and_drop_selection_enabled = true 🔗
如果為 true,則允許拖放選中的文字。文字仍可從其他來源拖放。
bool draw_control_chars = false 🔗
如果為 true,則會顯示控制字元。
如果為 true,“空格”字元將具有可見表示形式。
如果為 true,“定位字元”字元將具有可見表示形式。
如果為 false,則不能修改現在的文字,也不能新增新文字。
如果為 true,則啟用“Emoji 和符號”選單。
bool empty_selection_clipboard_enabled = true 🔗
如果為 true,未選中內容時進行複製或剪切會對游標所在行進行操作。否則需要先選中才能進行複製和剪切。
bool highlight_all_occurrences = false 🔗
如果為 true,所選文字的所有配對項都將突出顯示。
bool highlight_current_line = false 🔗
如果為 true,則包含游標的行會突出顯示。
bool indent_wrapped_lines = false 🔗
如果為 true,則所有換行的行都會縮進,縮進量與展開的行相同。
用於斷行和文字塑形算法的語言程式碼。如果留空,則使用目前區域設定。
bool middle_mouse_paste_enabled = true 🔗
如果為 false,將停用滑鼠中鍵貼上剪貼簿。
注意:這個方法只在 Linux 上實作。
如果為 true,則顯示小地圖,提供原始碼的概要。小地圖使用固定寬度的文字大小。
小地圖的寬度(以圖元為單位)。
String placeholder_text = "" 🔗
TextEdit 為空時顯示的文字。它不是 TextEdit 的預設值(參見 text)。
bool scroll_fit_content_height = false 🔗
如果為 true,則 TextEdit 會根據可見行數調整其最小高度,而不是進行垂直捲動。如果設定了最大高度(例如通過 Control.custom_maximum_size),且內容超出該高度,則會顯示垂直捲動條。
bool scroll_fit_content_width = false 🔗
如果為 true,則 TextEdit 會根據最長的一行文字調整其最小寬度,而不是進行水平捲動。如果設定了最大寬度(例如通過 Control.custom_maximum_size),且內容超出該寬度,則會顯示水平捲動條。
如果有一個水平捲軸,這決定了目前的水平捲動值,單位是圖元。
bool scroll_past_end_of_file = false 🔗
允許捲動過最後一行,進入“虛擬”空間。
在文字上平滑捲動,而不是跳到下一個位置。
float scroll_v_scroll_speed = 80.0 🔗
設定使用小地圖或當 scroll_smooth 被啟用時的捲動速度。
如果有一個垂直捲動條,這就決定了目前的垂直捲動值,以行數為單位,頂行從0開始。
bool selecting_enabled = true 🔗
如果為 true,文字可以被選擇。
如果為 false,使用者或使用select()或select_all()方法都不能選擇文字。
bool shortcut_keys_enabled = true 🔗
為 true 時,即使本文選單已被停用,也會啟用該本文選單的快捷鍵。
StructuredTextParser structured_text_bidi_override = 0 🔗
void set_structured_text_bidi_override(value: StructuredTextParser)
StructuredTextParser get_structured_text_bidi_override()
為結構化文字設定 BiDi 演算法覆蓋。
Array structured_text_bidi_override_options = [] 🔗
void set_structured_text_bidi_override_options(value: Array)
Array get_structured_text_bidi_override_options()
設定 BiDi 覆蓋的附加選項。
SyntaxHighlighter syntax_highlighter 🔗
void set_syntax_highlighter(value: SyntaxHighlighter)
SyntaxHighlighter get_syntax_highlighter()
要使用的語法醒目標示器。
注意:不應在多個 TextEdit 節點間共享 SyntaxHighlighter 實例。
如果為 true,則 ProjectSettings.input/ui_text_indent 會輸入 Tab 字元,否則會讓鍵盤焦點移至場景中的下一個 Control。
TextEdit 的字串值。
TextDirection text_direction = 0 🔗
void set_text_direction(value: TextDirection)
TextDirection get_text_direction()
基礎文字書寫方向。
bool use_custom_word_separators = false 🔗
如果為 false,使用 Ctrl + Left 或 Ctrl + Right(macOS 上為 Cmd + Left 或 Cmd + Right)綁定將使用 use_default_word_separators 的行為。如果為 true,如果檢測到 custom_word_separators 內的字元,它還將停止文字游標。對於子詞移動很有用。該行為也將套用至文字選擇的行為。
bool use_default_word_separators = true 🔗
如果為 false,使用 Ctrl + Left 或 Ctrl + Right(macOS 上為 Cmd + Left 或 Cmd + Right)綁定,僅當檢測到空白或標點符號時才會停止移動文字游標。如果為 true,當字元屬於 !"#$%&'()*+,-./:;<=>?@[\]^`{|}~、Unicode 通用標點符號表或 Unicode CJK 標點符號表時,它也會停止文字游標。對於子詞移動很有用。該行為也將套用至文字選擇行為。
bool virtual_keyboard_enabled = true 🔗
如果為 true,則會在支援的平台上啟用原生虛擬鍵盤。
bool virtual_keyboard_show_on_focus = true 🔗
如果為 true,則在收到獲得焦點事件時會在支援的平台上顯示原生虛擬鍵盤。
LineWrappingMode wrap_mode = 0 🔗
void set_line_wrapping_mode(value: LineWrappingMode)
LineWrappingMode get_line_wrapping_mode()
設定要使用的換行模式。
方法說明
void _backspace(caret_index: int) virtual 🔗
覆蓋此方法可以定義使用者按下倒退鍵時應該發生什麼。
void _copy(caret_index: int) virtual 🔗
覆蓋此方法可以定義使用者執行複製操作時應該發生什麼。
void _cut(caret_index: int) virtual 🔗
覆蓋此方法可以定義使用者執行剪切操作時應該發生什麼。
void _handle_unicode_input(unicode_char: int, caret_index: int) virtual 🔗
覆蓋此方法可以定義使用者打出所提供的鍵 unicode_char 時應該發生什麼。
void _paste(caret_index: int) virtual 🔗
覆蓋此方法可以定義使用者執行貼上操作時應該發生什麼。
void _paste_primary_clipboard(caret_index: int) virtual 🔗
覆蓋此方法可以定義使用者使用滑鼠中鍵執行貼上操作時應該發生什麼。
注意:此方法僅在 Linux 上實作。
int add_caret(line: int, column: int) 🔗
在給定的位置新增新的游標。返回新游標的索引,如果位置無效則返回 -1。
void add_caret_at_carets(below: bool) 🔗
在每個游標上方或下方新增一個額外的游標。如果 below 為 true,則會在下方新增新游標,否則為上方。
void add_gutter(at: int = -1) 🔗
為這個 TextEdit 註冊一個新的邊欄。請使用 at 指定邊欄的順序。-1 會將該邊欄追加到右側。
void add_selection_for_next_occurrence() 🔗
選中目前所選內容下一次出現的位置並新增文字游標。如果沒有活動的選中內容,則選中目前游標所處的單詞。
void adjust_carets_after_edit(caret: int, from_line: int, from_col: int, to_line: int, to_col: int) 🔗
已棄用: No longer necessary since methods now adjust carets themselves.
這個方法甚麼也不做。
void adjust_viewport_to_caret(caret_index: int = 0) 🔗
調整視埠,讓游標可見。
void apply_ime() 🔗
為所有游標應用輸入法編輯器中的文字,如果輸入法編輯器處於打開狀態,還會將其關閉。
void backspace(caret_index: int = -1) 🔗
使用者按下倒退鍵時呼叫。可以用 _backspace() 覆蓋。
void begin_complex_operation() 🔗
開始一個多部分編輯。在呼叫 end_complex_operation() 之前,所有編輯都將被視為一個動作。
void begin_multicaret_edit() 🔗
開始對多個游標進行編輯。編輯必須以 end_multicaret_edit() 結束。多游標編輯可用於編輯多個游標處的文字,並將游標的合併延遲到末尾,因此游標索引不會立即受到影響。begin_multicaret_edit() 和 end_multicaret_edit() 可以巢狀,並且合併將發生在最後一個 end_multicaret_edit()。
begin_complex_operation()
begin_multicaret_edit()
for i in range(get_caret_count()):
if multicaret_edit_ignore_caret(i):
continue
# 邏輯在這裡。
end_multicaret_edit()
end_complex_operation()
void cancel_ime() 🔗
如果輸入法編輯器處於打開狀態,則會將其關閉。輸入法編輯器中的文字會丟失。
void center_viewport_to_caret(caret_index: int = 0) 🔗
將視埠居中在正在編輯的插入符號所在的行上。這也將 scroll_horizontal 值重設為 0。
void clear() 🔗
執行對 TextEdit 的完全重設,包括復原歷史。
void clear_undo_history() 🔗
清除復原歷史。
void collapse_carets(from_line: int, from_column: int, to_line: int, to_column: int, inclusive: bool = false) 🔗
將給定範圍內的所有游標折疊到 from_line 和 from_column 位置。
inclusive 套用至兩端。
如果 is_in_mulitcaret_edit() 為 true,則折疊的游標對於 multicaret_edit_ignore_caret() 將為 true。
如果任何游標被折疊,將呼叫 merge_overlapping_carets().
void copy(caret_index: int = -1) 🔗
複製目前選區。可以使用 _copy() 覆蓋。
void cut(caret_index: int = -1) 🔗
剪切目前選區。可以使用 _cut() 覆蓋。
void delete_selection(caret_index: int = -1) 🔗
刪除選定的文字。
void deselect(caret_index: int = -1) 🔗
取消目前選擇。
void end_action() 🔗
標記在 start_action() 開始的目前動作中步驟的末尾。
void end_complex_operation() 🔗
結束一個多部分編輯,該多部分編輯從 begin_complex_operation() 開始。如果在一個複雜動作之外呼叫,則將目前動作將被壓入復原/重做堆疊。
void end_multicaret_edit() 🔗
結束以 begin_multicaret_edit() 開始的多個游標的編輯。如果這是最後一個 end_multicaret_edit(),並且呼叫了 merge_overlapping_carets(),則游標將被合併。
int get_caret_column(caret_index: int = 0) const 🔗
返回編輯游標所在的列。
返回該 TextEdit 中的游標數。
Vector2 get_caret_draw_pos(caret_index: int = 0) const 🔗
返回游標的圖元繪製位置。
PackedInt32Array get_caret_index_edit_order() 🔗
已棄用: Carets no longer need to be edited in any specific order. If the carets need to be sorted, use get_sorted_carets() instead.
返回文字游標索引的列表,使用編輯順序,從下到上進行。編輯順序是 insert_text_at_caret() 等動作的套用順序。
int get_caret_line(caret_index: int = 0) const 🔗
返回編輯游標所在的行。
int get_caret_wrap_index(caret_index: int = 0) const 🔗
返回正編輯的文字游標所在的換行索引。
int get_first_non_whitespace_column(line: int) const 🔗
回傳給定的行中第一個包含非空白字元的列。如果只有空白字元,就會回傳字元總數。
int get_first_visible_line() const 🔗
返回第一個可見行。
int get_gutter_count() const 🔗
返回註冊的邊欄數量。
String get_gutter_name(gutter: int) const 🔗
返回給定索引處邊欄的名稱。
GutterType get_gutter_type(gutter: int) const 🔗
回傳給定索引處的邊欄的型別。邊欄可以包含圖示、文字或自訂視覺效果。
int get_gutter_width(gutter: int) const 🔗
返回給定索引處邊欄的寬度。
HScrollBar get_h_scroll_bar() const 🔗
設定該 TextEdit 所使用的 HScrollBar。
int get_indent_level(line: int) const 🔗
回傳給定行的縮進層級。縮進層級為行首空白和制表符的數量,制表符會考慮制表符的大小(見 get_tab_size())。
int get_last_full_visible_line() const 🔗
返回最後一個可見的行。獲得換行索引的話,使用 get_last_full_visible_line_wrap_index()。
int get_last_full_visible_line_wrap_index() const 🔗
返回最後一個可見行的最後一個可見換行索引。
返回整個 TextEdit 中最後一個未隱藏的行。
String get_line(line: int) const 🔗
返回特定行的文字。
Color get_line_background_color(line: int) const 🔗
回傳給定行的自訂背景色。如果沒有設定顏色則回傳 Color(0, 0, 0, 0)。
Vector2i get_line_column_at_pos(position: Vector2i, clamp_line: bool = true, clamp_column: bool = true) const 🔗
回傳給定位置處的行號和列號。回傳的向量中,x 是列號,y 是行號。
如果 clamp_line 為 false 且 position 位於最後一列的下方,則會回傳 Vector2i(-1, -1)。
如果 clamp_column 為 false 且 position 超出了所在行的列的範圍,則會回傳 Vector2i(-1, -1)。
返回文字中的行數。
Texture2D get_line_gutter_icon(line: int, gutter: int) const 🔗
回傳 gutter 中目前位於 line 的圖示。僅當邊欄型別為 GUTTER_TYPE_ICON 時才有效(請參閱 set_gutter_type())。
Color get_line_gutter_item_color(line: int, gutter: int) const 🔗
返回邊欄 gutter 中,目前位於 line 行的顏色。
Variant get_line_gutter_metadata(line: int, gutter: int) const 🔗
返回邊欄 gutter 中,目前位於 line 行的中繼資料。
String get_line_gutter_text(line: int, gutter: int) const 🔗
回傳 gutter 中目前位於 line 的文字。僅當邊欄型別為 GUTTER_TYPE_STRING 時才有效(請參閱 set_gutter_type())。
返回所有行中行高的最大值。
注意:返回值受 line_spacing 和 font_size 的影響。不會比 1 小。
Array[Vector2i] get_line_ranges_from_carets(only_selections: bool = false, merge_adjacent: bool = true) const 🔗
回傳行範圍的 Array,其中 x 是第一行,y 是最後一行。這些範圍內的所有行都將帶有游標或是選區的一部分。每行都只能屬於一個行範圍,即使它上面有多個游標。
如果選區的結束列(get_selection_to_column())位於列 0,則不會包含該行。如果選區在另一個選區結束後的行上開始,並且 merge_adjacent 為 true,或者它們在同一行上開始和結束,則一個行範圍將包含兩個選區。
int get_line_width(line: int, wrap_index: int = -1) const 🔗
返回位於 line 的 wrap_index 的圖元寬度。
String get_line_with_ime(line: int) const 🔗
回傳目前顯示的行文字,包括 IME 合成字串。
int get_line_wrap_count(line: int) const 🔗
返回給定行換行的次數。
int get_line_wrap_index_at_column(line: int, column: int) const 🔗
回傳給定行給定列的自動換行索引。範圍為 0 到 get_line_wrap_count()。
PackedStringArray get_line_wrapped_text(line: int) const 🔗
返回代表各個換行索引的 String 陣列。
Vector2 get_local_mouse_pos() const 🔗
返回針對文字方向調整過的區域滑鼠位置。
返回該 TextEdit 的 PopupMenu。預設情況下,會在按右鍵 TextEdit 時顯示改選單。
你可以新增自訂功能表專案,也可以移除標準功能表專案。請確保你使用的 ID 與標準功能表專案的 ID 不衝突(見 MenuItems)。例如:
func _ready():
var menu = get_menu()
# 移除“復原”後的所有功能表專案。
menu.item_count = menu.get_item_index(MENU_REDO) + 1
# 新增自訂功能表專案。
menu.add_separator()
menu.add_item("插入日期", MENU_MAX + 1)
# 連接回呼函式。
menu.id_pressed.connect(_on_item_pressed)
func _on_item_pressed(id):
if id == MENU_MAX + 1:
insert_text_at_caret(Time.get_date_string_from_system())
public override void _Ready()
{
var menu = GetMenu();
// 移除“復原”後的所有功能表專案。
menu.ItemCount = menu.GetItemIndex(TextEdit.MenuItems.Redo) + 1;
// 新增自訂功能表專案。
menu.AddSeparator();
menu.AddItem("插入日期", TextEdit.MenuItems.Max + 1);
// 新增事件處理器。
menu.IdPressed += OnItemPressed;
}
public void OnItemPressed(int id)
{
if (id == TextEdit.MenuItems.Max + 1)
{
InsertTextAtCaret(Time.GetDateStringFromSystem());
}
}
警告:這是必要的內部節點,將其移除或釋放會導致當機。如果你想要將其隱藏,或者將其子節點隱藏,請使用對應的 Window.visible 屬性。
int get_minimap_line_at_pos(position: Vector2i) const 🔗
返回小地圖 position 處等價的行。
int get_minimap_visible_lines() const 🔗
返回小地圖上能夠繪製的行數。
int get_next_composite_character_column(line: int, column: int) const 🔗
如果游標位於合成字元的開頭,則回傳該字元末尾所在的正確列。合成字元由多個 Unicode 碼位組合而成(例如修復愛心 ❤️🩹 的 Unicode 為 U+2764 U+FE0F U+200D U+1FA79)。如果文字游標位於非合成字元字素的內部,也會回傳正確的列。
注意:請使用 get_next_composite_character_column(get_caret_line(), get_caret_column()) 在文字游標的位置進行檢查
Vector2i get_next_visible_line_index_offset_from(line: int, wrap_index: int, visible_amount: int) const 🔗
類似於 get_next_visible_line_offset_from(),但考慮了換行索引。在返回的向量中,x 是行,y 是換行索引。
int get_next_visible_line_offset_from(line: int, visible_amount: int) const 🔗
返回從 line 到 line + visible_amount 的下一個可見行的計數。也可以倒數計數。例如,如果 TextEdit 有 5 行,其中隱藏了第 2 行和第 3 行,使用 line = 1, visible_amount = 1 呼叫它會返回 3。
Vector2i get_pos_at_line_column(line: int, column: int) const 🔗
返回給定 line 和 column 的區域位置。如果返回的向量的 x 或 y 等於 -1,則該位置在該控制項的可視區域之外。
注意:Y 位置對應於行的底部。請使用 get_rect_at_line_column() 來取得頂部位置。
int get_previous_composite_character_column(line: int, column: int) const 🔗
如果游標位於合成字元的末尾,則回傳該字元開頭所在的正確列。合成字元由多個 Unicode 碼位組合而成(例如修復愛心 ❤️🩹 的 Unicode 為 U+2764 U+FE0F U+200D U+1FA79)。如果文字游標位於非合成字元字素的內部,也會回傳正確的列。
注意:請使用 get_previous_composite_character_column(get_caret_line(), get_caret_column()) 在文字游標的位置進行檢查
Rect2i get_rect_at_line_column(line: int, column: int) const 🔗
返回給定 line 和 column 處的字素的區域位置和大小。如果返回的矩形的 x 或 y 位置等於 -1,則該位置在該控制項的可視區域之外。
注意:返回的矩形的 Y 位置對應於該行的頂部,不像 get_pos_at_line_column() 返回底邊。
int get_saved_version() const 🔗
從 tag_saved_version() 返回最後一個標記的保存版本。
float get_scroll_pos_for_line(line: int, wrap_index: int = 0) const 🔗
返回 line 的 wrap_index 對應的捲動位置。
String get_selected_text(caret_index: int = -1) 🔗
返回游標所選文字,如果 caret_index 為預設值 -1 則為所有游標所選文字。
int get_selection_at_line_column(line: int, column: int, include_edges: bool = true, only_selections: bool = true) const 🔗
回傳給定 line 和 column 處選區的游標索引,如果沒有,則回傳 -1。
如果 include_edges 為 false,則位置必須位於選區內,而不是兩端。如果 only_selections 為 false,則還會考慮沒有選區的游標。
int get_selection_column(caret_index: int = 0) const 🔗
已棄用: Use get_selection_origin_column() instead.
返回選區的原始起始列。
int get_selection_from_column(caret_index: int = 0) const 🔗
回傳選區的起始列。如果沒有選區,則回傳游標列。
int get_selection_from_line(caret_index: int = 0) const 🔗
回傳選區的起始行。如果沒有選區,則回傳游標行。
int get_selection_line(caret_index: int = 0) const 🔗
已棄用: Use get_selection_origin_line() instead.
返回選區的原始起始行。
SelectionMode get_selection_mode() const 🔗
返回目前的選區模式。
int get_selection_origin_column(caret_index: int = 0) const 🔗
回傳選區的起始列。這是游標的另一端。
int get_selection_origin_line(caret_index: int = 0) const 🔗
回傳選區的起始行。這是游標的另一端。
int get_selection_to_column(caret_index: int = 0) const 🔗
回傳選區的結束列。如果沒有選區,則回傳游標列。
int get_selection_to_line(caret_index: int = 0) const 🔗
回傳選區結束行。如果沒有選區,則回傳游標行。
PackedInt32Array get_sorted_carets(include_ignored_carets: bool = false) const 🔗
回傳按選區排序的游標,從最低行和列開始到最高(從文字的頂部到底部)。
如果 include_ignored_carets 為 false,則 multicaret_edit_ignore_caret() 中的游標將被忽略。
返回該 TextEdit 的定位字元大小。
int get_total_gutter_width() const 🔗
返回所有欄位及內部邊距的總寬度。
int get_total_visible_line_count() const 🔗
文字中的總行數,包括自動換行,排除已折疊的行。如果 wrap_mode 為 LINE_WRAPPING_NONE 且沒有折疊任何行(見 CodeEdit.is_line_folded())則等價於 get_line_count()。有限範圍的行見 get_visible_line_count_in_range()。
VScrollBar get_v_scroll_bar() const 🔗
設定該 TextEdit 所使用的 StyleBox。
返回該 TextEdit 的目前版本。版本是復原/重做歷史所記錄操作的計數。
int get_visible_line_count() const 🔗
回傳視覺上能夠容納的行數,向下取整,基於控制項的高度。
int get_visible_line_count_in_range(from_line: int, to_line: int) const 🔗
回傳文字中 from_line 到 to_line 之間(兩端包含)的總行數,包括自動換行,排除已折疊的行。如果範圍包含所有行,則等價於 get_total_visible_line_count()。
String get_word_at_pos(position: Vector2) const 🔗
返回位於 position 的單詞。
String get_word_under_caret(caret_index: int = -1) const 🔗
返回一個 String 文字,其中包含文字游標位置下的單詞。
如果使用者的輸入法編輯器中存在文字,則回傳 true。
有“重做”動作可用時返回 true。
bool has_selection(caret_index: int = -1) const 🔗
如果使用者選中了文字,則返回 true。
有“復原”動作可用時返回 true。
void insert_line_at(line: int, text: String) 🔗
在第 line 行插入文字為 text 的新行。
void insert_text(text: String, line: int, column: int, before_selection_begin: bool = true, before_selection_end: bool = false) 🔗
在 line 和 column 處插入 text。
如果 before_selection_begin 為 true,則從 line 和 column 開始的游標和選區將移動到插入文字的末尾,連同其後的所有游標。
如果 before_selection_end 為 true,則從 line 和 column 結束的選區將擴充到插入文字的末尾。這些參數可用於在選區內部或外部插入文字。
void insert_text_at_caret(text: String, caret_index: int = -1) 🔗
在游標位置插入指定的文字。
bool is_caret_after_selection_origin(caret_index: int = 0) const 🔗
如果選區的游標位於選區原點之後,則回傳 true。這可用於確定選區的方向。
bool is_caret_visible(caret_index: int = 0) const 🔗
如果游標可見,回傳 true;否則回傳 false。當捲動功能開啟時,如果游標位於可捲動區域之外,它將被視為已隱藏。
注意: is_caret_visible() 不會考慮游標雖然還在可捲動區域內、但實際已經超出螢幕(即目前視埠)的情況。只要游標滿足 TextEdit 自身設定的可見條件,即使它在螢幕外,該方法也會回傳 true。這包括使用了 scroll_fit_content_width 和 scroll_fit_content_height 導致 TextEdit 擴充到視埠邊界之外的情況。
注意: 在剛剛設定完游標位置後,此方法並不能立刻保證給出準確的可見性檢查結果。正確的值可能只有在 TextEdit 完成繪製後的下一影格才能取得。任何導致 TextEdit 尺寸發生變化的操作,也同樣適用這條規則。
bool is_dragging_cursor() const 🔗
如果使用者拖動滑鼠進行捲動、選擇或文字拖動,則回傳 true。
bool is_gutter_clickable(gutter: int) const 🔗
如果給定索引處的邊欄可點選,則回傳 true。見 set_gutter_clickable()。
bool is_gutter_drawn(gutter: int) const 🔗
如果給定索引處的邊欄目前被繪製,則回傳 true。見 set_gutter_draw()。
bool is_gutter_overwritable(gutter: int) const 🔗
如果給定索引處的邊欄可覆蓋,則回傳 true。見 set_gutter_overwritable()。
bool is_in_mulitcaret_edit() const 🔗
如果已呼叫 begin_multicaret_edit() 且尚未呼叫 end_multicaret_edit() 則回傳 true。
bool is_line_gutter_clickable(line: int, gutter: int) const 🔗
如果給定索引處的邊欄在給定的行處可點選,則回傳 true。見 set_line_gutter_clickable()。
bool is_line_in_viewport(line: int) const 🔗
如果指定的行處於視埠可捲動區域的範圍內,則回傳 true。
bool is_line_wrapped(line: int) const 🔗
返回給定的行是否換行。
如果選單可見則回傳 true。請使用這個方法來代替 get_menu().visible,可以提高效能(因為避免了選單的建立)。見 get_menu()。
bool is_mouse_over_selection(edges: bool, caret_index: int = -1) const 🔗
如果滑鼠位於選區之上則回傳 true。如果 edges 為 true,則邊界會被認為是選區的一部分。
bool is_overtype_mode_enabled() const 🔗
如果啟用了改寫模式,則回傳 true。見 set_overtype_mode_enabled()。
執行 MenuItems 列舉中定義的給定操作。
void merge_gutters(from_line: int, to_line: int) 🔗
合併從 from_line 到 to_line 的邊欄。只會複製可覆蓋的邊欄。見 set_gutter_overwritable()。
void merge_overlapping_carets() 🔗
合併重疊的文字游標。會保留最新的游標,或者選區的游標。
如果 is_in_mulitcaret_edit() 為 true,則合併將排隊等待以在多游標編輯結束時發生。請參閱 begin_multicaret_edit() 和 end_multicaret_edit()。
注意:游標改變位置後不會進行呼叫,而是在某些動作之後呼叫,所以進入游標重疊的狀態是可能的。
bool multicaret_edit_ignore_caret(caret_index: int) const 🔗
如果給定的 caret_index 應作為多游標編輯的一部分被忽略,則回傳 true。請參閱 begin_multicaret_edit() 和 end_multicaret_edit()。應忽略的游標是已移除文字的一部分,可能會在編輯結束時合併,或在編輯期間新增的游標。
如果應忽略游標,建議在循環中 continue 迭代多個游標。
void paste(caret_index: int = -1) 🔗
貼上到目前位置。可以用 _paste() 覆蓋。
void paste_primary_clipboard(caret_index: int = -1) 🔗
貼上主剪貼簿。
void redo() 🔗
執行重做操作。
void remove_caret(caret: int) 🔗
移除給定的文字游標索引。
注意:可能導致所有其他游標索引的調整。
void remove_gutter(gutter: int) 🔗
移除給定索引的邊欄。
void remove_line_at(line: int, move_carets_down: bool = true) 🔗
移除 line 處的文字行。該行上的游標將嘗試匹配其先前的可視 x 位置。
如果 move_carets_down 為 true,則游標將向下移動到下一行,否則游標將向上移動。
void remove_secondary_carets() 🔗
移除所有額外的游標。
void remove_text(from_line: int, from_column: int, to_line: int, to_column: int) 🔗
移除給定位置之間的文字。
Vector2i search(text: String, flags: int, from_line: int, from_column: int) const 🔗
在文字內部進行搜尋。搜尋旗標可以在 SearchFlags 列舉中指定。
在返回的向量中,x 是列,y 是行。如果沒有找到結果,則兩者都等於 -1 。
var result = search("print", SEARCH_WHOLE_WORDS, 0, 0)
if result.x != -1:
# 找到了結果。
var line_number = result.y
var column_number = result.x
Vector2I result = Search("print", (uint)TextEdit.SearchFlags.WholeWords, 0, 0);
if (result.X != -1)
{
// 找到了結果。
int lineNumber = result.Y;
int columnNumber = result.X;
}
void select(origin_line: int, origin_column: int, caret_line: int, caret_column: int, caret_index: int = 0) 🔗
對於給定的 caret_index,從 origin_line 和 origin_column 到 caret_line 和 caret_column 選擇文字。這會移動選區原點和游標。如果位置相同,則將取消選區。
如果 selecting_enabled 為 false,則不會出現選區。
注意:如果支援多個游標,則不會檢查是否有任何重疊。請參閱 merge_overlapping_carets()。
void select_all() 🔗
選擇所有文字。
如果 selecting_enabled 為 false,則不會發生選擇。
void select_word_under_caret(caret_index: int = -1) 🔗
選中游標下的單詞。
void set_caret_column(column: int, adjust_viewport: bool = true, caret_index: int = 0) 🔗
將游標移動到指定的 column 索引。
如果 adjust_viewport 為 true,則視埠將在移動發生後以游標位置為中心。
注意:如果支援多個游標,則不會檢查任何重疊。請參閱 merge_overlapping_carets()。
void set_caret_line(line: int, adjust_viewport: bool = true, can_be_hidden: bool = true, wrap_index: int = 0, caret_index: int = 0) 🔗
將游標移動到指定的 line 索引。游標列將移動到上次呼叫 set_caret_column() 時的相同可視位置,或限制在行尾。
如果 adjust_viewport 為 true,則移動後視埠將以游標位置為中心。
如果 can_be_hidden 為 true,則指定的 line 可以隱藏。
如果 wrap_index 為 -1,則游標列將限制在 line 的長度範圍內。如果 wrap_index 大於 -1,則將移動該列以嘗試將行的 wrap_index 上的可視 x 位置與上次呼叫 set_caret_column() 時的位置相匹配。
注意:如果支援多個游標,則不會檢查任何重疊。請參閱 merge_overlapping_carets()。
void set_gutter_clickable(gutter: int, clickable: bool) 🔗
如果為 true,則滑鼠懸停在給定索引的邊欄上時,游標會變為指點手的形狀(Control.CURSOR_POINTING_HAND)。見 is_gutter_clickable() 和 set_line_gutter_clickable()。
void set_gutter_custom_draw(column: int, draw_callback: Callable) 🔗
為給定索引的邊欄設定自訂的繪製回呼。draw_callback 必須接受以下參數:行索引 int、邊欄索引 int、區域 Rect2。僅當邊欄型別為 GUTTER_TYPE_CUSTOM 時回呼才有效(見 set_gutter_type())。
void set_gutter_draw(gutter: int, draw: bool) 🔗
如果為 true,則會繪製給定索引處的邊欄。繪製方法由邊欄型別(set_gutter_type())決定。見 is_gutter_drawn()。
void set_gutter_name(gutter: int, name: String) 🔗
設定給定索引處邊欄的名稱。
void set_gutter_overwritable(gutter: int, overwritable: bool) 🔗
如果為 true,則使用 merge_gutters() 時可以覆蓋邊欄在給定索引處的行資料。見 is_gutter_overwritable()。
void set_gutter_type(gutter: int, type: GutterType) 🔗
設定給定索引處的邊欄的型別。邊欄可以包含圖示、文字或自訂視覺效果。
void set_gutter_width(gutter: int, width: int) 🔗
設定給定索引處邊欄的寬度。
void set_line(line: int, new_text: String) 🔗
設定第 line 行的文字。
位於該行的游標會嘗試保持視覺上的 X 位置。
void set_line_as_center_visible(line: int, wrap_index: int = 0) 🔗
將 line 的 wrap_index 放置在視埠的中心。
void set_line_as_first_visible(line: int, wrap_index: int = 0) 🔗
將 line 的 wrap_index 放置在視埠的頂部。
void set_line_as_last_visible(line: int, wrap_index: int = 0) 🔗
將 line 的 wrap_index 放置在視埠的底部。
void set_line_background_color(line: int, color: Color) 🔗
設定給定行的自訂背景色。如果半透明,則該顏色會應用在預設背景色之上(見 background_color)。如果設為 Color(0, 0, 0, 0),則不會應用額外的顏色。
void set_line_gutter_clickable(line: int, gutter: int, clickable: bool) 🔗
如果 clickable 為 true,則 line 行的 gutter 邊欄可點選。類似於 set_gutter_clickable(),但只作用於單行。如果 is_gutter_clickable() 為 true 則無效。見 is_line_gutter_clickable() 和 gutter_clicked。
void set_line_gutter_icon(line: int, gutter: int, icon: Texture2D) 🔗
將 line 上的 gutter 的圖示設定為 icon。僅當邊欄型別為 GUTTER_TYPE_ICON 時才有效(請參閱 set_gutter_type())。
void set_line_gutter_item_color(line: int, gutter: int, color: Color) 🔗
將邊欄 gutter 在第 line 行的顏色設定為 color。
void set_line_gutter_metadata(line: int, gutter: int, metadata: Variant) 🔗
將邊欄 gutter 在第 line 行的中繼資料設定為 metadata。
void set_line_gutter_text(line: int, gutter: int, text: String) 🔗
將 line 上的 gutter 的文字設定為 text。僅當邊欄型別為 GUTTER_TYPE_STRING 時才有效(請參閱 set_gutter_type())。
void set_overtype_mode_enabled(enabled: bool) 🔗
如果為 true,則啟用改寫模式。在改寫模式下,打字會覆蓋已有文字而不是插入文字。ProjectSettings.input/ui_text_toggle_insert_mode 動作會開關改寫模式。見 is_overtype_mode_enabled()。
void set_search_flags(flags: int) 🔗
設定搜尋旗標 flags。配合 set_search_text() 使用可以高亮被搜尋的文字。搜尋旗標可以使用 SearchFlags 列舉指定。
void set_search_text(search_text: String) 🔗
設定搜尋文字。見 set_search_flags()。
void set_selection_mode(mode: SelectionMode) 🔗
設定目前的選區模式。
void set_selection_origin_column(column: int, caret_index: int = 0) 🔗
將給定 caret_index 的選區原點列設定為 column。如果選區原點移動到游標位置,則選區將取消。
void set_selection_origin_line(line: int, can_be_hidden: bool = true, wrap_index: int = -1, caret_index: int = 0) 🔗
為給定 caret_index 將選區原點行設定為 line。如果選區原點移動到游標位置,則該選區將取消選擇。
如果 can_be_hidden 為 false,則該行將設定為下方或上方最近的未隱藏行。
如果 wrap_index 為 -1,則選區原點列將被限制為 line 的長度。如果 wrap_index 大於 -1,則將移動該列以嘗試將行的 wrap_index 上的可視 x 位置與上次呼叫 set_selection_origin_column() 或 select() 時的位置相匹配。
void set_tab_size(size: int) 🔗
設定該 TextEdit 使用的定位字元大小。
void set_tooltip_request_func(callback: Callable) 🔗
提供自訂工具提示文字。該回呼函式方法必須接受以下參數:hovered_word: String。
void skip_selection_for_next_occurrence() 🔗
將選區和游標移動到目前選擇的下一個匹配項。如果沒有活動的選區,則移動到游標下的單詞的下一個匹配項。
void start_action(action: EditAction) 🔗
開始一個動作,如果 action 與目前動作不同,則會終止目前動作。
呼叫 end_action()、觸發 ProjectSettings.gui/timers/text_edit_idle_detect_sec 或者在 start_action() 和 end_action() 之外呼叫可復原的操作都會導致動作的終止。
void swap_lines(from_line: int, to_line: int) 🔗
交換兩行。游標將與行交換。
void tag_saved_version() 🔗
將目前版本標記為已保存。
void undo() 🔗
執行復原操作。
主題屬性說明
Color background_color = Color(0, 0, 0, 0) 🔗
設定該 TextEdit 的背景 Color。
Color caret_background_color = Color(0, 0, 0, 1) 🔗
使用區塊游標時,游標下文字的 Color。
Color caret_color = Color(0.875, 0.875, 0.875, 1) 🔗
游標的 Color。可以設為完全透明的顏色,從而完全隱藏游標。
Color current_line_color = Color(0.25, 0.25, 0.26, 0.8) 🔗
游標所在行的背景 Color。
Color font_color = Color(0.875, 0.875, 0.875, 1) 🔗
設定字形顏色 Color。
Color font_outline_color = Color(0, 0, 0, 1) 🔗
該 TextEdit 的文字輪廓的色調。
Color font_placeholder_color = Color(0.875, 0.875, 0.875, 0.6) 🔗
placeholder_text 的字形顏色。
Color font_readonly_color = Color(0.875, 0.875, 0.875, 0.5) 🔗
Color font_selected_color = Color(0, 0, 0, 0) 🔗
設定所選文字的 Color。如果等於 Color(0, 0, 0, 0),則該屬性將被忽略。
Color search_result_border_color = Color(0.3, 0.3, 0.3, 0.4) 🔗
與搜尋查詢配對的文字周圍的邊框的 Color。
Color search_result_color = Color(0.3, 0.3, 0.3, 1) 🔗
與搜尋查詢配對的文字背景的 Color。
Color selection_color = Color(0.5, 0.5, 0.5, 1) 🔗
設定文字選擇的高亮 Color 顏色。
Color word_highlighted_color = Color(0.5, 0.5, 0.5, 0.25) 🔗
設定多次出現的高亮 Color 顏色。須啟用 highlight_all_occurrences 。
文字游標的圖元寬度。較大的值能夠確保游標易於看到,確保游標與較大的字形保持一致,從而提高可存取性。如果設定為 0 或更低,游標的寬度將被自動設定為 1 圖元,並乘以顯示縮放係數。
行與行之間的額外縱向留白(單位為像素),留白會被新增到行的降部。該值可以為負數。
文字輪廓的大小。
注意:如果使用啟用了 FontFile.multichannel_signed_distance_field 的字形,其 FontFile.msdf_pixel_range 必須至少設定為 outline_size 的兩倍,輪廓渲染才能看起來正確。否則,輪廓可能會比預期的更早被切斷。
設定換行寬度的額外邊距。
設定預設的字形 Font。
設定預設的字形大小。
為空格文字字元,設定一個自訂 Texture2D。
為定位字元文字字元,設定一個自訂 Texture2D。
設定當獲得焦點時的 StyleBox。該 focus StyleBox 顯示在基礎 StyleBox 之上,因此應使用部分透明的 StyleBox 以確保基礎 StyleBox 保持可見。表示輪廓或底線的 StyleBox 非常適合此目的。要停用焦點視覺效果,請指定一個 StyleBoxEmpty 資源。請注意,停用焦點視覺效果會破壞鍵盤 / 控制器導航的可用性,出於無障礙存取的原因,不建議這樣做。
設定這個 TextEdit 的 StyleBox。