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.

TextEdit

继承: Control < CanvasItem < Node < Object

派生: CodeEdit

多行文本编辑器。

描述

多行文本编辑器。它还有少量用于编辑代码的功能,例如语法高亮支持。更多针对编辑代码的高阶功能见 CodeEdit

注意:大多数视口、光标和编辑方法都包含 caret_index 参数以支持 caret_multiple。该参数应为以下之一:-1 用于所有光标,0 用于主光标,大于 0 用于辅助光标。

注意:当按住 Alt 时,垂直滚轮的滚动速度将是正常速度的 5 倍。这也适用于 Godot 脚本编辑器。

属性

AutowrapMode

autowrap_mode

3

bool

caret_blink

false

float

caret_blink_interval

0.65

bool

caret_draw_when_editable_disabled

false

bool

caret_mid_grapheme

false

bool

caret_move_on_right_click

true

bool

caret_multiple

true

CaretType

caret_type

0

bool

context_menu_enabled

true

bool

deselect_on_focus_loss_enabled

true

bool

drag_and_drop_selection_enabled

true

bool

draw_control_chars

false

bool

draw_spaces

false

bool

draw_tabs

false

bool

editable

true

FocusMode

focus_mode

2 (overrides Control)

bool

highlight_all_occurrences

false

bool

highlight_current_line

false

String

language

""

bool

middle_mouse_paste_enabled

true

bool

minimap_draw

false

int

minimap_width

80

CursorShape

mouse_default_cursor_shape

1 (overrides Control)

String

placeholder_text

""

bool

scroll_fit_content_height

false

int

scroll_horizontal

0

bool

scroll_past_end_of_file

false

bool

scroll_smooth

false

float

scroll_v_scroll_speed

80.0

float

scroll_vertical

0.0

bool

selecting_enabled

true

bool

shortcut_keys_enabled

true

StructuredTextParser

structured_text_bidi_override

0

Array

structured_text_bidi_override_options

[]

SyntaxHighlighter

syntax_highlighter

String

text

""

TextDirection

text_direction

0

bool

virtual_keyboard_enabled

true

LineWrappingMode

wrap_mode

0

方法

void

_backspace ( int caret_index ) virtual

void

_copy ( int caret_index ) virtual

void

_cut ( int caret_index ) virtual

void

_handle_unicode_input ( int unicode_char, int caret_index ) virtual

void

_paste ( int caret_index ) virtual

void

_paste_primary_clipboard ( int caret_index ) virtual

int

add_caret ( int line, int col )

void

add_caret_at_carets ( bool below )

void

add_gutter ( int at=-1 )

void

add_selection_for_next_occurrence ( )

void

adjust_carets_after_edit ( int caret, int from_line, int from_col, int to_line, int to_col )

void

adjust_viewport_to_caret ( int caret_index=0 )

void

backspace ( int caret_index=-1 )

void

begin_complex_operation ( )

void

center_viewport_to_caret ( int caret_index=0 )

void

clear ( )

void

clear_undo_history ( )

void

copy ( int caret_index=-1 )

void

cut ( int caret_index=-1 )

void

delete_selection ( int caret_index=-1 )

void

deselect ( int caret_index=-1 )

void

end_action ( )

void

end_complex_operation ( )

int

get_caret_column ( int caret_index=0 ) const

int

get_caret_count ( ) const

Vector2

get_caret_draw_pos ( int caret_index=0 ) const

PackedInt32Array

get_caret_index_edit_order ( )

int

get_caret_line ( int caret_index=0 ) const

int

get_caret_wrap_index ( int caret_index=0 ) const

int

get_first_non_whitespace_column ( int line ) const

int

get_first_visible_line ( ) const

int

get_gutter_count ( ) const

String

get_gutter_name ( int gutter ) const

GutterType

get_gutter_type ( int gutter ) const

int

get_gutter_width ( int gutter ) const

HScrollBar

get_h_scroll_bar ( ) const

int

get_indent_level ( int line ) const

int

get_last_full_visible_line ( ) const

int

get_last_full_visible_line_wrap_index ( ) const

int

get_last_unhidden_line ( ) const

String

get_line ( int line ) const

Color

get_line_background_color ( int line ) const

Vector2i

get_line_column_at_pos ( Vector2i position, bool allow_out_of_bounds=true ) const

int

get_line_count ( ) const

Texture2D

get_line_gutter_icon ( int line, int gutter ) const

