text_edit.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. /*************************************************************************/
  2. /* text_edit.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. class SyntaxHighlighter;
  37. class TextEdit : public Control {
  38. GDCLASS(TextEdit, Control);
  39. public:
  40. struct HighlighterInfo {
  41. Color color;
  42. };
  43. struct ColorRegion {
  44. Color color;
  45. String begin_key;
  46. String end_key;
  47. bool line_only;
  48. bool eq;
  49. ColorRegion(const String &p_begin_key = "", const String &p_end_key = "", const Color &p_color = Color(), bool p_line_only = false) {
  50. begin_key = p_begin_key;
  51. end_key = p_end_key;
  52. color = p_color;
  53. line_only = p_line_only || p_end_key == "";
  54. eq = begin_key == end_key;
  55. }
  56. };
  57. class Text {
  58. public:
  59. struct ColorRegionInfo {
  60. int region;
  61. bool end;
  62. ColorRegionInfo() {
  63. region = 0;
  64. end = false;
  65. }
  66. };
  67. struct Line {
  68. int width_cache : 24;
  69. bool marked : 1;
  70. bool breakpoint : 1;
  71. bool bookmark : 1;
  72. bool hidden : 1;
  73. bool safe : 1;
  74. bool has_info : 1;
  75. int wrap_amount_cache : 24;
  76. Map<int, ColorRegionInfo> region_info;
  77. Ref<Texture> info_icon;
  78. String info;
  79. String data;
  80. Line() {
  81. width_cache = 0;
  82. marked = false;
  83. breakpoint = false;
  84. bookmark = false;
  85. hidden = false;
  86. safe = false;
  87. has_info = false;
  88. wrap_amount_cache = 0;
  89. }
  90. };
  91. private:
  92. const Vector<ColorRegion> *color_regions;
  93. mutable Vector<Line> text;
  94. Ref<Font> font;
  95. int indent_size;
  96. void _update_line_cache(int p_line) const;
  97. public:
  98. void set_indent_size(int p_indent_size);
  99. void set_font(const Ref<Font> &p_font);
  100. void set_color_regions(const Vector<ColorRegion> *p_regions) { color_regions = p_regions; }
  101. int get_line_width(int p_line) const;
  102. int get_max_width(bool p_exclude_hidden = false) const;
  103. int get_char_width(CharType c, CharType next_c, int px) const;
  104. void set_line_wrap_amount(int p_line, int p_wrap_amount) const;
  105. int get_line_wrap_amount(int p_line) const;
  106. const Map<int, ColorRegionInfo> &get_color_region_info(int p_line) const;
  107. void set(int p_line, const String &p_text);
  108. void set_marked(int p_line, bool p_marked) { text.write[p_line].marked = p_marked; }
  109. bool is_marked(int p_line) const { return text[p_line].marked; }
  110. void set_bookmark(int p_line, bool p_bookmark) { text.write[p_line].bookmark = p_bookmark; }
  111. bool is_bookmark(int p_line) const { return text[p_line].bookmark; }
  112. void set_breakpoint(int p_line, bool p_breakpoint) { text.write[p_line].breakpoint = p_breakpoint; }
  113. bool is_breakpoint(int p_line) const { return text[p_line].breakpoint; }
  114. void set_hidden(int p_line, bool p_hidden) { text.write[p_line].hidden = p_hidden; }
  115. bool is_hidden(int p_line) const { return text[p_line].hidden; }
  116. void set_safe(int p_line, bool p_safe) { text.write[p_line].safe = p_safe; }
  117. bool is_safe(int p_line) const { return text[p_line].safe; }
  118. void set_info_icon(int p_line, Ref<Texture> p_icon, String p_info) {
  119. if (p_icon.is_null()) {
  120. text.write[p_line].has_info = false;
  121. return;
  122. }
  123. text.write[p_line].info_icon = p_icon;
  124. text.write[p_line].info = p_info;
  125. text.write[p_line].has_info = true;
  126. }
  127. bool has_info_icon(int p_line) const { return text[p_line].has_info; }
  128. const Ref<Texture> &get_info_icon(int p_line) const { return text[p_line].info_icon; }
  129. const String &get_info(int p_line) const { return text[p_line].info; }
  130. void insert(int p_at, const String &p_text);
  131. void remove(int p_at);
  132. int size() const { return text.size(); }
  133. void clear();
  134. void clear_width_cache();
  135. void clear_wrap_cache();
  136. void clear_info_icons();
  137. _FORCE_INLINE_ const String &operator[](int p_line) const { return text[p_line].data; }
  138. Text() { indent_size = 4; }
  139. };
  140. private:
  141. struct Cursor {
  142. int last_fit_x;
  143. int line, column; ///< cursor
  144. int x_ofs, line_ofs, wrap_ofs;
  145. Cursor() {
  146. last_fit_x = 0;
  147. line = 0;
  148. column = 0; ///< cursor
  149. x_ofs = 0;
  150. line_ofs = 0;
  151. wrap_ofs = 0;
  152. }
  153. } cursor;
  154. struct Selection {
  155. enum Mode {
  156. MODE_NONE,
  157. MODE_SHIFT,
  158. MODE_POINTER,
  159. MODE_WORD,
  160. MODE_LINE
  161. };
  162. Mode selecting_mode;
  163. int selecting_line, selecting_column;
  164. int selected_word_beg, selected_word_end, selected_word_origin;
  165. bool selecting_text;
  166. bool active;
  167. int from_line, from_column;
  168. int to_line, to_column;
  169. bool shiftclick_left;
  170. Selection() {
  171. selecting_mode = MODE_NONE;
  172. selecting_line = 0;
  173. selecting_column = 0;
  174. selected_word_beg = 0;
  175. selected_word_end = 0;
  176. selected_word_origin = 0;
  177. selecting_text = false;
  178. active = false;
  179. from_line = 0;
  180. from_column = 0;
  181. to_line = 0;
  182. to_column = 0;
  183. shiftclick_left = false;
  184. }
  185. } selection;
  186. struct Cache {
  187. Ref<Texture> tab_icon;
  188. Ref<Texture> space_icon;
  189. Ref<Texture> can_fold_icon;
  190. Ref<Texture> folded_icon;
  191. Ref<Texture> folded_eol_icon;
  192. Ref<Texture> executing_icon;
  193. Ref<StyleBox> style_normal;
  194. Ref<StyleBox> style_focus;
  195. Ref<StyleBox> style_readonly;
  196. Ref<Font> font;
  197. Color completion_background_color;
  198. Color completion_selected_color;
  199. Color completion_existing_color;
  200. Color completion_font_color;
  201. Color caret_color;
  202. Color caret_background_color;
  203. Color line_number_color;
  204. Color safe_line_number_color;
  205. Color font_color;
  206. Color font_color_selected;
  207. Color font_color_readonly;
  208. Color keyword_color;
  209. Color number_color;
  210. Color function_color;
  211. Color member_variable_color;
  212. Color selection_color;
  213. Color mark_color;
  214. Color bookmark_color;
  215. Color breakpoint_color;
  216. Color executing_line_color;
  217. Color code_folding_color;
  218. Color current_line_color;
  219. Color line_length_guideline_color;
  220. Color brace_mismatch_color;
  221. Color word_highlighted_color;
  222. Color search_result_color;
  223. Color search_result_border_color;
  224. Color symbol_color;
  225. Color background_color;
  226. int row_height;
  227. int line_spacing;
  228. int line_number_w;
  229. int breakpoint_gutter_width;
  230. int fold_gutter_width;
  231. int info_gutter_width;
  232. int minimap_width;
  233. Cache() {
  234. row_height = 0;
  235. line_spacing = 0;
  236. line_number_w = 0;
  237. breakpoint_gutter_width = 0;
  238. fold_gutter_width = 0;
  239. info_gutter_width = 0;
  240. minimap_width = 0;
  241. }
  242. } cache;
  243. Map<int, int> color_region_cache;
  244. Map<int, Map<int, HighlighterInfo> > syntax_highlighting_cache;
  245. struct TextOperation {
  246. enum Type {
  247. TYPE_NONE,
  248. TYPE_INSERT,
  249. TYPE_REMOVE
  250. };
  251. Type type;
  252. int from_line, from_column;
  253. int to_line, to_column;
  254. String text;
  255. uint32_t prev_version;
  256. uint32_t version;
  257. bool chain_forward;
  258. bool chain_backward;
  259. TextOperation() {
  260. type = TYPE_NONE;
  261. from_line = 0;
  262. from_column = 0;
  263. to_line = 0;
  264. to_column = 0;
  265. prev_version = 0;
  266. version = 0;
  267. chain_forward = false;
  268. chain_backward = false;
  269. }
  270. };
  271. String ime_text;
  272. Point2 ime_selection;
  273. TextOperation current_op;
  274. List<TextOperation> undo_stack;
  275. List<TextOperation>::Element *undo_stack_pos;
  276. void _clear_redo();
  277. void _do_text_op(const TextOperation &p_op, bool p_reverse);
  278. //syntax coloring
  279. SyntaxHighlighter *syntax_highlighter;
  280. HashMap<String, Color> keywords;
  281. HashMap<String, Color> member_keywords;
  282. Map<int, HighlighterInfo> _get_line_syntax_highlighting(int p_line);
  283. Vector<ColorRegion> color_regions;
  284. Set<String> completion_prefixes;
  285. bool completion_enabled;
  286. List<ScriptCodeCompletionOption> completion_sources;
  287. Vector<ScriptCodeCompletionOption> completion_options;
  288. bool completion_active;
  289. bool completion_forced;
  290. ScriptCodeCompletionOption completion_current;
  291. String completion_base;
  292. int completion_index;
  293. Rect2i completion_rect;
  294. int completion_line_ofs;
  295. String completion_hint;
  296. int completion_hint_offset;
  297. bool setting_text;
  298. // data
  299. Text text;
  300. uint32_t version;
  301. uint32_t saved_version;
  302. int max_chars;
  303. bool readonly;
  304. bool syntax_coloring;
  305. bool indent_using_spaces;
  306. int indent_size;
  307. String space_indent;
  308. Timer *caret_blink_timer;
  309. bool caret_blink_enabled;
  310. bool draw_caret;
  311. bool window_has_focus;
  312. bool block_caret;
  313. bool right_click_moves_caret;
  314. bool wrap_enabled;
  315. int wrap_at;
  316. int wrap_right_offset;
  317. bool first_draw;
  318. bool setting_row;
  319. bool draw_tabs;
  320. bool draw_spaces;
  321. bool override_selected_font_color;
  322. bool cursor_changed_dirty;
  323. bool text_changed_dirty;
  324. bool undo_enabled;
  325. bool line_numbers;
  326. bool line_numbers_zero_padded;
  327. bool line_length_guideline;
  328. int line_length_guideline_col;
  329. bool draw_bookmark_gutter;
  330. bool draw_breakpoint_gutter;
  331. int breakpoint_gutter_width;
  332. bool draw_fold_gutter;
  333. int fold_gutter_width;
  334. bool hiding_enabled;
  335. bool draw_info_gutter;
  336. int info_gutter_width;
  337. bool draw_minimap;
  338. int minimap_width;
  339. Point2 minimap_char_size;
  340. int minimap_line_spacing;
  341. bool highlight_all_occurrences;
  342. bool scroll_past_end_of_file_enabled;
  343. bool auto_brace_completion_enabled;
  344. bool brace_matching_enabled;
  345. bool highlight_current_line;
  346. bool auto_indent;
  347. String cut_copy_line;
  348. bool insert_mode;
  349. bool select_identifiers_enabled;
  350. bool smooth_scroll_enabled;
  351. bool scrolling;
  352. bool dragging_selection;
  353. bool dragging_minimap;
  354. bool can_drag_minimap;
  355. bool minimap_clicked;
  356. double minimap_scroll_ratio;
  357. double minimap_scroll_click_pos;
  358. float target_v_scroll;
  359. float v_scroll_speed;
  360. String highlighted_word;
  361. uint64_t last_dblclk;
  362. Timer *idle_detect;
  363. Timer *click_select_held;
  364. HScrollBar *h_scroll;
  365. VScrollBar *v_scroll;
  366. bool updating_scrolls;
  367. Object *tooltip_obj;
  368. StringName tooltip_func;
  369. Variant tooltip_ud;
  370. bool next_operation_is_complex;
  371. bool callhint_below;
  372. Vector2 callhint_offset;
  373. String search_text;
  374. uint32_t search_flags;
  375. int search_result_line;
  376. int search_result_col;
  377. bool selecting_enabled;
  378. bool context_menu_enabled;
  379. bool shortcut_keys_enabled;
  380. int executing_line;
  381. void _generate_context_menu();
  382. int get_visible_rows() const;
  383. int get_total_visible_rows() const;
  384. int _get_minimap_visible_rows() const;
  385. void update_cursor_wrap_offset();
  386. void _update_wrap_at();
  387. bool line_wraps(int line) const;
  388. int times_line_wraps(int line) const;
  389. Vector<String> get_wrap_rows_text(int p_line) const;
  390. int get_cursor_wrap_index() const;
  391. int get_line_wrap_index_at_col(int p_line, int p_column) const;
  392. int get_char_count();
  393. double get_scroll_pos_for_line(int p_line, int p_wrap_index = 0) const;
  394. void set_line_as_first_visible(int p_line, int p_wrap_index = 0);
  395. void set_line_as_center_visible(int p_line, int p_wrap_index = 0);
  396. void set_line_as_last_visible(int p_line, int p_wrap_index = 0);
  397. int get_first_visible_line() const;
  398. int get_last_visible_line() const;
  399. int get_last_visible_line_wrap_index() const;
  400. double get_visible_rows_offset() const;
  401. double get_v_scroll_offset() const;
  402. int get_char_pos_for_line(int p_px, int p_line, int p_wrap_index = 0) const;
  403. int get_column_x_offset_for_line(int p_char, int p_line) const;
  404. int get_char_pos_for(int p_px, String p_str) const;
  405. int get_column_x_offset(int p_char, String p_str) const;
  406. void adjust_viewport_to_cursor();
  407. double get_scroll_line_diff() const;
  408. void _scroll_moved(double);
  409. void _update_scrollbars();
  410. void _v_scroll_input();
  411. void _click_selection_held();
  412. void _update_selection_mode_pointer();
  413. void _update_selection_mode_word();
  414. void _update_selection_mode_line();
  415. void _update_minimap_click();
  416. void _update_minimap_drag();
  417. void _scroll_up(real_t p_delta);
  418. void _scroll_down(real_t p_delta);
  419. void _pre_shift_selection();
  420. void _post_shift_selection();
  421. void _scroll_lines_up();
  422. void _scroll_lines_down();
  423. //void mouse_motion(const Point& p_pos, const Point& p_rel, int p_button_mask);
  424. Size2 get_minimum_size() const;
  425. int _get_control_height() const;
  426. int get_row_height() const;
  427. void _reset_caret_blink_timer();
  428. void _toggle_draw_caret();
  429. void _update_caches();
  430. void _cursor_changed_emit();
  431. void _text_changed_emit();
  432. void _line_edited_from(int p_line);
  433. void _push_current_op();
  434. /* super internal api, undo/redo builds on it */
  435. void _base_insert_text(int p_line, int p_char, const String &p_text, int &r_end_line, int &r_end_column);
  436. String _base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const;
  437. void _base_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
  438. int _get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column);
  439. PoolVector<int> _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
  440. PopupMenu *menu;
  441. void _clear();
  442. void _cancel_completion();
  443. void _cancel_code_hint();
  444. void _confirm_completion();
  445. void _update_completion_candidates();
  446. int _calculate_spaces_till_next_left_indent(int column);
  447. int _calculate_spaces_till_next_right_indent(int column);
  448. protected:
  449. virtual String get_tooltip(const Point2 &p_pos) const;
  450. void _insert_text(int p_line, int p_char, const String &p_text, int *r_end_line = NULL, int *r_end_char = NULL);
  451. void _remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
  452. void _insert_text_at_cursor(const String &p_text);
  453. void _gui_input(const Ref<InputEvent> &p_gui_input);
  454. void _notification(int p_what);
  455. void _consume_pair_symbol(CharType ch);
  456. void _consume_backspace_for_pair_symbol(int prev_line, int prev_column);
  457. static void _bind_methods();
  458. public:
  459. SyntaxHighlighter *_get_syntax_highlighting();
  460. void _set_syntax_highlighting(SyntaxHighlighter *p_syntax_highlighter);
  461. int _is_line_in_region(int p_line);
  462. ColorRegion _get_color_region(int p_region) const;
  463. Map<int, Text::ColorRegionInfo> _get_line_color_region_info(int p_line) const;
  464. enum MenuItems {
  465. MENU_CUT,
  466. MENU_COPY,
  467. MENU_PASTE,
  468. MENU_CLEAR,
  469. MENU_SELECT_ALL,
  470. MENU_UNDO,
  471. MENU_REDO,
  472. MENU_MAX
  473. };
  474. enum SearchFlags {
  475. SEARCH_MATCH_CASE = 1,
  476. SEARCH_WHOLE_WORDS = 2,
  477. SEARCH_BACKWARDS = 4
  478. };
  479. enum SearchResult {
  480. SEARCH_RESULT_COLUMN,
  481. SEARCH_RESULT_LINE,
  482. };
  483. virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;
  484. void _get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const;
  485. void _get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const;
  486. //void delete_char();
  487. //void delete_line();
  488. void begin_complex_operation();
  489. void end_complex_operation();
  490. bool is_insert_text_operation();
  491. void set_text(String p_text);
  492. void insert_text_at_cursor(const String &p_text);
  493. void insert_at(const String &p_text, int at);
  494. int get_line_count() const;
  495. void set_line_as_marked(int p_line, bool p_marked);
  496. void set_line_as_bookmark(int p_line, bool p_bookmark);
  497. bool is_line_set_as_bookmark(int p_line) const;
  498. void get_bookmarks(List<int> *p_bookmarks) const;
  499. Array get_bookmarks_array() const;
  500. void set_line_as_breakpoint(int p_line, bool p_breakpoint);
  501. bool is_line_set_as_breakpoint(int p_line) const;
  502. void set_executing_line(int p_line);
  503. void clear_executing_line();
  504. void set_line_as_safe(int p_line, bool p_safe);
  505. bool is_line_set_as_safe(int p_line) const;
  506. void get_breakpoints(List<int> *p_breakpoints) const;
  507. Array get_breakpoints_array() const;
  508. void remove_breakpoints();
  509. void set_line_info_icon(int p_line, Ref<Texture> p_icon, String p_info = "");
  510. void clear_info_icons();
  511. void set_line_as_hidden(int p_line, bool p_hidden);
  512. bool is_line_hidden(int p_line) const;
  513. void fold_all_lines();
  514. void unhide_all_lines();
  515. int num_lines_from(int p_line_from, int visible_amount) const;
  516. int num_lines_from_rows(int p_line_from, int p_wrap_index_from, int visible_amount, int &wrap_index) const;
  517. int get_last_unhidden_line() const;
  518. bool can_fold(int p_line) const;
  519. bool is_folded(int p_line) const;
  520. Vector<int> get_folded_lines() const;
  521. void fold_line(int p_line);
  522. void unfold_line(int p_line);
  523. void toggle_fold_line(int p_line);
  524. String get_text();
  525. String get_line(int line) const;
  526. void set_line(int line, String new_text);
  527. void backspace_at_cursor();
  528. void indent_left();
  529. void indent_right();
  530. int get_indent_level(int p_line) const;
  531. bool is_line_comment(int p_line) const;
  532. inline void set_scroll_pass_end_of_file(bool p_enabled) {
  533. scroll_past_end_of_file_enabled = p_enabled;
  534. update();
  535. }
  536. inline void set_auto_brace_completion(bool p_enabled) {
  537. auto_brace_completion_enabled = p_enabled;
  538. }
  539. inline void set_brace_matching(bool p_enabled) {
  540. brace_matching_enabled = p_enabled;
  541. update();
  542. }
  543. inline void set_callhint_settings(bool below, Vector2 offset) {
  544. callhint_below = below;
  545. callhint_offset = offset;
  546. }
  547. void set_auto_indent(bool p_auto_indent);
  548. void center_viewport_to_cursor();
  549. void cursor_set_column(int p_col, bool p_adjust_viewport = true);
  550. void cursor_set_line(int p_row, bool p_adjust_viewport = true, bool p_can_be_hidden = true, int p_wrap_index = 0);
  551. int cursor_get_column() const;
  552. int cursor_get_line() const;
  553. Vector2i _get_cursor_pixel_pos();
  554. bool cursor_get_blink_enabled() const;
  555. void cursor_set_blink_enabled(const bool p_enabled);
  556. float cursor_get_blink_speed() const;
  557. void cursor_set_blink_speed(const float p_speed);
  558. void cursor_set_block_mode(const bool p_enable);
  559. bool cursor_is_block_mode() const;
  560. void set_right_click_moves_caret(bool p_enable);
  561. bool is_right_click_moving_caret() const;
  562. void set_readonly(bool p_readonly);
  563. bool is_readonly() const;
  564. void set_max_chars(int p_max_chars);
  565. int get_max_chars() const;
  566. void set_wrap_enabled(bool p_wrap_enabled);
  567. bool is_wrap_enabled() const;
  568. void clear();
  569. void set_syntax_coloring(bool p_enabled);
  570. bool is_syntax_coloring_enabled() const;
  571. void cut();
  572. void copy();
  573. void paste();
  574. void select_all();
  575. void select(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
  576. void deselect();
  577. void swap_lines(int line1, int line2);
  578. void set_search_text(const String &p_search_text);
  579. void set_search_flags(uint32_t p_flags);
  580. void set_current_search_result(int line, int col);
  581. void set_highlight_all_occurrences(const bool p_enabled);
  582. bool is_highlight_all_occurrences_enabled() const;
  583. bool is_selection_active() const;
  584. int get_selection_from_line() const;
  585. int get_selection_from_column() const;
  586. int get_selection_to_line() const;
  587. int get_selection_to_column() const;
  588. String get_selection_text() const;
  589. String get_word_under_cursor() const;
  590. String get_word_at_pos(const Vector2 &p_pos) const;
  591. bool search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column, int &r_line, int &r_column) const;
  592. void undo();
  593. void redo();
  594. void clear_undo_history();
  595. void set_indent_using_spaces(const bool p_use_spaces);
  596. bool is_indent_using_spaces() const;
  597. void set_indent_size(const int p_size);
  598. int get_indent_size();
  599. void set_draw_tabs(bool p_draw);
  600. bool is_drawing_tabs() const;
  601. void set_draw_spaces(bool p_draw);
  602. bool is_drawing_spaces() const;
  603. void set_override_selected_font_color(bool p_override_selected_font_color);
  604. bool is_overriding_selected_font_color() const;
  605. void set_insert_mode(bool p_enabled);
  606. bool is_insert_mode() const;
  607. void add_keyword_color(const String &p_keyword, const Color &p_color);
  608. bool has_keyword_color(String p_keyword) const;
  609. Color get_keyword_color(String p_keyword) const;
  610. void add_color_region(const String &p_begin_key = String(), const String &p_end_key = String(), const Color &p_color = Color(), bool p_line_only = false);
  611. void clear_colors();
  612. void add_member_keyword(const String &p_keyword, const Color &p_color);
  613. bool has_member_color(String p_member) const;
  614. Color get_member_color(String p_member) const;
  615. void clear_member_keywords();
  616. double get_v_scroll() const;
  617. void set_v_scroll(double p_scroll);
  618. int get_h_scroll() const;
  619. void set_h_scroll(int p_scroll);
  620. void set_smooth_scroll_enabled(bool p_enable);
  621. bool is_smooth_scroll_enabled() const;
  622. void set_v_scroll_speed(float p_speed);
  623. float get_v_scroll_speed() const;
  624. uint32_t get_version() const;
  625. uint32_t get_saved_version() const;
  626. void tag_saved_version();
  627. void menu_option(int p_option);
  628. void set_show_line_numbers(bool p_show);
  629. bool is_show_line_numbers_enabled() const;
  630. void set_highlight_current_line(bool p_enabled);
  631. bool is_highlight_current_line_enabled() const;
  632. void set_line_numbers_zero_padded(bool p_zero_padded);
  633. void set_show_line_length_guideline(bool p_show);
  634. void set_line_length_guideline_column(int p_column);
  635. void set_bookmark_gutter_enabled(bool p_draw);
  636. bool is_bookmark_gutter_enabled() const;
  637. void set_breakpoint_gutter_enabled(bool p_draw);
  638. bool is_breakpoint_gutter_enabled() const;
  639. void set_breakpoint_gutter_width(int p_gutter_width);
  640. int get_breakpoint_gutter_width() const;
  641. void set_draw_fold_gutter(bool p_draw);
  642. bool is_drawing_fold_gutter() const;
  643. void set_fold_gutter_width(int p_gutter_width);
  644. int get_fold_gutter_width() const;
  645. void set_draw_info_gutter(bool p_draw);
  646. bool is_drawing_info_gutter() const;
  647. void set_info_gutter_width(int p_gutter_width);
  648. int get_info_gutter_width() const;
  649. void set_draw_minimap(bool p_draw);
  650. bool is_drawing_minimap() const;
  651. void set_minimap_width(int p_minimap_width);
  652. int get_minimap_width() const;
  653. void set_hiding_enabled(bool p_enabled);
  654. bool is_hiding_enabled() const;
  655. void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
  656. void set_completion(bool p_enabled, const Vector<String> &p_prefixes);
  657. void code_complete(const List<ScriptCodeCompletionOption> &p_strings, bool p_forced = false);
  658. void set_code_hint(const String &p_hint);
  659. void query_code_comple();
  660. void set_select_identifiers_on_hover(bool p_enable);
  661. bool is_selecting_identifiers_on_hover_enabled() const;
  662. void set_context_menu_enabled(bool p_enable);
  663. bool is_context_menu_enabled();
  664. void set_selecting_enabled(bool p_enabled);
  665. bool is_selecting_enabled() const;
  666. void set_shortcut_keys_enabled(bool p_enabled);
  667. bool is_shortcut_keys_enabled() const;
  668. PopupMenu *get_menu() const;
  669. String get_text_for_completion();
  670. String get_text_for_lookup_completion();
  671. virtual bool is_text_field() const;
  672. TextEdit();
  673. ~TextEdit();
  674. };
  675. VARIANT_ENUM_CAST(TextEdit::MenuItems);
  676. VARIANT_ENUM_CAST(TextEdit::SearchFlags);
  677. VARIANT_ENUM_CAST(TextEdit::SearchResult);
  678. class SyntaxHighlighter {
  679. protected:
  680. TextEdit *text_editor;
  681. public:
  682. virtual ~SyntaxHighlighter() {}
  683. virtual void _update_cache() = 0;
  684. virtual Map<int, TextEdit::HighlighterInfo> _get_line_syntax_highlighting(int p_line) = 0;
  685. virtual String get_name() const = 0;
  686. virtual List<String> get_supported_languages() = 0;
  687. void set_text_editor(TextEdit *p_text_editor);
  688. TextEdit *get_text_editor();
  689. };
  690. #endif // TEXT_EDIT_H