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