Color

get_line_gutter_item_color ( int line, int gutter ) const

Variant

get_line_gutter_metadata ( int line, int gutter ) const

String

get_line_gutter_text ( int line, int gutter ) const

int

get_line_height ( ) const

int

get_line_width ( int line, int wrap_index=-1 ) const

int

get_line_wrap_count ( int line ) const

int

get_line_wrap_index_at_column ( int line, int column ) const

PackedStringArray

get_line_wrapped_text ( int line ) const

Vector2

get_local_mouse_pos ( ) const

PopupMenu

get_menu ( ) const

int

get_minimap_line_at_pos ( Vector2i position ) const

int

get_minimap_visible_lines ( ) const

Vector2i

get_next_visible_line_index_offset_from ( int line, int wrap_index, int visible_amount ) const

int

get_next_visible_line_offset_from ( int line, int visible_amount ) const

Vector2i

get_pos_at_line_column ( int line, int column ) const

Rect2i

get_rect_at_line_column ( int line, int column ) const

int

get_saved_version ( ) const

float

get_scroll_pos_for_line ( int line, int wrap_index=0 ) const

String

get_selected_text ( int caret_index=-1 )

int

get_selection_column ( int caret_index=0 ) const

int

get_selection_from_column ( int caret_index=0 ) const

int

get_selection_from_line ( int caret_index=0 ) const

int

get_selection_line ( int caret_index=0 ) const

SelectionMode

get_selection_mode ( ) const

int

get_selection_to_column ( int caret_index=0 ) const

int

get_selection_to_line ( int caret_index=0 ) const

int

get_tab_size ( ) const

int

get_total_gutter_width ( ) const

int

get_total_visible_line_count ( ) const

VScrollBar

get_v_scroll_bar ( ) const

int

get_version ( ) const

int

get_visible_line_count ( ) const

int

get_visible_line_count_in_range ( int from_line, int to_line ) const

String

get_word_at_pos ( Vector2 position ) const

String

get_word_under_caret ( int caret_index=-1 ) const

bool

has_ime_text ( ) const

bool

has_redo ( ) const

bool

has_selection ( int caret_index=-1 ) const

bool

has_undo ( ) const

void

insert_line_at ( int line, String text )

void

insert_text_at_caret ( String text, int caret_index=-1 )

bool

is_caret_visible ( int caret_index=0 ) const

bool

is_dragging_cursor ( ) const

bool

is_gutter_clickable ( int gutter ) const

bool

is_gutter_drawn ( int gutter ) const

bool

is_gutter_overwritable ( int gutter ) const

bool

is_line_gutter_clickable ( int line, int gutter ) const

bool

is_line_wrapped ( int line ) const

bool

is_menu_visible ( ) const

bool

is_mouse_over_selection ( bool edges, int caret_index=-1 ) const

bool

is_overtype_mode_enabled ( ) const

void

menu_option ( int option )

void

merge_gutters ( int from_line, int to_line )

void

merge_overlapping_carets ( )

void

paste ( int caret_index=-1 )

void

paste_primary_clipboard ( int caret_index=-1 )

void

redo ( )

void

remove_caret ( int caret )

void

remove_gutter ( int gutter )

void

remove_secondary_carets ( )

void

remove_text ( int from_line, int from_column, int to_line, int to_column )

Vector2i

search ( String text, int flags, int from_line, int from_colum ) const

void

select ( int from_line, int from_column, int to_line, int to_column, int caret_index=0 )

void

select_all ( )

void

select_word_under_caret ( int caret_index=-1 )

void

set_caret_column ( int column, bool adjust_viewport=true, int caret_index=0 )

void

set_caret_line ( int line, bool adjust_viewport=true, bool can_be_hidden=true, int wrap_index=0, int caret_index=0 )

void

set_gutter_clickable ( int gutter, bool clickable )

void

set_gutter_custom_draw ( int column, Callable draw_callback )

void

set_gutter_draw ( int gutter, bool draw )

void

set_gutter_name ( int gutter, String name )

void

set_gutter_overwritable ( int gutter, bool overwritable )

void

set_gutter_type ( int gutter, GutterType type )

void

set_gutter_width ( int gutter, int width )

void

set_line ( int line, String new_text )

void

set_line_as_center_visible ( int line, int wrap_index=0 )

void

set_line_as_first_visible ( int line, int wrap_index=0 )

void

