text_edit.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. /*************************************************************************/
  2. /* text_edit.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef TEXT_EDIT_H
  31. #define TEXT_EDIT_H
  32. #include "scene/gui/control.h"
  33. #include "scene/gui/popup_menu.h"
  34. #include "scene/gui/scroll_bar.h"
  35. #include "scene/main/timer.h"
  36. #include "scene/resources/syntax_highlighter.h"
  37. #include "scene/resources/text_paragraph.h"
  38. class TextEdit : public Control {
  39. GDCLASS(TextEdit, Control);
  40. public:
  41. /* Caret. */
  42. enum CaretType {
  43. CARET_TYPE_LINE,
  44. CARET_TYPE_BLOCK
  45. };
  46. /* Selection */
  47. enum SelectionMode {
  48. SELECTION_MODE_NONE,
  49. SELECTION_MODE_SHIFT,
  50. SELECTION_MODE_POINTER,
  51. SELECTION_MODE_WORD,
  52. SELECTION_MODE_LINE
  53. };
  54. /* Line Wrapping.*/
  55. enum LineWrappingMode {
  56. LINE_WRAPPING_NONE,
  57. LINE_WRAPPING_BOUNDARY
  58. };
  59. /* Gutters. */
  60. enum GutterType {
  61. GUTTER_TYPE_STRING,
  62. GUTTER_TYPE_ICON,
  63. GUTTER_TYPE_CUSTOM
  64. };
  65. /* Contex Menu. */
  66. enum MenuItems {
  67. MENU_CUT,
  68. MENU_COPY,
  69. MENU_PASTE,
  70. MENU_CLEAR,
  71. MENU_SELECT_ALL,
  72. MENU_UNDO,
  73. MENU_REDO,
  74. MENU_DIR_INHERITED,
  75. MENU_DIR_AUTO,
  76. MENU_DIR_LTR,
  77. MENU_DIR_RTL,
  78. MENU_DISPLAY_UCC,
  79. MENU_INSERT_LRM,
  80. MENU_INSERT_RLM,
  81. MENU_INSERT_LRE,
  82. MENU_INSERT_RLE,
  83. MENU_INSERT_LRO,
  84. MENU_INSERT_RLO,
  85. MENU_INSERT_PDF,
  86. MENU_INSERT_ALM,
  87. MENU_INSERT_LRI,
  88. MENU_INSERT_RLI,
  89. MENU_INSERT_FSI,
  90. MENU_INSERT_PDI,
  91. MENU_INSERT_ZWJ,
  92. MENU_INSERT_ZWNJ,
  93. MENU_INSERT_WJ,
  94. MENU_INSERT_SHY,
  95. MENU_MAX
  96. };
  97. /* Search. */
  98. enum SearchFlags {
  99. SEARCH_MATCH_CASE = 1,
  100. SEARCH_WHOLE_WORDS = 2,
  101. SEARCH_BACKWARDS = 4
  102. };
  103. private:
  104. struct GutterInfo {
  105. GutterType type = GutterType::GUTTER_TYPE_STRING;
  106. String name = "";
  107. int width = 24;
  108. bool draw = true;
  109. bool clickable = false;
  110. bool overwritable = false;
  111. ObjectID custom_draw_obj = ObjectID();
  112. StringName custom_draw_callback;
  113. };
  114. class Text {
  115. public:
  116. struct Gutter {
  117. Variant metadata;
  118. bool clickable = false;
  119. Ref<Texture2D> icon = Ref<Texture2D>();
  120. String text = "";
  121. Color color = Color(1, 1, 1);
  122. };
  123. struct Line {
  124. Vector<Gutter> gutters;
  125. String data;
  126. Array bidi_override;
  127. Ref<TextParagraph> data_buf;
  128. Color background_color = Color(0, 0, 0, 0);
  129. bool hidden = false;
  130. int height = 0;
  131. int width = 0;
  132. Line() {
  133. data_buf.instantiate();
  134. }
  135. };
  136. private:
  137. bool is_dirty = false;
  138. bool tab_size_dirty = false;
  139. mutable Vector<Line> text;
  140. Ref<Font> font;
  141. int font_size = -1;
  142. Dictionary opentype_features;
  143. String language;
  144. TextServer::Direction direction = TextServer::DIRECTION_AUTO;
  145. bool draw_control_chars = false;
  146. int line_height = -1;
  147. int max_width = -1;
  148. int width = -1;
  149. int tab_size = 4;
  150. int gutter_count = 0;
  151. void _calculate_line_height();
  152. void _calculate_max_line_width();
  153. public:
  154. void set_tab_size(int p_tab_size);
  155. int get_tab_size() const;
  156. void set_font(const Ref<Font> &p_font);
  157. void set_font_size(int p_font_size);
  158. void set_font_features(const Dictionary &p_features);
  159. void set_direction_and_language(TextServer::Direction p_direction, const String &p_language);
  160. void set_draw_control_chars(bool p_enabled);
  161. int get_line_height() const;
  162. int get_line_width(int p_line, int p_wrap_index = -1) const;
  163. int get_max_width() const;
  164. void set_width(float p_width);
  165. int get_line_wrap_amount(int p_line) const;
  166. Vector<Vector2i> get_line_wrap_ranges(int p_line) const;
  167. const Ref<TextParagraph> get_line_data(int p_line) const;
  168. void set(int p_line, const String &p_text, const Array &p_bidi_override);
  169. void set_hidden(int p_line, bool p_hidden) {
  170. text.write[p_line].hidden = p_hidden;
  171. if (!p_hidden && text[p_line].width > max_width) {
  172. max_width = text[p_line].width;
  173. } else if (p_hidden && text[p_line].width == max_width) {
  174. _calculate_max_line_width();
  175. }
  176. }
  177. bool is_hidden(int p_line) const { return text[p_line].hidden; }
  178. void insert(int p_at, const String &p_text, const Array &p_bidi_override);
  179. void remove(int p_at);
  180. int size() const { return text.size(); }
  181. void clear();
  182. void invalidate_cache(int p_line, int p_column = -1, const String &p_ime_text = String(), const Array &p_bidi_override = Array());
  183. void invalidate_all();
  184. void invalidate_all_lines();
  185. _FORCE_INLINE_ const String &operator[](int p_line) const;
  186. /* Gutters. */
  187. void add_gutter(int p_at);
  188. void remove_gutter(int p_gutter);
  189. void move_gutters(int p_from_line, int p_to_line);
  190. void set_line_gutter_metadata(int p_line, int p_gutter, const Variant &p_metadata) { text.write[p_line].gutters.write[p_gutter].metadata = p_metadata; }
  191. const Variant &get_line_gutter_metadata(int p_line, int p_gutter) const { return text[p_line].gutters[p_gutter].metadata; }
  192. void set_line_gutter_text(int p_line, int p_gutter, const String &p_text) { text.write[p_line].gutters.write[p_gutter].text = p_text; }
  193. const String &get_line_gutter_text(int p_line, int p_gutter) const { return text[p_line].gutters[p_gutter].text; }
  194. void set_line_gutter_icon(int p_line, int p_gutter, const Ref<Texture2D> &p_icon) { text.write[p_line].gutters.write[p_gutter].icon = p_icon; }
  195. const Ref<Texture2D> &get_line_gutter_icon(int p_line, int p_gutter) const { return text[p_line].gutters[p_gutter].icon; }
  196. void set_line_gutter_item_color(int p_line, int p_gutter, const Color &p_color) { text.write[p_line].gutters.write[p_gutter].color = p_color; }
  197. const Color &get_line_gutter_item_color(int p_line, int p_gutter) const { return text[p_line].gutters[p_gutter].color; }
  198. void set_line_gutter_clickable(int p_line, int p_gutter, bool p_clickable) { text.write[p_line].gutters.write[p_gutter].clickable = p_clickable; }
  199. bool is_line_gutter_clickable(int p_line, int p_gutter) const { return text[p_line].gutters[p_gutter].clickable; }
  200. /* Line style. */
  201. void set_line_background_color(int p_line, const Color &p_color) { text.write[p_line].background_color = p_color; }
  202. const Color get_line_background_color(int p_line) const { return text[p_line].background_color; }
  203. };
  204. /* Text */
  205. Text text;
  206. bool setting_text = false;
  207. // Text properties.
  208. String ime_text = "";
  209. Point2 ime_selection;
  210. /* Initialise to opposite first, so we get past the early-out in set_editable. */
  211. bool editable = false;
  212. TextDirection text_direction = TEXT_DIRECTION_AUTO;
  213. TextDirection input_direction = TEXT_DIRECTION_LTR;
  214. Dictionary opentype_features;
  215. String language = "";
  216. Control::StructuredTextParser st_parser = STRUCTURED_TEXT_DEFAULT;
  217. Array st_args;
  218. void _clear();
  219. void _update_caches();
  220. // User control.
  221. bool overtype_mode = false;
  222. bool context_menu_enabled = true;
  223. bool shortcut_keys_enabled = true;
  224. bool virtual_keyboard_enabled = true;
  225. bool middle_mouse_paste_enabled = true;
  226. // Overridable actions
  227. String cut_copy_line = "";
  228. // Context menu.
  229. PopupMenu *menu = nullptr;
  230. PopupMenu *menu_dir = nullptr;
  231. PopupMenu *menu_ctl = nullptr;
  232. void _generate_context_menu();
  233. int _get_menu_action_accelerator(const String &p_action);
  234. /* Versioning */
  235. struct TextOperation {
  236. enum Type {
  237. TYPE_NONE,
  238. TYPE_INSERT,
  239. TYPE_REMOVE
  240. };
  241. Type type = TYPE_NONE;
  242. int from_line = 0;
  243. int from_column = 0;
  244. int to_line = 0;
  245. int to_column = 0;
  246. String text;
  247. uint32_t prev_version = 0;
  248. uint32_t version = 0;
  249. bool chain_forward = false;
  250. bool chain_backward = false;
  251. };
  252. bool undo_enabled = true;
  253. int undo_stack_max_size = 50;
  254. int complex_operation_count = 0;
  255. bool next_operation_is_complex = false;
  256. TextOperation current_op;
  257. List<TextOperation> undo_stack;
  258. List<TextOperation>::Element *undo_stack_pos = nullptr;
  259. Timer *idle_detect;
  260. uint32_t version = 0;
  261. uint32_t saved_version = 0;
  262. void _push_current_op();
  263. void _do_text_op(const TextOperation &p_op, bool p_reverse);
  264. void _clear_redo();
  265. /* Search */
  266. Color search_result_color = Color(1, 1, 1);
  267. Color search_result_border_color = Color(1, 1, 1);
  268. String search_text = "";
  269. uint32_t search_flags = 0;
  270. int _get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column) const;
  271. /* Tooltip. */
  272. ObjectID tooltip_obj_id;
  273. StringName tooltip_func;
  274. Variant tooltip_ud;
  275. /* Mouse */
  276. int _get_char_pos_for_line(int p_px, int p_line, int p_wrap_index = 0) const;
  277. /* Caret. */
  278. struct Caret {
  279. Point2 draw_pos;
  280. bool visible = false;
  281. int last_fit_x = 0;
  282. int line = 0;
  283. int column = 0;
  284. int x_ofs = 0;
  285. int line_ofs = 0;
  286. int wrap_ofs = 0;
  287. } caret;
  288. bool setting_caret_line = false;
  289. bool caret_pos_dirty = false;
  290. Color caret_color = Color(1, 1, 1);
  291. Color caret_background_color = Color(0, 0, 0);
  292. CaretType caret_type = CaretType::CARET_TYPE_LINE;
  293. bool draw_caret = true;
  294. bool caret_blink_enabled = false;
  295. Timer *caret_blink_timer;
  296. bool move_caret_on_right_click = true;
  297. bool caret_mid_grapheme_enabled = false;
  298. void _emit_caret_changed();
  299. void _reset_caret_blink_timer();
  300. void _toggle_draw_caret();
  301. int _get_column_x_offset_for_line(int p_char, int p_line) const;
  302. /* Selection. */
  303. struct Selection {
  304. SelectionMode selecting_mode = SelectionMode::SELECTION_MODE_NONE;
  305. int selecting_line = 0;
  306. int selecting_column = 0;
  307. int selected_word_beg = 0;
  308. int selected_word_end = 0;
  309. int selected_word_origin = 0;
  310. bool selecting_text = false;
  311. bool active = false;
  312. int from_line = 0;
  313. int from_column = 0;
  314. int to_line = 0;
  315. int to_column = 0;
  316. bool shiftclick_left = false;
  317. } selection;
  318. bool selecting_enabled = true;
  319. bool deselect_on_focus_loss_enabled = true;
  320. Color font_selected_color = Color(1, 1, 1);
  321. Color selection_color = Color(1, 1, 1);
  322. bool override_selected_font_color = false;
  323. bool dragging_selection = false;
  324. Timer *click_select_held;
  325. uint64_t last_dblclk = 0;
  326. Vector2 last_dblclk_pos;
  327. void _click_selection_held();
  328. void _update_selection_mode_pointer();
  329. void _update_selection_mode_word();
  330. void _update_selection_mode_line();
  331. void _pre_shift_selection();
  332. void _post_shift_selection();
  333. /* line wrapping. */
  334. LineWrappingMode line_wrapping_mode = LineWrappingMode::LINE_WRAPPING_NONE;
  335. int wrap_at_column = 0;
  336. int wrap_right_offset = 10;
  337. void _update_wrap_at_column(bool p_force = false);
  338. void _update_caret_wrap_offset();
  339. /* Viewport. */
  340. HScrollBar *h_scroll;
  341. VScrollBar *v_scroll;
  342. bool scroll_past_end_of_file_enabled = false;
  343. // Smooth scrolling.
  344. bool smooth_scroll_enabled = false;
  345. float target_v_scroll = 0.0;
  346. float v_scroll_speed = 80.0;
  347. // Scrolling.
  348. bool scrolling = false;
  349. bool updating_scrolls = false;
  350. void _update_scrollbars();
  351. int _get_control_height() const;
  352. void _v_scroll_input();
  353. void _scroll_moved(double p_to_val);
  354. double _get_visible_lines_offset() const;
  355. double _get_v_scroll_offset() const;
  356. void _scroll_up(real_t p_delta);
  357. void _scroll_down(real_t p_delta);
  358. void _scroll_lines_up();
  359. void _scroll_lines_down();
  360. // Minimap
  361. bool draw_minimap = false;
  362. int minimap_width = 80;
  363. Point2 minimap_char_size = Point2(1, 2);
  364. int minimap_line_spacing = 1;
  365. // minimap scroll
  366. bool minimap_clicked = false;
  367. bool hovering_minimap = false;
  368. bool dragging_minimap = false;
  369. bool can_drag_minimap = false;
  370. double minimap_scroll_ratio = 0.0;
  371. double minimap_scroll_click_pos = 0.0;
  372. void _update_minimap_hover();
  373. void _update_minimap_click();
  374. void _update_minimap_drag();
  375. /* Gutters. */
  376. Vector<GutterInfo> gutters;
  377. int gutters_width = 0;
  378. int gutter_padding = 0;
  379. Vector2i hovered_gutter = Vector2i(-1, -1); // X = gutter index, Y = row.
  380. void _update_gutter_width();
  381. /* Syntax highlighting. */
  382. Ref<SyntaxHighlighter> syntax_highlighter;
  383. Map<int, Dictionary> syntax_highlighting_cache;
  384. Dictionary _get_line_syntax_highlighting(int p_line);
  385. /* Visual. */
  386. Ref<StyleBox> style_normal;
  387. Ref<StyleBox> style_focus;
  388. Ref<StyleBox> style_readonly;
  389. Ref<Texture2D> tab_icon;
  390. Ref<Texture2D> space_icon;
  391. Ref<Font> font;
  392. int font_size = 16;
  393. Color font_color = Color(1, 1, 1);
  394. Color font_readonly_color = Color(1, 1, 1);
  395. int outline_size = 0;
  396. Color outline_color = Color(1, 1, 1);
  397. int line_spacing = 1;
  398. Color background_color = Color(1, 1, 1);
  399. Color current_line_color = Color(1, 1, 1);
  400. Color word_highlighted_color = Color(1, 1, 1);
  401. bool window_has_focus = true;
  402. bool first_draw = true;
  403. bool highlight_current_line = false;
  404. bool highlight_all_occurrences = false;
  405. bool draw_control_chars = false;
  406. bool draw_tabs = false;
  407. bool draw_spaces = false;
  408. /*** Super internal Core API. Everything builds on it. ***/
  409. bool text_changed_dirty = false;
  410. void _text_changed_emit();
  411. void _insert_text(int p_line, int p_char, const String &p_text, int *r_end_line = nullptr, int *r_end_char = nullptr);
  412. void _remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
  413. void _base_insert_text(int p_line, int p_char, const String &p_text, int &r_end_line, int &r_end_column);
  414. String _base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const;
  415. void _base_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
  416. /* Input actions. */
  417. void _swap_current_input_direction();
  418. void _new_line(bool p_split_current = true, bool p_above = false);
  419. void _move_caret_left(bool p_select, bool p_move_by_word = false);
  420. void _move_caret_right(bool p_select, bool p_move_by_word = false);
  421. void _move_caret_up(bool p_select);
  422. void _move_caret_down(bool p_select);
  423. void _move_caret_to_line_start(bool p_select);
  424. void _move_caret_to_line_end(bool p_select);
  425. void _move_caret_page_up(bool p_select);
  426. void _move_caret_page_down(bool p_select);
  427. void _do_backspace(bool p_word = false, bool p_all_to_left = false);
  428. void _delete(bool p_word = false, bool p_all_to_right = false);
  429. void _move_caret_document_start(bool p_select);
  430. void _move_caret_document_end(bool p_select);
  431. protected:
  432. void _notification(int p_what);
  433. static void _bind_methods();
  434. bool _set(const StringName &p_name, const Variant &p_value);
  435. bool _get(const StringName &p_name, Variant &r_ret) const;
  436. void _get_property_list(List<PropertyInfo> *p_list) const;
  437. /* Internal API for CodeEdit, pending public API. */
  438. // brace matching
  439. bool highlight_matching_braces_enabled = false;
  440. Color brace_mismatch_color;
  441. // Line hiding.
  442. Color code_folding_color = Color(1, 1, 1);
  443. Ref<Texture2D> folded_eol_icon;
  444. bool hiding_enabled = false;
  445. void _set_hiding_enabled(bool p_enabled);
  446. bool _is_hiding_enabled() const;
  447. void _set_line_as_hidden(int p_line, bool p_hidden);
  448. bool _is_line_hidden(int p_line) const;
  449. void _unhide_all_lines();
  450. // Symbol lookup.
  451. String lookup_symbol_word;
  452. void _set_symbol_lookup_word(const String &p_symbol);
  453. /* Text manipulation */
  454. // Overridable actions
  455. virtual void _handle_unicode_input_internal(const uint32_t p_unicode);
  456. virtual void _backspace_internal();
  457. virtual void _cut_internal();
  458. virtual void _copy_internal();
  459. virtual void _paste_internal();
  460. virtual void _paste_primary_clipboard_internal();
  461. GDVIRTUAL1(_handle_unicode_input, int)
  462. GDVIRTUAL0(_backspace)
  463. GDVIRTUAL0(_cut)
  464. GDVIRTUAL0(_copy)
  465. GDVIRTUAL0(_paste)
  466. GDVIRTUAL0(_paste_primary_clipboard)
  467. public:
  468. /* General overrides. */
  469. virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
  470. virtual Size2 get_minimum_size() const override;
  471. virtual bool is_text_field() const override;
  472. virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
  473. virtual String get_tooltip(const Point2 &p_pos) const override;
  474. void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
  475. /* Text */
  476. // Text properties.
  477. bool has_ime_text() const;
  478. void set_editable(const bool p_editable);
  479. bool is_editable() const;
  480. void set_text_direction(TextDirection p_text_direction);
  481. TextDirection get_text_direction() const;
  482. void set_opentype_feature(const String &p_name, int p_value);
  483. int get_opentype_feature(const String &p_name) const;
  484. void clear_opentype_features();
  485. void set_language(const String &p_language);
  486. String get_language() const;
  487. void set_structured_text_bidi_override(Control::StructuredTextParser p_parser);
  488. Control::StructuredTextParser get_structured_text_bidi_override() const;
  489. void set_structured_text_bidi_override_options(Array p_args);
  490. Array get_structured_text_bidi_override_options() const;
  491. void set_tab_size(const int p_size);
  492. int get_tab_size() const;
  493. // User controls
  494. void set_overtype_mode_enabled(const bool p_enabled);
  495. bool is_overtype_mode_enabled() const;
  496. void set_context_menu_enabled(bool p_enabled);
  497. bool is_context_menu_enabled() const;
  498. void set_shortcut_keys_enabled(bool p_enabled);
  499. bool is_shortcut_keys_enabled() const;
  500. void set_virtual_keyboard_enabled(bool p_enabled);
  501. bool is_virtual_keyboard_enabled() const;
  502. void set_middle_mouse_paste_enabled(bool p_enabled);
  503. bool is_middle_mouse_paste_enabled() const;
  504. // Text manipulation
  505. void clear();
  506. void set_text(const String &p_text);
  507. String get_text() const;
  508. int get_line_count() const;
  509. void set_line(int p_line, const String &p_new_text);
  510. String get_line(int p_line) const;
  511. int get_line_width(int p_line, int p_wrap_index = -1) const;
  512. int get_line_height() const;
  513. int get_indent_level(int p_line) const;
  514. int get_first_non_whitespace_column(int p_line) const;
  515. void swap_lines(int p_from_line, int p_to_line);
  516. void insert_line_at(int p_at, const String &p_text);
  517. void insert_text_at_caret(const String &p_text);
  518. void remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
  519. int get_last_unhidden_line() const;
  520. int get_next_visible_line_offset_from(int p_line_from, int p_visible_amount) const;
  521. Point2i get_next_visible_line_index_offset_from(int p_line_from, int p_wrap_index_from, int p_visible_amount) const;
  522. // Overridable actions
  523. void handle_unicode_input(const uint32_t p_unicode);
  524. void backspace();
  525. void cut();
  526. void copy();
  527. void paste();
  528. void paste_primary_clipboard();
  529. // Context menu.
  530. PopupMenu *get_menu() const;
  531. bool is_menu_visible() const;
  532. void menu_option(int p_option);
  533. /* Versioning */
  534. void begin_complex_operation();
  535. void end_complex_operation();
  536. bool has_undo() const;
  537. bool has_redo() const;
  538. void undo();
  539. void redo();
  540. void clear_undo_history();
  541. bool is_insert_text_operation() const;
  542. void tag_saved_version();
  543. uint32_t get_version() const;
  544. uint32_t get_saved_version() const;
  545. /* Search */
  546. void set_search_text(const String &p_search_text);
  547. void set_search_flags(uint32_t p_flags);
  548. Point2i search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
  549. /* Mouse */
  550. Point2 get_local_mouse_pos() const;
  551. String get_word_at_pos(const Vector2 &p_pos) const;
  552. Point2i get_line_column_at_pos(const Point2i &p_pos) const;
  553. int get_minimap_line_at_pos(const Point2i &p_pos) const;
  554. bool is_dragging_cursor() const;
  555. /* Caret */
  556. void set_caret_type(CaretType p_type);
  557. CaretType get_caret_type() const;
  558. void set_caret_blink_enabled(const bool p_enabled);
  559. bool is_caret_blink_enabled() const;
  560. void set_caret_blink_speed(const float p_speed);
  561. float get_caret_blink_speed() const;
  562. void set_move_caret_on_right_click_enabled(const bool p_enabled);
  563. bool is_move_caret_on_right_click_enabled() const;
  564. void set_caret_mid_grapheme_enabled(const bool p_enabled);
  565. bool is_caret_mid_grapheme_enabled() const;
  566. bool is_caret_visible() const;
  567. Point2 get_caret_draw_pos() const;
  568. void set_caret_line(int p_line, bool p_adjust_viewport = true, bool p_can_be_hidden = true, int p_wrap_index = 0);
  569. int get_caret_line() const;
  570. void set_caret_column(int p_col, bool p_adjust_viewport = true);
  571. int get_caret_column() const;
  572. int get_caret_wrap_index() const;
  573. String get_word_under_caret() const;
  574. /* Selection. */
  575. void set_selecting_enabled(const bool p_enabled);
  576. bool is_selecting_enabled() const;
  577. void set_deselect_on_focus_loss_enabled(const bool p_enabled);
  578. bool is_deselect_on_focus_loss_enabled() const;
  579. void set_override_selected_font_color(bool p_override_selected_font_color);
  580. bool is_overriding_selected_font_color() const;
  581. void set_selection_mode(SelectionMode p_mode, int p_line = -1, int p_column = -1);
  582. SelectionMode get_selection_mode() const;
  583. void select_all();
  584. void select_word_under_caret();
  585. void select(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
  586. bool has_selection() const;
  587. String get_selected_text() const;
  588. int get_selection_line() const;
  589. int get_selection_column() const;
  590. int get_selection_from_line() const;
  591. int get_selection_from_column() const;
  592. int get_selection_to_line() const;
  593. int get_selection_to_column() const;
  594. void deselect();
  595. void delete_selection();
  596. /* line wrapping. */
  597. void set_line_wrapping_mode(LineWrappingMode p_wrapping_mode);
  598. LineWrappingMode get_line_wrapping_mode() const;
  599. bool is_line_wrapped(int p_line) const;
  600. int get_line_wrap_count(int p_line) const;
  601. int get_line_wrap_index_at_column(int p_line, int p_column) const;
  602. Vector<String> get_line_wrapped_text(int p_line) const;
  603. /* Viewport. */
  604. // Scrolling.
  605. void set_smooth_scroll_enabled(const bool p_enabled);
  606. bool is_smooth_scroll_enabled() const;
  607. void set_scroll_past_end_of_file_enabled(const bool p_enabled);
  608. bool is_scroll_past_end_of_file_enabled() const;
  609. void set_v_scroll(double p_scroll);
  610. double get_v_scroll() const;
  611. void set_h_scroll(int p_scroll);
  612. int get_h_scroll() const;
  613. void set_v_scroll_speed(float p_speed);
  614. float get_v_scroll_speed() const;
  615. double get_scroll_pos_for_line(int p_line, int p_wrap_index = 0) const;
  616. // Visible lines.
  617. void set_line_as_first_visible(int p_line, int p_wrap_index = 0);
  618. int get_first_visible_line() const;
  619. void set_line_as_center_visible(int p_line, int p_wrap_index = 0);
  620. void set_line_as_last_visible(int p_line, int p_wrap_index = 0);
  621. int get_last_full_visible_line() const;
  622. int get_last_full_visible_line_wrap_index() const;
  623. int get_visible_line_count() const;
  624. int get_total_visible_line_count() const;
  625. // Auto Adjust
  626. void adjust_viewport_to_caret();
  627. void center_viewport_to_caret();
  628. // Minimap
  629. void set_draw_minimap(bool p_enabled);
  630. bool is_drawing_minimap() const;
  631. void set_minimap_width(int p_minimap_width);
  632. int get_minimap_width() const;
  633. int get_minimap_visible_lines() const;
  634. /* Gutters. */
  635. void add_gutter(int p_at = -1);
  636. void remove_gutter(int p_gutter);
  637. int get_gutter_count() const;
  638. void set_gutter_name(int p_gutter, const String &p_name);
  639. String get_gutter_name(int p_gutter) const;
  640. void set_gutter_type(int p_gutter, GutterType p_type);
  641. GutterType get_gutter_type(int p_gutter) const;
  642. void set_gutter_width(int p_gutter, int p_width);
  643. int get_gutter_width(int p_gutter) const;
  644. int get_total_gutter_width() const;
  645. void set_gutter_draw(int p_gutter, bool p_draw);
  646. bool is_gutter_drawn(int p_gutter) const;
  647. void set_gutter_clickable(int p_gutter, bool p_clickable);
  648. bool is_gutter_clickable(int p_gutter) const;
  649. void set_gutter_overwritable(int p_gutter, bool p_overwritable);
  650. bool is_gutter_overwritable(int p_gutter) const;
  651. void merge_gutters(int p_from_line, int p_to_line);
  652. void set_gutter_custom_draw(int p_gutter, Object *p_object, const StringName &p_callback);
  653. // Line gutters.
  654. void set_line_gutter_metadata(int p_line, int p_gutter, const Variant &p_metadata);
  655. Variant get_line_gutter_metadata(int p_line, int p_gutter) const;
  656. void set_line_gutter_text(int p_line, int p_gutter, const String &p_text);
  657. String get_line_gutter_text(int p_line, int p_gutter) const;
  658. void set_line_gutter_icon(int p_line, int p_gutter, const Ref<Texture2D> &p_icon);
  659. Ref<Texture2D> get_line_gutter_icon(int p_line, int p_gutter) const;
  660. void set_line_gutter_item_color(int p_line, int p_gutter, const Color &p_color);
  661. Color get_line_gutter_item_color(int p_line, int p_gutter) const;
  662. void set_line_gutter_clickable(int p_line, int p_gutter, bool p_clickable);
  663. bool is_line_gutter_clickable(int p_line, int p_gutter) const;
  664. // Line style
  665. void set_line_background_color(int p_line, const Color &p_color);
  666. Color get_line_background_color(int p_line) const;
  667. /* Syntax Highlighting. */
  668. void set_syntax_highlighter(Ref<SyntaxHighlighter> p_syntax_highlighter);
  669. Ref<SyntaxHighlighter> get_syntax_highlighter() const;
  670. /* Visual. */
  671. void set_highlight_current_line(bool p_enabled);
  672. bool is_highlight_current_line_enabled() const;
  673. void set_highlight_all_occurrences(const bool p_enabled);
  674. bool is_highlight_all_occurrences_enabled() const;
  675. void set_draw_control_chars(bool p_enabled);
  676. bool get_draw_control_chars() const;
  677. void set_draw_tabs(bool p_enabled);
  678. bool is_drawing_tabs() const;
  679. void set_draw_spaces(bool p_enabled);
  680. bool is_drawing_spaces() const;
  681. TextEdit();
  682. };
  683. VARIANT_ENUM_CAST(TextEdit::CaretType);
  684. VARIANT_ENUM_CAST(TextEdit::LineWrappingMode);
  685. VARIANT_ENUM_CAST(TextEdit::SelectionMode);
  686. VARIANT_ENUM_CAST(TextEdit::GutterType);
  687. VARIANT_ENUM_CAST(TextEdit::MenuItems);
  688. VARIANT_ENUM_CAST(TextEdit::SearchFlags);
  689. #endif // TEXT_EDIT_H