跳转至

TextEdit

继承

Control

简要描述

多行文字编辑控件。

描述

TextEdit用于编辑多行文本,它也有编辑码功能,如语法高亮支持和撤销/重做的多个级别。

成员

类型 属性名 默认值
bool breakpoint_gutter false
bool caret_blink false
float caret_blink_speed 0.65
bool caret_block_mode false
bool caret_moving_by_right_click true
bool context_menu_enabled true
bool draw_spaces false
bool draw_tabs false
int focus_mode 2
bool fold_gutter false
bool hiding_enabled false
bool highlight_all_occurrences false
bool highlight_current_line false
bool minimap_draw false
int minimap_width 80
int mouse_default_cursor_shape 1
bool override_selected_font_color false
bool readonly false
int scroll_horizontal 0
float scroll_vertical 0.0
bool selecting_enabled true
bool shortcut_keys_enabled true
bool show_line_numbers false
bool smooth_scrolling false
bool syntax_highlighting false
String text ""
float v_scroll_speed 80.0
bool wrap_enabled false

方法

返回值类型 方法名称
void add_color_region(begin_key: String, end_key: String, color: Color, line_only: bool = false)
void add_keyword_color(keyword: String, color: Color)
bool can_fold(line: int) const
void center_viewport_to_cursor()
void clear_colors()
void clear_undo_history()
void copy()
int cursor_get_column() const
int cursor_get_line() const
void cursor_set_column(column: int, adjust_viewport: bool = true)
void cursor_set_line(line: int, adjust_viewport: bool = true, can_be_hidden: bool = true, wrap_index: int = 0)
void cut()
void deselect()
void fold_all_lines()
void fold_line(line: int)
Array get_breakpoints() const
Color get_keyword_color(keyword: String) const
String get_line(line: int) const
int get_line_count() const
PopupMenu get_menu() const
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
String get_word_under_cursor() const
bool has_keyword_color(keyword: String) const
void insert_text_at_cursor(text: String)
bool is_folded(line: int) const
bool is_line_hidden(line: int) const
bool is_selection_active() const
void menu_option(option: int)
void paste()
void redo()
void remove_breakpoints()
PoolIntArray search(key: String, flags: int, from_line: int, from_column: int) const
void select(from_line: int, from_column: int, to_line: int, to_column: int)
void select_all()
void set_line_as_hidden(line: int, enable: bool)
void toggle_fold_line(line: int)
void undo()
void unfold_line(line: int)
void unhide_all_lines()

信号

  • breakpoint_toggled

通过断点槽放置断点时发出。


  • cursor_changed

光标更改时发出。


  • info_clicked

单击信息图标时发出。


  • request_completion

  • symbol_lookup

  • text_changed

文本更改时发出。


枚举

enum SearchFlags: - SEARCH_MATCH_CASE = 1

搜索时区分大小写。

  • SEARCH_WHOLE_WORDS = 2

搜索时匹配整个单词。

  • SEARCH_BACKWARDS = 4

从头到尾搜索。


enum SearchResult: - SEARCH_RESULT_COLUMN = 0

用于从[方法搜索]中访问结果列。

  • SEARCH_RESULT_LINE = 1

用于从[方法搜索]访问结果行。


enum MenuItems: - 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 breakpoint_gutter
Default false
setter set_breakpoint_gutter_enabled(value)
getter is_breakpoint_gutter_enabled
  • bool caret_blink
Default false
setter cursor_set_blink_enabled(value)
getter cursor_get_blink_enabled
  • float caret_blink_speed
Default 0.65
setter cursor_set_blink_speed(value)
getter cursor_get_blink_speed
  • bool caret_block_mode
Default false
setter cursor_set_block_mode(value)
getter cursor_is_block_mode
  • bool caret_moving_by_right_click
Default true
setter set_right_click_moves_caret(value)
getter is_right_click_moving_caret
  • bool context_menu_enabled
Default true
setter set_context_menu_enabled(value)
getter is_context_menu_enabled
  • bool draw_spaces
Default false
setter set_draw_spaces(value)
getter is_drawing_spaces
  • bool draw_tabs
Default false
setter set_draw_tabs(value)
getter is_drawing_tabs
  • int focus_mode
Default 2
setter set_focus_mode(value)
getter get_focus_mode
  • bool fold_gutter
Default false
setter set_draw_fold_gutter(value)
getter is_drawing_fold_gutter
  • bool hiding_enabled
Default false
setter set_hiding_enabled(value)
getter is_hiding_enabled
  • bool highlight_all_occurrences
Default false
setter set_highlight_all_occurrences(value)
getter is_highlight_all_occurrences_enabled
  • bool highlight_current_line
Default false
setter set_highlight_current_line(value)
getter is_highlight_current_line_enabled
  • bool minimap_draw
Default false
setter draw_minimap(value)
getter is_drawing_minimap
  • int minimap_width
Default 80
setter set_minimap_width(value)
getter get_minimap_width
  • int mouse_default_cursor_shape
Default 1
setter set_default_cursor_shape(value)
getter get_default_cursor_shape
  • bool override_selected_font_color
Default false
setter set_override_selected_font_color(value)
getter is_overriding_selected_font_color
  • bool readonly
Default false
setter set_readonly(value)
getter is_readonly
  • int scroll_horizontal
Default 0
setter set_h_scroll(value)
getter get_h_scroll
  • float scroll_vertical