set_line_as_last_visible ( int line, int wrap_index=0 )

void

set_line_background_color ( int line, Color color )

void

set_line_gutter_clickable ( int line, int gutter, bool clickable )

void

set_line_gutter_icon ( int line, int gutter, Texture2D icon )

void

set_line_gutter_item_color ( int line, int gutter, Color color )

void

set_line_gutter_metadata ( int line, int gutter, Variant metadata )

void

set_line_gutter_text ( int line, int gutter, String text )

void

set_overtype_mode_enabled ( bool enabled )

void

set_search_flags ( int flags )

void

set_search_text ( String search_text )

void

set_selection_mode ( SelectionMode mode, int line=-1, int column=-1, int caret_index=0 )

void

set_tab_size ( int size )

void

set_tooltip_request_func ( Callable callback )

void

start_action ( EditAction action )

void

swap_lines ( int from_line, int to_line )

void

tag_saved_version ( )

void

undo ( )

主题属性

Color

background_color

Color(0, 0, 0, 0)

Color

caret_background_color

Color(0, 0, 0, 1)

Color

caret_color

Color(0.875, 0.875, 0.875, 1)

Color

current_line_color

Color(0.25, 0.25, 0.26, 0.8)

Color

font_color

Color(0.875, 0.875, 0.875, 1)

Color

font_outline_color

Color(1, 1, 1, 1)

Color

font_placeholder_color

Color(0.875, 0.875, 0.875, 0.6)

Color

font_readonly_color

Color(0.875, 0.875, 0.875, 0.5)

Color

font_selected_color

Color(0, 0, 0, 0)

Color

search_result_border_color

Color(0.3, 0.3, 0.3, 0.4)

Color

search_result_color

Color(0.3, 0.3, 0.3, 1)

Color

selection_color

Color(0.5, 0.5, 0.5, 1)

Color

word_highlighted_color

Color(0.5, 0.5, 0.5, 0.25)

int

caret_width

1

int

line_spacing

4

int

outline_size

0

Font

font

int

font_size

Texture2D

space

Texture2D

tab

StyleBox

focus

StyleBox

normal

StyleBox

read_only


信号

caret_changed ( )

光标改变位置时发出。


gutter_added ( )

添加边栏时发出。


gutter_clicked ( int line, int gutter )

点击边栏时发出。


gutter_removed ( )

移除边栏时发出。


lines_edited_from ( int from_line, int to_line )

文本改变时立即发出。

添加文本时 from_line 小于 to_line。移除文本时 to_line 小于 from_line


text_changed ( )

当文本更改时触发。


text_set ( )

clear 被调用,或 text 被设置时发出。


枚举

enum MenuItems:

MenuItems MENU_CUT = 0

剪切(复制并删除)选中的文本。

MenuItems MENU_COPY = 1

复制选中的文本。

MenuItems MENU_PASTE = 2

将剪贴板上的文本粘贴在选定的文本上(或光标的位置)。

MenuItems MENU_CLEAR = 3

擦除整个 TextEdit 文本。

MenuItems MENU_SELECT_ALL = 4

选择整个 TextEdit 文本。

MenuItems MENU_UNDO = 5

撤销之前的操作。

MenuItems MENU_REDO = 6

重做前一个动作。

MenuItems MENU_SUBMENU_TEXT_DIR = 7

“文本书写方向”子菜单的 ID。

MenuItems MENU_DIR_INHERITED = 8

将文本方向设置为继承。

MenuItems MENU_DIR_AUTO = 9

将文本方向设置为自动。

MenuItems MENU_DIR_LTR = 10

将文本方向设置为从左至右。

MenuItems MENU_DIR_RTL = 11

将文本方向设置为从右至左。

MenuItems MENU_DISPLAY_UCC = 12

切换控制字符的显示。

MenuItems MENU_SUBMENU_INSERT_UCC = 13

“插入控制字符”子菜单的 ID。

MenuItems MENU_INSERT_LRM = 14

插入从左至右标志(LRM)字符。

MenuItems MENU_INSERT_RLM = 15

插入从右至左标志(LRM)字符。

MenuItems MENU_INSERT_LRE = 16

插入开始从左至右嵌入(LRE)字符。

MenuItems MENU_INSERT_RLE = 17

插入开始从右至左嵌入(RLE)字符。

MenuItems MENU_INSERT_LRO = 18

插入开始从左至右强制(LRO)字符。