TextEdit¶
Inherits: Control < CanvasItem < Node < Object
多行文本编辑控件。
描述¶
TextEdit是用来编辑大型多行文本的。它也有编辑代码的功能,如支持语法高亮和多级撤销/重做。
注意:当按住Alt
时,垂直滚轮的滚动速度是平时的5倍。这在Godot脚本编辑器中也适用。
属性¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
focus_mode |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
mouse_default_cursor_shape |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法¶
void |
add_color_region ( String begin_key, String end_key, Color color, bool line_only=false ) |
void |
add_keyword_color ( String keyword, Color color ) |
void |
|
void |
clear_colors ( ) |
void |
|
void |
copy ( ) |
cursor_get_column ( ) const |
|
cursor_get_line ( ) const |
|
void |
cursor_set_column ( int column, bool adjust_viewport=true ) |
void |
cursor_set_line ( int line, bool adjust_viewport=true, bool can_be_hidden=true, int wrap_index=0 ) |
void |
cut ( ) |
void |
deselect ( ) |
void |
fold_all_lines ( ) |
void |
|
get_breakpoints ( ) const |
|
get_keyword_color ( String keyword ) const |
|
get_line_column_at_pos ( Vector2 position ) const |
|
get_line_count ( ) const |
|
get_line_height ( ) const |
|
get_line_width ( int line, int wrap_index=-1 ) const |
|
get_line_wrap_count ( int line ) const |
|
get_line_wrapped_text ( int line ) const |
|
get_menu ( ) const |
|
get_pos_at_line_column ( int line, int column ) const |
|
get_rect_at_line_column ( int line, int column ) const |
|
get_selection_from_column ( ) const |
|
get_selection_from_line ( ) const |
|
get_selection_text ( ) const |
|
get_selection_to_column ( ) const |
|
get_selection_to_line ( ) const |
|
get_total_gutter_width ( ) const |
|
get_word_under_cursor ( ) const |
|
has_keyword_color ( String keyword ) const |
|
has_redo ( ) const |
|
has_undo ( ) const |
|
void |
insert_text_at_cursor ( String text ) |
is_line_hidden ( int line ) const |
|
is_line_set_as_bookmark ( int line ) const |
|
is_line_set_as_breakpoint ( int line ) const |
|
is_line_set_as_safe ( int line ) const |
|
is_line_wrapped ( int line ) const |
|
is_selection_active ( ) const |
|
void |
menu_option ( int option ) |
void |
paste ( ) |
void |
redo ( ) |
void |
|
search ( String key, int flags, int from_line, int from_column ) const |
|
void |
select ( int from_line, int from_column, int to_line, int to_column ) |
void |
select_all ( ) |
void |
|
void |
set_line_as_bookmark ( int line, bool bookmark ) |
void |
set_line_as_breakpoint ( int line, bool breakpoint ) |
void |
set_line_as_hidden ( int line, bool enable ) |
void |
set_line_as_safe ( int line, bool safe ) |
void |
toggle_fold_line ( int line ) |
void |
undo ( ) |
void |
unfold_line ( int line ) |
void |
unhide_all_lines ( ) |
主题属性¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
信号¶
breakpoint_toggled ( int row )
当通过断点栏放置断点时发出。
cursor_changed ( )
光标更改时发出。
单击信息图标时发出。
request_completion ( )
text_changed ( )
当文本更改时触发。
枚举¶
enum SearchFlags:
SEARCH_MATCH_CASE = 1 --- 搜索时匹配大小写。
SEARCH_WHOLE_WORDS = 2 --- 搜索时匹配整个单词。
SEARCH_BACKWARDS = 4 --- 从头到尾搜索。
enum SearchResult:
MENU_CUT = 0 --- 剪切(复制并删除)选定的文本。
MENU_COPY = 1 --- 复制选定的文本。
MENU_PASTE = 2 --- 将剪贴板上的文本粘贴在选定的文本上(或光标的位置)。
MENU_CLEAR = 3 --- 擦除整个
TextEdit
文本。MENU_SELECT_ALL = 4 --- 选择整个
TextEdit
文本。MENU_UNDO = 5 --- 撤销之前的操作。
MENU_REDO = 6 --- 重做前一个动作。
MENU_MAX = 7 --- 表示MenuItems枚举的大小。
属性说明¶
bool bookmark_gutter
Default |
|
Setter |
set_bookmark_gutter_enabled(value) |
Getter |
is_bookmark_gutter_enabled() |
为 true
时书签栏可见。
bool breakpoint_gutter
Default |
|
Setter |
set_breakpoint_gutter_enabled(value) |
Getter |
is_breakpoint_gutter_enabled() |
为 true
时断点栏可见。
bool caret_blink
Default |
|
Setter |
cursor_set_blink_enabled(value) |
Getter |
cursor_get_blink_enabled() |
如果为true
,插入符号(可视光标)将闪烁。
float caret_blink_speed
Default |
|
Setter |
cursor_set_blink_speed(value) |
Getter |
cursor_get_blink_speed() |
插入符号闪烁周期的持续时间(秒)。
bool caret_block_mode
Default |
|
Setter |
cursor_set_block_mode(value) |
Getter |
cursor_is_block_mode() |
为 true
时光标显示为矩形。
为 false
时光标显示为条形。
bool caret_moving_by_right_click
Default |
|
Setter |
set_right_click_moves_caret(value) |
Getter |
is_right_click_moving_caret() |
为 true
时,在显示上下文菜单之前右键单击将光标移动到鼠标位置。
为 false
时,上下文菜单忽略鼠标位置。
Default |
|
Setter |
set_context_menu_enabled(value) |
Getter |
is_context_menu_enabled() |
为 true
时右键单击会显示上下文菜单。
bool draw_spaces
Default |
|
Setter |
set_draw_spaces(value) |
Getter |
is_drawing_spaces() |
如果 true
,“空格”字符将具有可见表示形式。
bool draw_tabs
Default |
|
Setter |
set_draw_tabs(value) |
Getter |
is_drawing_tabs() |
如果 true
,“制表符”字符将具有可见表示形式。
bool fold_gutter
Default |
|
Setter |
set_draw_fold_gutter(value) |
Getter |
is_drawing_fold_gutter() |
如果 true
,则折叠栏可见。这允许折叠缩进行。
bool hiding_enabled
Default |
|
Setter |
set_hiding_enabled(value) |
Getter |
is_hiding_enabled() |
如果 true
,所有已被 set_line_as_hidden 设置为隐藏的行将不可见。
bool highlight_all_occurrences
Default |
|
Setter |
set_highlight_all_occurrences(value) |
Getter |
is_highlight_all_occurrences_enabled() |
如果 true
,所选文本的所有匹配项都将突出显示。
bool highlight_current_line
Default |
|
Setter |
set_highlight_current_line(value) |
Getter |
is_highlight_current_line_enabled() |
如果 true
,则包含光标的行会突出显示。
bool minimap_draw
Default |
|
Setter |
draw_minimap(value) |
Getter |
is_drawing_minimap() |
如果 true
,则显示小地图,提供源代码的概要。
int minimap_width
Default |
|
Setter |
set_minimap_width(value) |
Getter |
get_minimap_width() |
小地图的宽度(以像素为单位)。
bool override_selected_font_color
Default |
|
Setter |
set_override_selected_font_color(value) |
Getter |
is_overriding_selected_font_color() |
如果 true
,自定义 font_color_selected
将用于所选文本。
bool readonly
Default |
|
Setter |
set_readonly(value) |
Getter |
is_readonly() |
如果true
,启用只读模式。现有的文本不能被修改,新的文本不能被添加。
int scroll_horizontal
Default |
|
Setter |
set_h_scroll(value) |
Getter |
get_h_scroll() |
如果有一个水平滚动条,这决定了当前的水平滚动值,单位是像素。
float scroll_vertical
Default |
|
Setter |
set_v_scroll(value) |
Getter |
get_v_scroll() |
如果有一个垂直滚动条,这就决定了当前的垂直滚动值,以行数为单位,顶行从0开始。
bool selecting_enabled
Default |
|
Setter |
set_selecting_enabled(value) |
Getter |
is_selecting_enabled() |
如果true
,文本可以被选择。
如果false
,用户或使用select或select_all方法都不能选择文本。
bool shortcut_keys_enabled
Default |
|
Setter |
set_shortcut_keys_enabled(value) |
Getter |
is_shortcut_keys_enabled() |
为 true
时,即使上下文菜单已被禁用,也会启用该上下文菜单的快捷键。
bool show_line_numbers
Default |
|
Setter |
set_show_line_numbers(value) |
Getter |
is_show_line_numbers_enabled() |
如果 true
,行号显示在文本的左侧。
bool smooth_scrolling
Default |
|
Setter |
set_smooth_scroll_enable(value) |
Getter |
is_smooth_scroll_enabled() |
如果 true
,将滚动条的步长 step
设置为 0.25
,从而使滚动更加平滑。
bool syntax_highlighting
Default |
|
Setter |
set_syntax_coloring(value) |
Getter |
is_syntax_coloring_enabled() |
如果 true
,为此 TextEdit
设置的任何自定义颜色属性都将可见。
String text
Default |
|
Setter |
set_text(value) |
Getter |
get_text() |
TextEdit
的字符串值。
float v_scroll_speed
Default |
|
Setter |
set_v_scroll_speed(value) |
Getter |
get_v_scroll_speed() |
垂直滚动的灵敏度。
bool virtual_keyboard_enabled
Default |
|
Setter |
set_virtual_keyboard_enabled(value) |
Getter |
is_virtual_keyboard_enabled() |
如果true
,则本机虚拟键盘将显示在支持它的平台上。
bool wrap_enabled
Default |
|
Setter |
set_wrap_enabled(value) |
Getter |
is_wrap_enabled() |
如果 true
,当文本超出可见边缘时启用文本换行。
方法说明¶
添加给定分隔符划分区域的颜色。
添加一个关键字keyword
和它的颜色Color。
返回给定的行是否可折叠,也就是说,它在它的正下方有缩进的行。
void center_viewport_to_cursor ( )
将视窗置于编辑光标所在的线上。这也会将 scroll_horizontal 值重置为 0
。
void clear_colors ( )
清除之前用add_color_region或add_keyword_color添加的所有自定义语法着色信息。
void clear_undo_history ( )
清除撤销历史。
void copy ( )
复制当前的文本选择。
int cursor_get_column ( ) const
返回编辑光标所在的列。
int cursor_get_line ( ) const
返回编辑光标所在的行。
将光标移动到指定的 column
索引处。
如果 adjust_viewport
设置为 true
,则移动发生后视窗将以光标位置为中心。
void cursor_set_line ( int line, bool adjust_viewport=true, bool can_be_hidden=true, int wrap_index=0 )
在指定的 line
索引处移动光标。
如果 adjust_viewport
设置为 true
,则移动发生后视窗将以光标位置为中心。
如果 can_be_hidden
设置为 true
,则可以使用 set_line_as_hidden 隐藏指定的 line
。
void cut ( )
剪切当前选择。
void deselect ( )
取消当前选择。
void fold_all_lines ( )
折叠所有可能被折叠的行(参阅 can_fold)。
void fold_line ( int line )
如果可能,折叠给定的行(参阅 can_fold)。
Array get_breakpoints ( ) const
返回一个包含每个断点行号的数组。
返回指定的关键字keyword
的颜色Color。
返回特定行的文本。
返回位于给定位置的行和列。返回的向量中,x
是列、y
是行。
int get_line_count ( ) const
返回文本中的总行数。
int get_line_height ( ) const
返回最大行的高度。
返回位于行 line
的 wrap_index
的像素宽度。
返回给定行换行的次数。
PoolStringArray get_line_wrapped_text ( int line ) const
返回代表各个换行索引的 String 数组。
返回此TextEdit
的PopupMenu。默认情况下,这个菜单在右键点击TextEdit
的时候显示。
警告: 这是一个必要的内部节点,删除和释放它可能会导致崩溃。如果你想隐藏它或它的任何子节点,请使用其的 CanvasItem.visible 属性。
返回给定行 line
和列 column
的本地位置。如果返回向量的 x
或 y
等于 -1
,该位置位于该控件的可视范围之外。
注意:位置的 Y 对应行的底部。请使用 get_rect_at_line_column 来获取顶部位置。
返回位于给定行 line
和列 column
的字形大小。如果返回的矩形位置的 x
或 y
等于 -1
,该位置位于该控件的可视范围之外。
注意:位置的 Y 对应行的顶部,而 get_pos_at_line_column 返回的则是底部位置。
int get_selection_from_column ( ) const
返回选择的开始列。
int get_selection_from_line ( ) const
返回选择开始行。
String get_selection_text ( ) const
返回选择内的文本。
int get_selection_to_column ( ) const
返回选择结束列。
int get_selection_to_line ( ) const
返回选择结束行。
int get_total_gutter_width ( ) const
返回所有栏位及内部边距的总宽度。
String get_word_under_cursor ( ) const
返回一个 String 文本,该文本中的单词位于 caret(文本光标)的位置。
返回指定的关键字 keyword
是否有一个颜色被设置为它。
bool has_redo ( ) const
有“重做”动作可用时返回 true
。
bool has_undo ( ) const
有“撤销”动作可用时返回 true
。
void insert_text_at_cursor ( String text )
在光标位置插入指定的文本。
返回指定索引处的行是否折叠。
返回指定索引处的行是否隐藏。
当指定的行 line
被标记为书签时,返回 true
。
当指定的行 line
有断点时返回 true
。
当指定的行 line
被标记为安全时返回 true
。
返回给定的行是否换行。
bool is_selection_active ( ) const
如果选择处于活动状态,则返回 true
。
按指定的索引触发右键单击菜单操作。有关可用索引的列表,请参阅 MenuItems。
void paste ( )
粘贴当前选择。
void redo ( )
执行重做操作。
void remove_breakpoints ( )
删除所有断点。这不会触发 breakpoint_toggled 信号。
PoolIntArray search ( String key, int flags, int from_line, int from_column ) const
在文本内部进行搜索。搜索标志可以在SearchFlags枚举中指定。
如果没有找到结果,返回一个空的PoolIntArray
。否则,可以通过SearchResult枚举中指定的索引访问结果行和列,例如。
var result = search(key, flags, line, column)
if result.size() > 0:
# 找到的结果。
var res_line = result[TextEdit.SEARCH_RESULT_LINE)
var res_column = result[TextEdit.SEARCH_RESULT_COLUMN]
执行选择,从行/列到行/列。
如果 selecting_enabled 为 false
,则不会发生选择。
void select_all ( )
选择所有文本。
如果 selecting_enabled 为 false
,则不会发生选择。
设置特定行的文本。
如果 bookmark
为 true,则为行 line
设置书签。如果 bookmark
为 false,则删除该书签。
书签显示在 breakpoint_gutter 中。
添加或删除 line
中的断点。断点显示在 breakpoint_gutter 中。
如果 true
,隐藏指定索引的行。
如果为 true
,将行 line
标记为安全。
这将以 safe_line_number_color
主题属性中提供的颜色显示行号。
void toggle_fold_line ( int line )
在给定行切换代码块的折叠。
void undo ( )
执行撤销操作。
void unfold_line ( int line )
如果折叠,展开给定的线。
void unhide_all_lines ( )
取消隐藏之前由 set_line_as_hidden 设置为隐藏的所有行。
Theme Property Descriptions¶
Color background_color
Default |
|
设置这个 TextEdit
的背景颜色 Color。必须启用语法高亮 syntax_highlighting。
Color bookmark_color
Default |
|
设置书签标记的颜色 Color。必须启用语法高亮 syntax_highlighting。
Color brace_mismatch_color
Default |
|
Color breakpoint_color
Default |
|
设置断点的颜色 Color。必须启用断点栏 breakpoint_gutter。
Color caret_background_color
Default |
|
Color caret_color
Default |
|
Color code_folding_color
Default |
|
Color completion_background_color
Default |
|
Color completion_existing_color
Default |
|
Color completion_font_color
Default |
|
Color completion_scroll_color
Default |
|
Color completion_selected_color
Default |
|
Color current_line_color
Default |
|
设置断点的颜色 Color。必须启用断点栏 breakpoint_gutter。
Color executing_line_color
Default |
|
Color font_color
Default |
|
设置字体颜色 Color。
Color font_color_readonly
Default |
|
Color font_color_selected
Default |
|
设置所选文本的颜色 Color。必须启用覆盖所选文字字体颜色 override_selected_font_color。
Color function_color
Default |
|
Color line_number_color
Default |
|
设置行号颜色 Color。show_line_numbers 显示行号必须被启用。
Color mark_color
Default |
|
设置标记文本的颜色 Color。
Color member_variable_color
Default |
|
Color number_color
Default |
|
Color safe_line_number_color
Default |
|
Color selection_color
Default |
|
设置文本选择的高亮 Color 颜色。
Color symbol_color
Default |
|
Color word_highlighted_color
Default |
|
设置多次出现的高亮 Color 颜色。须启用 highlight_all_occurrences 。
int completion_lines
Default |
|
int completion_max_width
Default |
|
int completion_scroll_width
Default |
|
int line_spacing
Default |
|
设置行间距。
Font font
设置默认的字体 Font。
Texture fold
Texture folded
Texture space
Texture tab
为制表符字符设置自定义纹理 Texture。
StyleBox completion
StyleBox focus
StyleBox normal
设置这个 TextEdit
的 StyleBox。
StyleBox read_only