Default 0.0
setter set_v_scroll(value)
getter get_v_scroll
  • bool selecting_enabled
Default true
setter set_selecting_enabled(value)
getter is_selecting_enabled
  • bool shortcut_keys_enabled
Default true
setter set_shortcut_keys_enabled(value)
getter is_shortcut_keys_enabled
  • bool show_line_numbers
Default false
setter set_show_line_numbers(value)
getter is_show_line_numbers_enabled
  • bool smooth_scrolling
Default false
setter set_smooth_scroll_enable(value)
getter is_smooth_scroll_enabled
  • bool syntax_highlighting
Default false
setter set_syntax_coloring(value)
getter is_syntax_coloring_enabled
  • String text
Default ""
setter set_text(value)
getter get_text
  • float v_scroll_speed
Default 80.0
setter set_v_scroll_speed(value)
getter get_v_scroll_speed
  • bool wrap_enabled
Default false
setter set_wrap_enabled(value)
getter is_wrap_enabled

方法说明

  • add_color_region add_color_region(begin_key: String, end_key: String, color: Color, line_only: bool = false)

添加颜色区域(给定分隔符)及其颜色。


  • add_keyword_color add_keyword_color(keyword: String, color: Color)

添加关键字及其Color


  • can_fold can_fold(line: int) const

如果给定的行是可折叠的,则返回该行。即在它的正下方有缩进的行。


  • center_viewport_to_cursor center_viewport_to_cursor()

  • clear_colors clear_colors()

清除以前通过add_color_regionadd_keyword_color添加的所有自定义语法着色信息。


  • clear_undo_history clear_undo_history()

清除撤消历史记录。


  • copy copy()

复制当前的文本选择。


  • cursor_get_column cursor_get_column() const

返回编辑光标所在的列。


  • cursor_get_line cursor_get_line() const

返回编辑光标所在的行。


  • cursor_set_column cursor_set_column(column: int, adjust_viewport: bool = true)

将光标移动到指定的索引处。

如果将adjust_viewport设置为true,则视口将在发生移动后居中于光标位置。


  • cursor_set_line cursor_set_line(line: int, adjust_viewport: bool = true, can_be_hidden: bool = true, wrap_index: int = 0)

将光标移动到指定的line索引处。

如果将adjust_viewport设置为true,则视口将在发生移动后居中于光标位置。

如果can_be_hidden设置为true,则可以使用set_line_as_hidden隐藏指定的line


  • cut cut()

剪切为当前选择。


  • deselect deselect()

取消选择当前选择。


  • fold_all_lines fold_all_lines()

折叠所有可能折叠的行(请参见can_fold)。


  • fold_line fold_line(line: int)

如果可能的话,折叠给定的行(请参见can_fold)。


  • get_breakpoints get_breakpoints() const

返回一个包含每个断点行号的数组。


  • get_keyword_color get_keyword_color(keyword: String) const

返回指定的关键字Color


  • get_line get_line(line: int) const

返回特定行的文本。


  • get_line_count get_line_count() const

返回文本中的总行数。


  • get_menu get_menu() const

返回此TextEditPopupMenu


  • get_selection_from_column get_selection_from_column() const

返回选择开始列。


  • get_selection_from_line get_selection_from_line() const

返回选择开始行。


  • get_selection_text get_selection_text() const

返回所选内容内的文本。


  • get_selection_to_column get_selection_to_column() const

返回选择结束列。


  • get_selection_to_line get_selection_to_line() const

返回选择结束行。


  • get_word_under_cursor get_word_under_cursor() const

返回String文本,其单词在鼠标光标位置下。


  • has_keyword_color has_keyword_color(keyword: String) const

返回指定的keyword是否设置了颜色。


  • insert_text_at_cursor insert_text_at_cursor(text: String)

在光标位置插入指定的文本。


  • is_folded is_folded(line: int) const

返回指定索引处的行是否折叠。


  • is_line_hidden is_line_hidden(line: int) const

返回指定索引处的行是否隐藏。


  • is_selection_active is_selection_active() const

如果选择处于活动状态,则返回true


  • menu_option menu_option(option: int)

通过指定的索引触发右键单击菜单动作。


  • paste paste()

粘贴当前选择。


  • redo redo()

执行重做操作。


  • remove_breakpoints remove_breakpoints()

删除所有断点。


  • search search(key: String, flags: int, from_line: int, from_column: int) const

在文本内执行搜索。

如果未找到结果,则返回一个空的PoolIntArray

var result = search(key, flags, line, column)
if result.size() > 0:
    # Result found.
    var res_line = result[TextEdit.SEARCH_RESULT_LINE]
    var res_column = result[TextEdit.SEARCH_RESULT_COLUMN]

  • select select(from_line: int, from_column: int, to_line: int, to_column: int)

从行/列到行/列执行选择。


  • select_all select_all()

选择所有文本。


  • set_line_as_hidden set_line_as_hidden(line: int, enable: bool)

如果true,则隐藏指定索引的行。


  • toggle_fold_line toggle_fold_line(line: int)

在给定的行上切换代码块的折叠。


  • undo undo()

执行撤消操作。


  • unfold_line unfold_line(line: int)

如果给定的行折叠,则展开。


  • unhide_all_lines unhide_all_lines()

取消隐藏先前由set_line_as_hidden设置为隐藏的所有行。