Browse Source

Cleanup and rename caret operations

Paulb23 4 years ago
parent
commit
d5dcaee4c5

+ 86 - 56
doc/classes/TextEdit.xml

@@ -56,8 +56,9 @@
 				Called when the user presses the backspace key. Can be overriden with [method _backspace].
 			</description>
 		</method>
-		<method name="center_viewport_to_cursor">
-			<return type="void" />
+		<method name="center_viewport_to_caret">
+			<return type="void">
+			</return>
 			<description>
 				Centers the viewport on the line the editing cursor is at. This also resets the [member scroll_horizontal] value to [code]0[/code].
 			</description>
@@ -80,60 +81,52 @@
 				Copy's the current text selection. Can be overriden with [method _copy].
 			</description>
 		</method>
-		<method name="cursor_get_column" qualifiers="const">
-			<return type="int" />
-			<description>
-				Returns the column the editing cursor is at.
-			</description>
-		</method>
-		<method name="cursor_get_line" qualifiers="const">
-			<return type="int" />
+		<method name="cut">
+			<return type="void">
+			</return>
 			<description>
-				Returns the line the editing cursor is at.
+				Cut's the current selection. Can be overriden with [method _cut].
 			</description>
 		</method>
-		<method name="cursor_set_column">
-			<return type="void" />
-			<argument index="0" name="column" type="int" />
-			<argument index="1" name="adjust_viewport" type="bool" default="true" />
+		<method name="delete_selection">
+			<return type="void">
+			</return>
 			<description>
-				Moves the cursor at the specified [code]column[/code] index.
-				If [code]adjust_viewport[/code] is set to [code]true[/code], the viewport will center at the cursor position after the move occurs.
 			</description>
 		</method>
-		<method name="cursor_set_line">
-			<return type="void" />
-			<argument index="0" name="line" type="int" />
-			<argument index="1" name="adjust_viewport" type="bool" default="true" />
-			<argument index="2" name="can_be_hidden" type="bool" default="true" />
-			<argument index="3" name="wrap_index" type="int" default="0" />
+		<method name="deselect">
+			<return type="void">
+			</return>
 			<description>
-				Moves the cursor at the specified [code]line[/code] index.
-				If [code]adjust_viewport[/code] is set to [code]true[/code], the viewport will center at the cursor position after the move occurs.
-				If [code]can_be_hidden[/code] is set to [code]true[/code], the specified [code]line[/code] can be hidden.
+				Deselects the current selection.
 			</description>
 		</method>
-		<method name="cut">
-			<return type="void" />
+		<method name="get_caret_column" qualifiers="const">
+			<return type="int">
+			</return>
 			<description>
-				Cut's the current selection. Can be overriden with [method _cut].
+				Returns the column the editing caret is at.
 			</description>
 		</method>
-		<method name="delete_selection">
-			<return type="void" />
+		<method name="get_caret_draw_pos" qualifiers="const">
+			<return type="Vector2">
+			</return>
 			<description>
+				Gets the caret pixel draw poistion.
 			</description>
 		</method>
-		<method name="deselect">
-			<return type="void" />
+		<method name="get_caret_line" qualifiers="const">
+			<return type="int">
+			</return>
 			<description>
-				Deselects the current selection.
+				Returns the line the editing caret is on.
 			</description>
 		</method>
-		<method name="get_caret_draw_pos" qualifiers="const">
-			<return type="Vector2" />
+		<method name="get_caret_wrap_index" qualifiers="const">
+			<return type="int">
+			</return>
 			<description>
-				Gets the caret pixel draw position.
+				Returns the wrap index the editing caret is on.
 			</description>
 		</method>
 		<method name="get_first_non_whitespace_column" qualifiers="const">
@@ -295,17 +288,20 @@
 				Returns the number of visible lines, including wrapped text.
 			</description>
 		</method>
-		<method name="get_word_under_cursor" qualifiers="const">
-			<return type="String" />
+		<method name="get_word_under_caret" qualifiers="const">
+			<return type="String">
+			</return>
 			<description>
-				Returns a [String] text with the word under the caret (text cursor) location.
+				Returns a [String] text with the word under the caret location.
 			</description>
 		</method>
-		<method name="insert_text_at_cursor">
-			<return type="void" />
-			<argument index="0" name="text" type="String" />
+		<method name="insert_text_at_caret">
+			<return type="void">
+			</return>
+			<argument index="0" name="text" type="String">
+			</argument>
 			<description>
-				Insert the specified text at the cursor position.
+				Insert the specified text at the caret position.
 			</description>
 		</method>
 		<method name="is_caret_visible" qualifiers="const">
@@ -435,6 +431,35 @@
 				If [member selecting_enabled] is [code]false[/code], no selection will occur.
 			</description>
 		</method>
+		<method name="set_caret_column">
+			<return type="void">
+			</return>
+			<argument index="0" name="column" type="int">
+			</argument>
+			<argument index="1" name="adjust_viewport" type="bool" default="true">
+			</argument>
+			<description>
+				Moves the caret to the specified [code]column[/code] index.
+				If [code]adjust_viewport[/code] is set to [code]true[/code], the viewport will center at the caret position after the move occurs.
+			</description>
+		</method>
+		<method name="set_caret_line">
+			<return type="void">
+			</return>
+			<argument index="0" name="line" type="int">
+			</argument>
+			<argument index="1" name="adjust_viewport" type="bool" default="true">
+			</argument>
+			<argument index="2" name="can_be_hidden" type="bool" default="true">
+			</argument>
+			<argument index="3" name="wrap_index" type="int" default="0">
+			</argument>
+			<description>
+				Moves the caret to the specified [code]line[/code] index.
+				If [code]adjust_viewport[/code] is set to [code]true[/code], the viewport will center at the caret position after the move occurs.
+				If [code]can_be_hidden[/code] is set to [code]true[/code], the specified [code]line[/code] can be hidden.
+			</description>
+		</method>
 		<method name="set_gutter_clickable">
 			<return type="void" />
 			<argument index="0" name="gutter" type="int" />
@@ -572,24 +597,23 @@
 		</method>
 	</methods>
 	<members>
-		<member name="caret_blink" type="bool" setter="cursor_set_blink_enabled" getter="cursor_get_blink_enabled" default="false">
-			If [code]true[/code], the caret (visual cursor) blinks.
+		<member name="caret_blink" type="bool" setter="set_caret_blink_enabled" getter="is_caret_blink_enabled" default="false">
+			Sets if the caret should blink.
 		</member>
-		<member name="caret_blink_speed" type="float" setter="cursor_set_blink_speed" getter="cursor_get_blink_speed" default="0.65">
+		<member name="caret_blink_speed" type="float" setter="set_caret_blink_speed" getter="get_caret_blink_speed" default="0.65">
 			Duration (in seconds) of a caret's blinking cycle.
 		</member>
-		<member name="caret_block_mode" type="bool" setter="cursor_set_block_mode" getter="cursor_is_block_mode" default="false">
-			If [code]true[/code], the caret displays as a rectangle.
-			If [code]false[/code], the caret displays as a bar.
-		</member>
-		<member name="caret_mid_grapheme" type="bool" setter="set_mid_grapheme_caret_enabled" getter="get_mid_grapheme_caret_enabled" default="false">
+		<member name="caret_mid_grapheme" type="bool" setter="set_caret_mid_grapheme_enabled" getter="is_caret_mid_grapheme_enabled" default="false">
 			Allow moving caret, selecting and removing the individual composite character components.
 			Note: [kbd]Backspace[/kbd] is always removing individual composite character components.
 		</member>
-		<member name="caret_moving_by_right_click" type="bool" setter="set_right_click_moves_caret" getter="is_right_click_moving_caret" default="true">
-			If [code]true[/code], a right-click moves the cursor at the mouse position before displaying the context menu.
+		<member name="caret_move_on_right_click" type="bool" setter="set_move_caret_on_right_click_enabled" getter="is_move_caret_on_right_click_enabled" default="true">
+			If [code]true[/code], a right-click moves the caret at the mouse position before displaying the context menu.
 			If [code]false[/code], the context menu disregards mouse location.
 		</member>
+		<member name="caret_type" type="int" setter="set_caret_type" getter="get_caret_type" enum="TextEdit.CaretType" default="0">
+			Set the type of caret to draw.
+		</member>
 		<member name="context_menu_enabled" type="bool" setter="set_context_menu_enabled" getter="is_context_menu_enabled" default="true">
 			If [code]true[/code], a right-click displays the context menu.
 		</member>
@@ -667,9 +691,9 @@
 		</member>
 	</members>
 	<signals>
-		<signal name="cursor_changed">
+		<signal name="caret_changed">
 			<description>
-				Emitted when the cursor changes.
+				Emitted when the caret changes position.
 			</description>
 		</signal>
 		<signal name="gutter_added">
@@ -708,6 +732,12 @@
 		<constant name="SEARCH_BACKWARDS" value="4" enum="SearchFlags">
 			Search from end to beginning.
 		</constant>
+		<constant name="CARET_TYPE_LINE" value="0" enum="CaretType">
+			Vertical line caret.
+		</constant>
+		<constant name="CARET_TYPE_BLOCK" value="1" enum="CaretType">
+			Block caret.
+		</constant>
 		<constant name="SELECTION_MODE_NONE" value="0" enum="SelectionMode">
 		</constant>
 		<constant name="SELECTION_MODE_SHIFT" value="1" enum="SelectionMode">

+ 85 - 85
editor/code_editor.cpp

@@ -44,7 +44,7 @@
 void GotoLineDialog::popup_find_line(CodeEdit *p_edit) {
 	text_editor = p_edit;
 
-	line->set_text(itos(text_editor->cursor_get_line()));
+	line->set_text(itos(text_editor->get_caret_line()));
 	line->select_all();
 	popup_centered(Size2(180, 80) * EDSCALE);
 	line->grab_focus();
@@ -59,7 +59,7 @@ void GotoLineDialog::ok_pressed() {
 		return;
 	}
 	text_editor->unfold_line(get_line() - 1);
-	text_editor->cursor_set_line(get_line() - 1);
+	text_editor->set_caret_line(get_line() - 1);
 	hide();
 }
 
@@ -150,9 +150,9 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col)
 	if (found) {
 		if (!preserve_cursor && !is_selection_only()) {
 			text_editor->unfold_line(line);
-			text_editor->cursor_set_line(line, false);
-			text_editor->cursor_set_column(col + text.length(), false);
-			text_editor->center_viewport_to_cursor();
+			text_editor->set_caret_line(line, false);
+			text_editor->set_caret_column(col + text.length(), false);
+			text_editor->center_viewport_to_caret();
 			text_editor->select(line, col, line, col + text.length());
 		}
 
@@ -191,8 +191,8 @@ void FindReplaceBar::_replace() {
 
 	text_editor->begin_complex_operation();
 	if (selection_enabled && is_selection_only()) { // To restrict search_current() to selected region
-		text_editor->cursor_set_line(selection_begin.width);
-		text_editor->cursor_set_column(selection_begin.height);
+		text_editor->set_caret_line(selection_begin.width);
+		text_editor->set_caret_column(selection_begin.height);
 	}
 
 	if (search_current()) {
@@ -203,13 +203,13 @@ void FindReplaceBar::_replace() {
 			Point2i match_from(result_line, result_col);
 			Point2i match_to(result_line, result_col + search_text_len);
 			if (!(match_from < selection_begin || match_to > selection_end)) {
-				text_editor->insert_text_at_cursor(replace_text);
+				text_editor->insert_text_at_caret(replace_text);
 				if (match_to.x == selection_end.x) { // Adjust selection bounds if necessary
 					selection_end.y += replace_text.length() - search_text_len;
 				}
 			}
 		} else {
-			text_editor->insert_text_at_cursor(replace_text);
+			text_editor->insert_text_at_caret(replace_text);
 		}
 	}
 	text_editor->end_complex_operation();
@@ -226,7 +226,7 @@ void FindReplaceBar::_replace() {
 void FindReplaceBar::_replace_all() {
 	text_editor->disconnect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed));
 	// Line as x so it gets priority in comparison, column as y.
-	Point2i orig_cursor(text_editor->cursor_get_line(), text_editor->cursor_get_column());
+	Point2i orig_cursor(text_editor->get_caret_line(), text_editor->get_caret_column());
 	Point2i prev_match = Point2(-1, -1);
 
 	bool selection_enabled = text_editor->is_selection_active();
@@ -238,8 +238,8 @@ void FindReplaceBar::_replace_all() {
 
 	int vsval = text_editor->get_v_scroll();
 
-	text_editor->cursor_set_line(0);
-	text_editor->cursor_set_column(0);
+	text_editor->set_caret_line(0);
+	text_editor->set_caret_column(0);
 
 	String replace_text = get_replace_text();
 	int search_text_len = get_search_text().length();
@@ -251,8 +251,8 @@ void FindReplaceBar::_replace_all() {
 	text_editor->begin_complex_operation();
 
 	if (selection_enabled && is_selection_only()) {
-		text_editor->cursor_set_line(selection_begin.width);
-		text_editor->cursor_set_column(selection_begin.height);
+		text_editor->set_caret_line(selection_begin.width);
+		text_editor->set_caret_column(selection_begin.height);
 	}
 	if (search_current()) {
 		do {
@@ -275,14 +275,14 @@ void FindReplaceBar::_replace_all() {
 				}
 
 				// Replace but adjust selection bounds.
-				text_editor->insert_text_at_cursor(replace_text);
+				text_editor->insert_text_at_caret(replace_text);
 				if (match_to.x == selection_end.x) {
 					selection_end.y += replace_text.length() - search_text_len;
 				}
 
 			} else {
 				// Just replace.
-				text_editor->insert_text_at_cursor(replace_text);
+				text_editor->insert_text_at_caret(replace_text);
 			}
 
 			rc++;
@@ -294,8 +294,8 @@ void FindReplaceBar::_replace_all() {
 	replace_all_mode = false;
 
 	// Restore editor state (selection, cursor, scroll).
-	text_editor->cursor_set_line(orig_cursor.x);
-	text_editor->cursor_set_column(orig_cursor.y);
+	text_editor->set_caret_line(orig_cursor.x);
+	text_editor->set_caret_column(orig_cursor.y);
 
 	if (selection_enabled && is_selection_only()) {
 		// Reselect.
@@ -313,8 +313,8 @@ void FindReplaceBar::_replace_all() {
 }
 
 void FindReplaceBar::_get_search_from(int &r_line, int &r_col) {
-	r_line = text_editor->cursor_get_line();
-	r_col = text_editor->cursor_get_column();
+	r_line = text_editor->get_caret_line();
+	r_col = text_editor->get_caret_column();
 
 	if (text_editor->is_selection_active() && is_selection_only()) {
 		return;
@@ -807,10 +807,10 @@ void CodeTextEditor::_reset_zoom() {
 }
 
 void CodeTextEditor::_line_col_changed() {
-	String line = text_editor->get_line(text_editor->cursor_get_line());
+	String line = text_editor->get_line(text_editor->get_caret_line());
 
 	int positional_column = 0;
-	for (int i = 0; i < text_editor->cursor_get_column(); i++) {
+	for (int i = 0; i < text_editor->get_caret_column(); i++) {
 		if (line[i] == '\t') {
 			positional_column += text_editor->get_indent_size(); //tab size
 		} else {
@@ -820,7 +820,7 @@ void CodeTextEditor::_line_col_changed() {
 
 	StringBuilder sb;
 	sb.append("(");
-	sb.append(itos(text_editor->cursor_get_line() + 1).lpad(3));
+	sb.append(itos(text_editor->get_caret_line() + 1).lpad(3));
 	sb.append(",");
 	sb.append(itos(positional_column + 1).lpad(3));
 	sb.append(")");
@@ -952,9 +952,9 @@ void CodeTextEditor::update_editor_settings() {
 	text_editor->set_draw_fold_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding"));
 	text_editor->set_wrap_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/word_wrap"));
 	text_editor->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file"));
-	text_editor->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret"));
-	text_editor->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink"));
-	text_editor->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed"));
+	text_editor->set_caret_type((TextEdit::CaretType)EditorSettings::get_singleton()->get("text_editor/cursor/type").operator int());
+	text_editor->set_caret_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink"));
+	text_editor->set_caret_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed"));
 	text_editor->set_auto_brace_completion_enabled(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete"));
 
 	if (EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guidelines")) {
@@ -1039,8 +1039,8 @@ void CodeTextEditor::convert_indent_to_spaces() {
 		indent += " ";
 	}
 
-	int cursor_line = text_editor->cursor_get_line();
-	int cursor_column = text_editor->cursor_get_column();
+	int cursor_line = text_editor->get_caret_line();
+	int cursor_column = text_editor->get_caret_column();
 
 	bool changed_indentation = false;
 	for (int i = 0; i < text_editor->get_line_count(); i++) {
@@ -1069,7 +1069,7 @@ void CodeTextEditor::convert_indent_to_spaces() {
 		}
 	}
 	if (changed_indentation) {
-		text_editor->cursor_set_column(cursor_column);
+		text_editor->set_caret_column(cursor_column);
 		text_editor->end_complex_operation();
 		text_editor->update();
 	}
@@ -1079,8 +1079,8 @@ void CodeTextEditor::convert_indent_to_tabs() {
 	int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size");
 	indent_size -= 1;
 
-	int cursor_line = text_editor->cursor_get_line();
-	int cursor_column = text_editor->cursor_get_column();
+	int cursor_line = text_editor->get_caret_line();
+	int cursor_column = text_editor->get_caret_column();
 
 	bool changed_indentation = false;
 	for (int i = 0; i < text_editor->get_line_count(); i++) {
@@ -1118,7 +1118,7 @@ void CodeTextEditor::convert_indent_to_tabs() {
 		}
 	}
 	if (changed_indentation) {
-		text_editor->cursor_set_column(cursor_column);
+		text_editor->set_caret_column(cursor_column);
 		text_editor->end_complex_operation();
 		text_editor->update();
 	}
@@ -1176,7 +1176,7 @@ void CodeTextEditor::move_lines_up() {
 		int from_col = text_editor->get_selection_from_column();
 		int to_line = text_editor->get_selection_to_line();
 		int to_column = text_editor->get_selection_to_column();
-		int cursor_line = text_editor->cursor_get_line();
+		int cursor_line = text_editor->get_caret_line();
 
 		for (int i = from_line; i <= to_line; i++) {
 			int line_id = i;
@@ -1190,15 +1190,15 @@ void CodeTextEditor::move_lines_up() {
 			text_editor->unfold_line(next_id);
 
 			text_editor->swap_lines(line_id, next_id);
-			text_editor->cursor_set_line(next_id);
+			text_editor->set_caret_line(next_id);
 		}
 		int from_line_up = from_line > 0 ? from_line - 1 : from_line;
 		int to_line_up = to_line > 0 ? to_line - 1 : to_line;
 		int cursor_line_up = cursor_line > 0 ? cursor_line - 1 : cursor_line;
 		text_editor->select(from_line_up, from_col, to_line_up, to_column);
-		text_editor->cursor_set_line(cursor_line_up);
+		text_editor->set_caret_line(cursor_line_up);
 	} else {
-		int line_id = text_editor->cursor_get_line();
+		int line_id = text_editor->get_caret_line();
 		int next_id = line_id - 1;
 
 		if (line_id == 0 || next_id < 0) {
@@ -1209,7 +1209,7 @@ void CodeTextEditor::move_lines_up() {
 		text_editor->unfold_line(next_id);
 
 		text_editor->swap_lines(line_id, next_id);
-		text_editor->cursor_set_line(next_id);
+		text_editor->set_caret_line(next_id);
 	}
 	text_editor->end_complex_operation();
 	text_editor->update();
@@ -1222,7 +1222,7 @@ void CodeTextEditor::move_lines_down() {
 		int from_col = text_editor->get_selection_from_column();
 		int to_line = text_editor->get_selection_to_line();
 		int to_column = text_editor->get_selection_to_column();
-		int cursor_line = text_editor->cursor_get_line();
+		int cursor_line = text_editor->get_caret_line();
 
 		for (int i = to_line; i >= from_line; i--) {
 			int line_id = i;
@@ -1236,15 +1236,15 @@ void CodeTextEditor::move_lines_down() {
 			text_editor->unfold_line(next_id);
 
 			text_editor->swap_lines(line_id, next_id);
-			text_editor->cursor_set_line(next_id);
+			text_editor->set_caret_line(next_id);
 		}
 		int from_line_down = from_line < text_editor->get_line_count() ? from_line + 1 : from_line;
 		int to_line_down = to_line < text_editor->get_line_count() ? to_line + 1 : to_line;
 		int cursor_line_down = cursor_line < text_editor->get_line_count() ? cursor_line + 1 : cursor_line;
 		text_editor->select(from_line_down, from_col, to_line_down, to_column);
-		text_editor->cursor_set_line(cursor_line_down);
+		text_editor->set_caret_line(cursor_line_down);
 	} else {
-		int line_id = text_editor->cursor_get_line();
+		int line_id = text_editor->get_caret_line();
 		int next_id = line_id + 1;
 
 		if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) {
@@ -1255,7 +1255,7 @@ void CodeTextEditor::move_lines_down() {
 		text_editor->unfold_line(next_id);
 
 		text_editor->swap_lines(line_id, next_id);
-		text_editor->cursor_set_line(next_id);
+		text_editor->set_caret_line(next_id);
 	}
 	text_editor->end_complex_operation();
 	text_editor->update();
@@ -1266,12 +1266,12 @@ void CodeTextEditor::_delete_line(int p_line) {
 	// so `begin_complex_operation` is omitted here
 	text_editor->set_line(p_line, "");
 	if (p_line == 0 && text_editor->get_line_count() > 1) {
-		text_editor->cursor_set_line(1);
-		text_editor->cursor_set_column(0);
+		text_editor->set_caret_line(1);
+		text_editor->set_caret_column(0);
 	}
 	text_editor->backspace();
 	text_editor->unfold_line(p_line);
-	text_editor->cursor_set_line(p_line);
+	text_editor->set_caret_line(p_line);
 }
 
 void CodeTextEditor::delete_lines() {
@@ -1281,42 +1281,42 @@ void CodeTextEditor::delete_lines() {
 		int from_line = text_editor->get_selection_from_line();
 		int count = Math::abs(to_line - from_line) + 1;
 
-		text_editor->cursor_set_line(from_line, false);
+		text_editor->set_caret_line(from_line, false);
 		for (int i = 0; i < count; i++) {
 			_delete_line(from_line);
 		}
 		text_editor->deselect();
 	} else {
-		_delete_line(text_editor->cursor_get_line());
+		_delete_line(text_editor->get_caret_line());
 	}
 	text_editor->end_complex_operation();
 }
 
 void CodeTextEditor::duplicate_selection() {
-	const int cursor_column = text_editor->cursor_get_column();
-	int from_line = text_editor->cursor_get_line();
-	int to_line = text_editor->cursor_get_line();
+	const int cursor_column = text_editor->get_caret_column();
+	int from_line = text_editor->get_caret_line();
+	int to_line = text_editor->get_caret_line();
 	int from_column = 0;
 	int to_column = 0;
 	int cursor_new_line = to_line + 1;
-	int cursor_new_column = text_editor->cursor_get_column();
+	int cursor_new_column = text_editor->get_caret_column();
 	String new_text = "\n" + text_editor->get_line(from_line);
 	bool selection_active = false;
 
-	text_editor->cursor_set_column(text_editor->get_line(from_line).length());
+	text_editor->set_caret_column(text_editor->get_line(from_line).length());
 	if (text_editor->is_selection_active()) {
 		from_column = text_editor->get_selection_from_column();
 		to_column = text_editor->get_selection_to_column();
 
 		from_line = text_editor->get_selection_from_line();
 		to_line = text_editor->get_selection_to_line();
-		cursor_new_line = to_line + text_editor->cursor_get_line() - from_line;
+		cursor_new_line = to_line + text_editor->get_caret_line() - from_line;
 		cursor_new_column = to_column == cursor_column ? 2 * to_column - from_column : to_column;
 		new_text = text_editor->get_selection_text();
 		selection_active = true;
 
-		text_editor->cursor_set_line(to_line);
-		text_editor->cursor_set_column(to_column);
+		text_editor->set_caret_line(to_line);
+		text_editor->set_caret_column(to_column);
 	}
 
 	text_editor->begin_complex_operation();
@@ -1325,9 +1325,9 @@ void CodeTextEditor::duplicate_selection() {
 		text_editor->unfold_line(i);
 	}
 	text_editor->deselect();
-	text_editor->insert_text_at_cursor(new_text);
-	text_editor->cursor_set_line(cursor_new_line);
-	text_editor->cursor_set_column(cursor_new_column);
+	text_editor->insert_text_at_caret(new_text);
+	text_editor->set_caret_line(cursor_new_line);
+	text_editor->set_caret_column(cursor_new_column);
 	if (selection_active) {
 		text_editor->select(to_line, to_column, 2 * to_line - from_line, to_line == from_line ? 2 * to_column - from_column : to_column);
 	}
@@ -1348,7 +1348,7 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
 		}
 
 		int col_to = text_editor->get_selection_to_column();
-		int cursor_pos = text_editor->cursor_get_column();
+		int cursor_pos = text_editor->get_caret_column();
 
 		// Check if all lines in the selected block are commented.
 		bool is_commented = true;
@@ -1377,7 +1377,7 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
 		int offset = (is_commented ? -1 : 1) * delimiter.length();
 		int col_from = text_editor->get_selection_from_column() > 0 ? text_editor->get_selection_from_column() + offset : 0;
 
-		if (is_commented && text_editor->cursor_get_column() == text_editor->get_line(text_editor->cursor_get_line()).length() + 1) {
+		if (is_commented && text_editor->get_caret_column() == text_editor->get_line(text_editor->get_caret_line()).length() + 1) {
 			cursor_pos += 1;
 		}
 
@@ -1385,19 +1385,19 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
 			col_to += offset;
 		}
 
-		if (text_editor->cursor_get_column() != 0) {
+		if (text_editor->get_caret_column() != 0) {
 			cursor_pos += offset;
 		}
 
 		text_editor->select(begin, col_from, text_editor->get_selection_to_line(), col_to);
-		text_editor->cursor_set_column(cursor_pos);
+		text_editor->set_caret_column(cursor_pos);
 
 	} else {
-		int begin = text_editor->cursor_get_line();
+		int begin = text_editor->get_caret_line();
 		String line_text = text_editor->get_line(begin);
 		int delimiter_length = delimiter.length();
 
-		int col = text_editor->cursor_get_column();
+		int col = text_editor->get_caret_column();
 		if (line_text.begins_with(delimiter)) {
 			line_text = line_text.substr(delimiter_length, line_text.length());
 			col -= delimiter_length;
@@ -1407,7 +1407,7 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
 		}
 
 		text_editor->set_line(begin, line_text);
-		text_editor->cursor_set_column(col);
+		text_editor->set_caret_column(col);
 	}
 	text_editor->end_complex_operation();
 	text_editor->update();
@@ -1428,7 +1428,7 @@ void CodeTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) {
 
 void CodeTextEditor::goto_line_centered(int p_line) {
 	goto_line(p_line);
-	text_editor->call_deferred(SNAME("center_viewport_to_cursor"));
+	text_editor->call_deferred(SNAME("center_viewport_to_caret"));
 }
 
 void CodeTextEditor::set_executing_line(int p_line) {
@@ -1444,8 +1444,8 @@ Variant CodeTextEditor::get_edit_state() {
 
 	state["scroll_position"] = text_editor->get_v_scroll();
 	state["h_scroll_position"] = text_editor->get_h_scroll();
-	state["column"] = text_editor->cursor_get_column();
-	state["row"] = text_editor->cursor_get_line();
+	state["column"] = text_editor->get_caret_column();
+	state["row"] = text_editor->get_caret_line();
 
 	state["selection"] = get_text_editor()->is_selection_active();
 	if (get_text_editor()->is_selection_active()) {
@@ -1469,8 +1469,8 @@ void CodeTextEditor::set_edit_state(const Variant &p_state) {
 	Dictionary state = p_state;
 
 	/* update the row first as it sets the column to 0 */
-	text_editor->cursor_set_line(state["row"]);
-	text_editor->cursor_set_column(state["column"]);
+	text_editor->set_caret_line(state["row"]);
+	text_editor->set_caret_column(state["column"]);
 	text_editor->set_v_scroll(state["scroll_position"]);
 	text_editor->set_h_scroll(state["h_scroll_position"]);
 
@@ -1517,9 +1517,9 @@ void CodeTextEditor::set_error_pos(int p_line, int p_column) {
 void CodeTextEditor::goto_error() {
 	if (error->get_text() != "") {
 		text_editor->unfold_line(error_line);
-		text_editor->cursor_set_line(error_line);
-		text_editor->cursor_set_column(error_column);
-		text_editor->center_viewport_to_cursor();
+		text_editor->set_caret_line(error_line);
+		text_editor->set_caret_column(error_column);
+		text_editor->center_viewport_to_caret();
 	}
 }
 
@@ -1712,7 +1712,7 @@ void CodeTextEditor::set_warning_count(int p_warning_count) {
 }
 
 void CodeTextEditor::toggle_bookmark() {
-	int line = text_editor->cursor_get_line();
+	int line = text_editor->get_caret_line();
 	text_editor->set_line_as_bookmarked(line, !text_editor->is_line_bookmarked(line));
 }
 
@@ -1722,18 +1722,18 @@ void CodeTextEditor::goto_next_bookmark() {
 		return;
 	}
 
-	int line = text_editor->cursor_get_line();
+	int line = text_editor->get_caret_line();
 	if (line >= (int)bmarks[bmarks.size() - 1]) {
 		text_editor->unfold_line(bmarks[0]);
-		text_editor->cursor_set_line(bmarks[0]);
-		text_editor->center_viewport_to_cursor();
+		text_editor->set_caret_line(bmarks[0]);
+		text_editor->center_viewport_to_caret();
 	} else {
 		for (int i = 0; i < bmarks.size(); i++) {
 			int bmark_line = bmarks[i];
 			if (bmark_line > line) {
 				text_editor->unfold_line(bmark_line);
-				text_editor->cursor_set_line(bmark_line);
-				text_editor->center_viewport_to_cursor();
+				text_editor->set_caret_line(bmark_line);
+				text_editor->center_viewport_to_caret();
 				return;
 			}
 		}
@@ -1746,18 +1746,18 @@ void CodeTextEditor::goto_prev_bookmark() {
 		return;
 	}
 
-	int line = text_editor->cursor_get_line();
+	int line = text_editor->get_caret_line();
 	if (line <= (int)bmarks[0]) {
 		text_editor->unfold_line(bmarks[bmarks.size() - 1]);
-		text_editor->cursor_set_line(bmarks[bmarks.size() - 1]);
-		text_editor->center_viewport_to_cursor();
+		text_editor->set_caret_line(bmarks[bmarks.size() - 1]);
+		text_editor->center_viewport_to_caret();
 	} else {
 		for (int i = bmarks.size(); i >= 0; i--) {
 			int bmark_line = bmarks[i];
 			if (bmark_line < line) {
 				text_editor->unfold_line(bmark_line);
-				text_editor->cursor_set_line(bmark_line);
-				text_editor->center_viewport_to_cursor();
+				text_editor->set_caret_line(bmark_line);
+				text_editor->center_viewport_to_caret();
 				return;
 			}
 		}
@@ -1913,7 +1913,7 @@ CodeTextEditor::CodeTextEditor() {
 	line_and_col_txt->set_mouse_filter(MOUSE_FILTER_STOP);
 
 	text_editor->connect("gui_input", callable_mp(this, &CodeTextEditor::_text_editor_gui_input));
-	text_editor->connect("cursor_changed", callable_mp(this, &CodeTextEditor::_line_col_changed));
+	text_editor->connect("caret_changed", callable_mp(this, &CodeTextEditor::_line_col_changed));
 	text_editor->connect("text_changed", callable_mp(this, &CodeTextEditor::_text_changed));
 	text_editor->connect("request_code_completion", callable_mp(this, &CodeTextEditor::_complete_request));
 	TypedArray<String> cs;

+ 2 - 1
editor/editor_settings.cpp

@@ -546,7 +546,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
 
 	// Cursor
 	_initial_set("text_editor/cursor/scroll_past_end_of_file", false);
-	_initial_set("text_editor/cursor/block_caret", false);
+	_initial_set("text_editor/cursor/type", 0);
+	hints["text_editor/cursor/type"] = PropertyInfo(Variant::INT, "text_editor/cursor/type", PROPERTY_HINT_ENUM, "Line,Block");
 	_initial_set("text_editor/cursor/caret_blink", true);
 	_initial_set("text_editor/cursor/caret_blink_speed", 0.5);
 	hints["text_editor/cursor/caret_blink_speed"] = PropertyInfo(Variant::FLOAT, "text_editor/cursor/caret_blink_speed", PROPERTY_HINT_RANGE, "0.1, 10, 0.01");

+ 44 - 43
editor/plugins/script_text_editor.cpp

@@ -248,7 +248,7 @@ void ScriptTextEditor::_warning_clicked(Variant p_line) {
 
 void ScriptTextEditor::_error_clicked(Variant p_line) {
 	if (p_line.get_type() == Variant::INT) {
-		code_editor->get_text_editor()->cursor_set_line(p_line.operator int64_t());
+		code_editor->get_text_editor()->set_caret_line(p_line.operator int64_t());
 	}
 }
 
@@ -256,14 +256,14 @@ void ScriptTextEditor::reload_text() {
 	ERR_FAIL_COND(script.is_null());
 
 	CodeEdit *te = code_editor->get_text_editor();
-	int column = te->cursor_get_column();
-	int row = te->cursor_get_line();
+	int column = te->get_caret_column();
+	int row = te->get_caret_line();
 	int h = te->get_h_scroll();
 	int v = te->get_v_scroll();
 
 	te->set_text(script->get_source_code());
-	te->cursor_set_line(row);
-	te->cursor_set_column(column);
+	te->set_caret_line(row);
+	te->set_caret_column(column);
 	te->set_h_scroll(h);
 	te->set_v_scroll(v);
 
@@ -281,12 +281,12 @@ void ScriptTextEditor::add_callback(const String &p_function, PackedStringArray
 		pos = code_editor->get_text_editor()->get_line_count() + 2;
 		String func = script->get_language()->make_function("", p_function, p_args);
 		//code=code+func;
-		code_editor->get_text_editor()->cursor_set_line(pos + 1);
-		code_editor->get_text_editor()->cursor_set_column(1000000); //none shall be that big
-		code_editor->get_text_editor()->insert_text_at_cursor("\n\n" + func);
+		code_editor->get_text_editor()->set_caret_line(pos + 1);
+		code_editor->get_text_editor()->set_caret_column(1000000); //none shall be that big
+		code_editor->get_text_editor()->insert_text_at_caret("\n\n" + func);
 	}
-	code_editor->get_text_editor()->cursor_set_line(pos);
-	code_editor->get_text_editor()->cursor_set_column(1);
+	code_editor->get_text_editor()->set_caret_line(pos);
+	code_editor->get_text_editor()->set_caret_column(1);
 }
 
 bool ScriptTextEditor::show_members_overview() {
@@ -726,7 +726,7 @@ void ScriptTextEditor::_breakpoint_item_pressed(int p_idx) {
 		_edit_option(breakpoints_menu->get_item_id(p_idx));
 	} else {
 		code_editor->goto_line(breakpoints_menu->get_item_metadata(p_idx));
-		code_editor->get_text_editor()->call_deferred(SNAME("center_viewport_to_cursor")); //Need to be deferred, because goto uses call_deferred().
+		code_editor->get_text_editor()->call_deferred(SNAME("center_viewport_to_caret")); //Need to be deferred, because goto uses call_deferred().
 	}
 }
 
@@ -1054,7 +1054,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
 			code_editor->duplicate_selection();
 		} break;
 		case EDIT_TOGGLE_FOLD_LINE: {
-			tx->toggle_foldable_line(tx->cursor_get_line());
+			tx->toggle_foldable_line(tx->get_caret_line());
 			tx->update();
 		} break;
 		case EDIT_FOLD_ALL_LINES: {
@@ -1142,7 +1142,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
 			}
 
 			code_editor->get_text_editor()->begin_complex_operation(); //prevents creating a two-step undo
-			code_editor->get_text_editor()->insert_text_at_cursor(String("\n").join(results));
+			code_editor->get_text_editor()->insert_text_at_caret(String("\n").join(results));
 			code_editor->get_text_editor()->end_complex_operation();
 		} break;
 		case SEARCH_FIND: {
@@ -1189,7 +1189,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
 			code_editor->remove_all_bookmarks();
 		} break;
 		case DEBUG_TOGGLE_BREAKPOINT: {
-			int line = tx->cursor_get_line();
+			int line = tx->get_caret_line();
 			bool dobreak = !tx->is_line_breakpointed(line);
 			tx->set_line_as_breakpoint(line, dobreak);
 			EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak);
@@ -1210,20 +1210,20 @@ void ScriptTextEditor::_edit_option(int p_op) {
 				return;
 			}
 
-			int line = tx->cursor_get_line();
+			int line = tx->get_caret_line();
 
 			// wrap around
 			if (line >= (int)bpoints[bpoints.size() - 1]) {
 				tx->unfold_line(bpoints[0]);
-				tx->cursor_set_line(bpoints[0]);
-				tx->center_viewport_to_cursor();
+				tx->set_caret_line(bpoints[0]);
+				tx->center_viewport_to_caret();
 			} else {
 				for (int i = 0; i < bpoints.size(); i++) {
 					int bline = bpoints[i];
 					if (bline > line) {
 						tx->unfold_line(bline);
-						tx->cursor_set_line(bline);
-						tx->center_viewport_to_cursor();
+						tx->set_caret_line(bline);
+						tx->center_viewport_to_caret();
 						return;
 					}
 				}
@@ -1236,19 +1236,19 @@ void ScriptTextEditor::_edit_option(int p_op) {
 				return;
 			}
 
-			int line = tx->cursor_get_line();
+			int line = tx->get_caret_line();
 			// wrap around
 			if (line <= (int)bpoints[0]) {
 				tx->unfold_line(bpoints[bpoints.size() - 1]);
-				tx->cursor_set_line(bpoints[bpoints.size() - 1]);
-				tx->center_viewport_to_cursor();
+				tx->set_caret_line(bpoints[bpoints.size() - 1]);
+				tx->center_viewport_to_caret();
 			} else {
 				for (int i = bpoints.size(); i >= 0; i--) {
 					int bline = bpoints[i];
 					if (bline < line) {
 						tx->unfold_line(bline);
-						tx->cursor_set_line(bline);
-						tx->center_viewport_to_cursor();
+						tx->set_caret_line(bline);
+						tx->center_viewport_to_caret();
 						return;
 					}
 				}
@@ -1258,19 +1258,19 @@ void ScriptTextEditor::_edit_option(int p_op) {
 		case HELP_CONTEXTUAL: {
 			String text = tx->get_selection_text();
 			if (text == "") {
-				text = tx->get_word_under_cursor();
+				text = tx->get_word_under_caret();
 			}
 			if (text != "") {
 				emit_signal(SNAME("request_help"), text);
 			}
 		} break;
 		case LOOKUP_SYMBOL: {
-			String text = tx->get_word_under_cursor();
+			String text = tx->get_word_under_caret();
 			if (text == "") {
 				text = tx->get_selection_text();
 			}
 			if (text != "") {
-				_lookup_symbol(text, tx->cursor_get_line(), tx->cursor_get_column());
+				_lookup_symbol(text, tx->get_caret_line(), tx->get_caret_column());
 			}
 		} break;
 	}
@@ -1436,9 +1436,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
 			return;
 		}
 
-		te->cursor_set_line(row);
-		te->cursor_set_column(col);
-		te->insert_text_at_cursor(res->get_path());
+		te->set_caret_line(row);
+		te->set_caret_column(col);
+		te->insert_text_at_caret(res->get_path());
 	}
 
 	if (d.has("type") && (String(d["type"]) == "files" || String(d["type"]) == "files_and_dirs")) {
@@ -1459,9 +1459,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
 			}
 		}
 
-		te->cursor_set_line(row);
-		te->cursor_set_column(col);
-		te->insert_text_at_cursor(text_to_drop);
+		te->set_caret_line(row);
+		te->set_caret_column(col);
+		te->insert_text_at_caret(text_to_drop);
 	}
 
 	if (d.has("type") && String(d["type"]) == "nodes") {
@@ -1489,9 +1489,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
 			text_to_drop += "\"" + path.c_escape() + "\"";
 		}
 
-		te->cursor_set_line(row);
-		te->cursor_set_column(col);
-		te->insert_text_at_cursor(text_to_drop);
+		te->set_caret_line(row);
+		te->set_caret_column(col);
+		te->insert_text_at_caret(text_to_drop);
 	}
 }
 
@@ -1505,8 +1505,9 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
 	if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_RIGHT && mb->is_pressed()) {
 		local_pos = mb->get_global_position() - tx->get_global_position();
 		create_menu = true;
-	} else if (k.is_valid() && k->get_keycode() == KEY_MENU) {
-		local_pos = tx->_get_cursor_pixel_pos();
+	} else if (k.is_valid() && k->is_action("ui_menu", true)) {
+		tx->adjust_viewport_to_caret();
+		local_pos = tx->get_caret_draw_pos();
 		create_menu = true;
 	}
 
@@ -1514,8 +1515,8 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
 		int col, row;
 		tx->_get_mouse_pos(local_pos, row, col);
 
-		tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
-		if (tx->is_right_click_moving_caret()) {
+		tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
+		if (tx->is_move_caret_on_right_click_enabled()) {
 			if (tx->is_selection_active()) {
 				int from_line = tx->get_selection_from_line();
 				int to_line = tx->get_selection_to_line();
@@ -1528,14 +1529,14 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
 				}
 			}
 			if (!tx->is_selection_active()) {
-				tx->cursor_set_line(row, true, false);
-				tx->cursor_set_column(col);
+				tx->set_caret_line(row, false, false);
+				tx->set_caret_column(col);
 			}
 		}
 
 		String word_at_pos = tx->get_word_at_pos(local_pos);
 		if (word_at_pos == "") {
-			word_at_pos = tx->get_word_under_cursor();
+			word_at_pos = tx->get_word_under_caret();
 		}
 		if (word_at_pos == "") {
 			word_at_pos = tx->get_selection_text();

+ 12 - 11
editor/plugins/shader_editor_plugin.cpp

@@ -74,14 +74,14 @@ void ShaderTextEditor::reload_text() {
 	ERR_FAIL_COND(shader.is_null());
 
 	CodeEdit *te = get_text_editor();
-	int column = te->cursor_get_column();
-	int row = te->cursor_get_line();
+	int column = te->get_caret_column();
+	int row = te->get_caret_line();
 	int h = te->get_h_scroll();
 	int v = te->get_v_scroll();
 
 	te->set_text(shader->get_code());
-	te->cursor_set_line(row);
-	te->cursor_set_column(column);
+	te->set_caret_line(row);
+	te->set_caret_column(column);
 	te->set_h_scroll(h);
 	te->set_v_scroll(v);
 
@@ -408,7 +408,7 @@ void ShaderEditor::_show_warnings_panel(bool p_show) {
 
 void ShaderEditor::_warning_clicked(Variant p_line) {
 	if (p_line.get_type() == Variant::INT) {
-		shader_editor->get_text_editor()->cursor_set_line(p_line.operator int64_t());
+		shader_editor->get_text_editor()->set_caret_line(p_line.operator int64_t());
 	}
 }
 
@@ -553,9 +553,9 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
 			int col, row;
 			CodeEdit *tx = shader_editor->get_text_editor();
 			tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col);
-			tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
+			tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
 
-			if (tx->is_right_click_moving_caret()) {
+			if (tx->is_move_caret_on_right_click_enabled()) {
 				if (tx->is_selection_active()) {
 					int from_line = tx->get_selection_from_line();
 					int to_line = tx->get_selection_to_line();
@@ -568,8 +568,8 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
 					}
 				}
 				if (!tx->is_selection_active()) {
-					tx->cursor_set_line(row, true, false);
-					tx->cursor_set_column(col);
+					tx->set_caret_line(row, true, false);
+					tx->set_caret_column(col);
 				}
 			}
 			_make_context_menu(tx->is_selection_active(), get_local_mouse_position());
@@ -577,9 +577,10 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
 	}
 
 	Ref<InputEventKey> k = ev;
-	if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_MENU) {
+	if (k.is_valid() && k->is_pressed() && k->is_action("ui_menu", true)) {
 		CodeEdit *tx = shader_editor->get_text_editor();
-		_make_context_menu(tx->is_selection_active(), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->_get_cursor_pixel_pos()));
+		tx->adjust_viewport_to_caret();
+		_make_context_menu(tx->is_selection_active(), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->get_caret_draw_pos()));
 		context_menu->grab_focus();
 	}
 }

+ 13 - 12
editor/plugins/text_editor.cpp

@@ -132,14 +132,14 @@ void TextEditor::reload_text() {
 	ERR_FAIL_COND(text_file.is_null());
 
 	CodeEdit *te = code_editor->get_text_editor();
-	int column = te->cursor_get_column();
-	int row = te->cursor_get_line();
+	int column = te->get_caret_column();
+	int row = te->get_caret_line();
 	int h = te->get_h_scroll();
 	int v = te->get_v_scroll();
 
 	te->set_text(text_file->get_text());
-	te->cursor_set_line(row);
-	te->cursor_set_column(column);
+	te->set_caret_line(row);
+	te->set_caret_column(column);
 	te->set_h_scroll(h);
 	te->set_v_scroll(v);
 
@@ -332,7 +332,7 @@ void TextEditor::_edit_option(int p_op) {
 			code_editor->duplicate_selection();
 		} break;
 		case EDIT_TOGGLE_FOLD_LINE: {
-			tx->toggle_foldable_line(tx->cursor_get_line());
+			tx->toggle_foldable_line(tx->get_caret_line());
 			tx->update();
 		} break;
 		case EDIT_FOLD_ALL_LINES: {
@@ -431,11 +431,11 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
 			CodeEdit *tx = code_editor->get_text_editor();
 			tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col);
 
-			tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
+			tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret"));
 			bool can_fold = tx->can_fold_line(row);
 			bool is_folded = tx->is_line_folded(row);
 
-			if (tx->is_right_click_moving_caret()) {
+			if (tx->is_move_caret_on_right_click_enabled()) {
 				if (tx->is_selection_active()) {
 					int from_line = tx->get_selection_from_line();
 					int to_line = tx->get_selection_to_line();
@@ -448,8 +448,8 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
 					}
 				}
 				if (!tx->is_selection_active()) {
-					tx->cursor_set_line(row, true, false);
-					tx->cursor_set_column(col);
+					tx->set_caret_line(row, true, false);
+					tx->set_caret_column(col);
 				}
 			}
 
@@ -460,10 +460,11 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
 	}
 
 	Ref<InputEventKey> k = ev;
-	if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_MENU) {
+	if (k.is_valid() && k->is_pressed() && k->is_action("ui_menu", true)) {
 		CodeEdit *tx = code_editor->get_text_editor();
-		int line = tx->cursor_get_line();
-		_make_context_menu(tx->is_selection_active(), tx->can_fold_line(line), tx->is_line_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->_get_cursor_pixel_pos()));
+		int line = tx->get_caret_line();
+		tx->adjust_viewport_to_caret();
+		_make_context_menu(tx->is_selection_active(), tx->can_fold_line(line), tx->is_line_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->get_caret_draw_pos()));
 		context_menu->grab_focus();
 	}
 }

+ 77 - 77
scene/gui/code_edit.cpp

@@ -559,39 +559,39 @@ void CodeEdit::_handle_unicode_input(const uint32_t p_unicode) {
 		begin_complex_operation();
 
 		/* Make sure we don't try and remove empty space. */
-		if (cursor_get_column() < get_line(cursor_get_line()).length()) {
-			_remove_text(cursor_get_line(), cursor_get_column(), cursor_get_line(), cursor_get_column() + 1);
+		if (get_caret_column() < get_line(get_caret_line()).length()) {
+			_remove_text(get_caret_line(), get_caret_column(), get_caret_line(), get_caret_column() + 1);
 		}
 	}
 
 	const char32_t chr[2] = { (char32_t)p_unicode, 0 };
 
 	if (auto_brace_completion_enabled) {
-		int cl = cursor_get_line();
-		int cc = cursor_get_column();
+		int cl = get_caret_line();
+		int cc = get_caret_column();
 		int caret_move_offset = 1;
 
 		int post_brace_pair = cc < get_line(cl).length() ? _get_auto_brace_pair_close_at_pos(cl, cc) : -1;
 
 		if (has_string_delimiter(chr) && cc > 0 && _is_char(get_line(cl)[cc - 1]) && post_brace_pair == -1) {
-			insert_text_at_cursor(chr);
+			insert_text_at_caret(chr);
 		} else if (cc < get_line(cl).length() && _is_char(get_line(cl)[cc])) {
-			insert_text_at_cursor(chr);
+			insert_text_at_caret(chr);
 		} else if (post_brace_pair != -1 && auto_brace_completion_pairs[post_brace_pair].close_key[0] == chr[0]) {
 			caret_move_offset = auto_brace_completion_pairs[post_brace_pair].close_key.length();
 		} else if (is_in_comment(cl, cc) != -1 || (is_in_string(cl, cc) != -1 && has_string_delimiter(chr))) {
-			insert_text_at_cursor(chr);
+			insert_text_at_caret(chr);
 		} else {
-			insert_text_at_cursor(chr);
+			insert_text_at_caret(chr);
 
 			int pre_brace_pair = _get_auto_brace_pair_open_at_pos(cl, cc + 1);
 			if (pre_brace_pair != -1) {
-				insert_text_at_cursor(auto_brace_completion_pairs[pre_brace_pair].close_key);
+				insert_text_at_caret(auto_brace_completion_pairs[pre_brace_pair].close_key);
 			}
 		}
-		cursor_set_column(cc + caret_move_offset);
+		set_caret_column(cc + caret_move_offset);
 	} else {
-		insert_text_at_cursor(chr);
+		insert_text_at_caret(chr);
 	}
 
 	if ((is_insert_mode() && !had_selection) || (had_selection)) {
@@ -604,8 +604,8 @@ void CodeEdit::_backspace() {
 		return;
 	}
 
-	int cc = cursor_get_column();
-	int cl = cursor_get_line();
+	int cc = get_caret_column();
+	int cl = get_caret_line();
 
 	if (cc == 0 && cl == 0) {
 		return;
@@ -617,7 +617,7 @@ void CodeEdit::_backspace() {
 	}
 
 	if (cl > 0 && is_line_hidden(cl - 1)) {
-		unfold_line(cursor_get_line() - 1);
+		unfold_line(get_caret_line() - 1);
 	}
 
 	int prev_line = cc ? cl : cl - 1;
@@ -635,8 +635,8 @@ void CodeEdit::_backspace() {
 			} else {
 				_remove_text(prev_line, prev_column, cl, cc);
 			}
-			cursor_set_line(prev_line, false, true);
-			cursor_set_column(prev_column);
+			set_caret_line(prev_line, false, true);
+			set_caret_column(prev_column);
 			return;
 		}
 	}
@@ -652,8 +652,8 @@ void CodeEdit::_backspace() {
 
 	_remove_text(prev_line, prev_column, cl, cc);
 
-	cursor_set_line(prev_line, false, true);
-	cursor_set_column(prev_column);
+	set_caret_line(prev_line, false, true);
+	set_caret_column(prev_column);
 }
 
 /* Indent management */
@@ -724,13 +724,13 @@ void CodeEdit::do_indent() {
 	}
 
 	if (!indent_using_spaces) {
-		insert_text_at_cursor("\t");
+		insert_text_at_caret("\t");
 		return;
 	}
 
-	int spaces_to_add = _calculate_spaces_till_next_right_indent(cursor_get_column());
+	int spaces_to_add = _calculate_spaces_till_next_right_indent(get_caret_column());
 	if (spaces_to_add > 0) {
-		insert_text_at_cursor(String(" ").repeat(spaces_to_add));
+		insert_text_at_caret(String(" ").repeat(spaces_to_add));
 	}
 }
 
@@ -745,7 +745,7 @@ void CodeEdit::indent_lines() {
 	/* Default is 1 for tab indentation.                                                   */
 	int selection_offset = 1;
 
-	int start_line = cursor_get_line();
+	int start_line = get_caret_line();
 	int end_line = start_line;
 	if (is_selection_active()) {
 		start_line = get_selection_from_line();
@@ -780,7 +780,7 @@ void CodeEdit::indent_lines() {
 	if (is_selection_active()) {
 		select(start_line, get_selection_from_column() + selection_offset, get_selection_to_line(), get_selection_to_column() + selection_offset);
 	}
-	cursor_set_column(cursor_get_column() + selection_offset, false);
+	set_caret_column(get_caret_column() + selection_offset, false);
 
 	end_complex_operation();
 }
@@ -790,19 +790,19 @@ void CodeEdit::do_unindent() {
 		return;
 	}
 
-	int cc = cursor_get_column();
+	int cc = get_caret_column();
 
 	if (is_selection_active() || cc <= 0) {
 		unindent_lines();
 		return;
 	}
 
-	int cl = cursor_get_line();
+	int cl = get_caret_line();
 	const String &line = get_line(cl);
 
 	if (line[cc - 1] == '\t') {
 		_remove_text(cl, cc - 1, cl, cc);
-		cursor_set_column(MAX(0, cc - 1));
+		set_caret_column(MAX(0, cc - 1));
 		return;
 	}
 
@@ -819,7 +819,7 @@ void CodeEdit::do_unindent() {
 			}
 		}
 		_remove_text(cl, cc - spaces_to_remove, cl, cc);
-		cursor_set_column(MAX(0, cc - spaces_to_remove));
+		set_caret_column(MAX(0, cc - spaces_to_remove));
 	}
 }
 
@@ -835,9 +835,9 @@ void CodeEdit::unindent_lines() {
 	/* therefore we just remember initial values and at the end of the operation offset them by number of removed characters.   */
 	int removed_characters = 0;
 	int initial_selection_end_column = 0;
-	int initial_cursor_column = cursor_get_column();
+	int initial_cursor_column = get_caret_column();
 
-	int start_line = cursor_get_line();
+	int start_line = get_caret_line();
 	int end_line = start_line;
 	if (is_selection_active()) {
 		start_line = get_selection_from_line();
@@ -893,7 +893,7 @@ void CodeEdit::unindent_lines() {
 			select(get_selection_from_line(), get_selection_from_column(), get_selection_to_line(), initial_selection_end_column - removed_characters);
 		}
 	}
-	cursor_set_column(initial_cursor_column - removed_characters, false);
+	set_caret_column(initial_cursor_column - removed_characters, false);
 
 	end_complex_operation();
 }
@@ -915,8 +915,8 @@ void CodeEdit::_new_line(bool p_split_current_line, bool p_above) {
 		return;
 	}
 
-	const int cc = cursor_get_column();
-	const int cl = cursor_get_line();
+	const int cc = get_caret_column();
+	const int cl = get_caret_line();
 	const String line = get_line(cl);
 
 	String ins = "\n";
@@ -992,24 +992,24 @@ void CodeEdit::_new_line(bool p_split_current_line, bool p_above) {
 	if (!p_split_current_line) {
 		if (p_above) {
 			if (cl > 0) {
-				cursor_set_line(cl - 1, false);
-				cursor_set_column(get_line(cursor_get_line()).length());
+				set_caret_line(cl - 1, false);
+				set_caret_column(get_line(get_caret_line()).length());
 			} else {
-				cursor_set_column(0);
+				set_caret_column(0);
 				first_line = true;
 			}
 		} else {
-			cursor_set_column(line.length());
+			set_caret_column(line.length());
 		}
 	}
 
-	insert_text_at_cursor(ins);
+	insert_text_at_caret(ins);
 
 	if (first_line) {
-		cursor_set_line(0);
+		set_caret_line(0);
 	} else if (brace_indent) {
-		cursor_set_line(cursor_get_line() - 1, false);
-		cursor_set_column(get_line(cursor_get_line()).length());
+		set_caret_line(get_caret_line() - 1, false);
+		set_caret_column(get_line(get_caret_line()).length());
 	}
 
 	end_complex_operation();
@@ -1434,9 +1434,9 @@ void CodeEdit::fold_line(int p_line) {
 	}
 
 	/* Reset caret. */
-	if (is_line_hidden(cursor_get_line())) {
-		cursor_set_line(p_line, false, false);
-		cursor_set_column(get_line(p_line).length(), false);
+	if (is_line_hidden(get_caret_line())) {
+		set_caret_line(p_line, false, false);
+		set_caret_column(get_line(p_line).length(), false);
 	}
 	update();
 }
@@ -1710,11 +1710,11 @@ String CodeEdit::get_text_for_code_completion() const {
 	for (int i = 0; i < text_size; i++) {
 		String line = get_line(i);
 
-		if (i == cursor_get_line()) {
-			completion_text += line.substr(0, cursor_get_column());
+		if (i == get_caret_line()) {
+			completion_text += line.substr(0, get_caret_column());
 			/* Not unicode, represents the caret. */
 			completion_text += String::chr(0xFFFF);
-			completion_text += line.substr(cursor_get_column(), line.size());
+			completion_text += line.substr(get_caret_column(), line.size());
 		} else {
 			completion_text += line;
 		}
@@ -1761,10 +1761,10 @@ void CodeEdit::request_code_completion(bool p_force) {
 		return;
 	}
 
-	String line = get_line(cursor_get_line());
-	int ofs = CLAMP(cursor_get_column(), 0, line.length());
+	String line = get_line(get_caret_line());
+	int ofs = CLAMP(get_caret_column(), 0, line.length());
 
-	if (ofs > 0 && (is_in_string(cursor_get_line(), ofs) != -1 || _is_char(line[ofs - 1]) || code_completion_prefixes.has(String::chr(line[ofs - 1])))) {
+	if (ofs > 0 && (is_in_string(get_caret_line(), ofs) != -1 || _is_char(line[ofs - 1]) || code_completion_prefixes.has(String::chr(line[ofs - 1])))) {
 		emit_signal(SNAME("request_code_completion"));
 	} else if (ofs > 1 && line[ofs - 1] == ' ' && code_completion_prefixes.has(String::chr(line[ofs - 2]))) {
 		emit_signal(SNAME("request_code_completion"));
@@ -1850,7 +1850,7 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
 	}
 	begin_complex_operation();
 
-	int caret_line = cursor_get_line();
+	int caret_line = get_caret_line();
 
 	const String &insert_text = code_completion_options[code_completion_current_selected].insert_text;
 	const String &display_text = code_completion_options[code_completion_current_selected].display;
@@ -1858,7 +1858,7 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
 	if (p_replace) {
 		/* Find end of current section */
 		const String line = get_line(caret_line);
-		int caret_col = cursor_get_column();
+		int caret_col = get_caret_column();
 		int caret_remove_line = caret_line;
 
 		bool merge_text = true;
@@ -1881,13 +1881,13 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
 		}
 
 		/* Replace. */
-		_remove_text(caret_line, cursor_get_column() - code_completion_base.length(), caret_remove_line, caret_col);
-		cursor_set_column(cursor_get_column() - code_completion_base.length(), false);
-		insert_text_at_cursor(insert_text);
+		_remove_text(caret_line, get_caret_column() - code_completion_base.length(), caret_remove_line, caret_col);
+		set_caret_column(get_caret_column() - code_completion_base.length(), false);
+		insert_text_at_caret(insert_text);
 	} else {
 		/* Get first non-matching char. */
 		const String line = get_line(caret_line);
-		int caret_col = cursor_get_column();
+		int caret_col = get_caret_column();
 		int matching_chars = code_completion_base.length();
 		for (; matching_chars <= insert_text.length(); matching_chars++) {
 			if (caret_col >= line.length() || line[caret_col] != insert_text[matching_chars]) {
@@ -1897,41 +1897,41 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
 		}
 
 		/* Remove base completion text. */
-		_remove_text(caret_line, cursor_get_column() - code_completion_base.length(), caret_line, cursor_get_column());
-		cursor_set_column(cursor_get_column() - code_completion_base.length(), false);
+		_remove_text(caret_line, get_caret_column() - code_completion_base.length(), caret_line, get_caret_column());
+		set_caret_column(get_caret_column() - code_completion_base.length(), false);
 
 		/* Merge with text. */
-		insert_text_at_cursor(insert_text.substr(0, code_completion_base.length()));
-		cursor_set_column(caret_col, false);
-		insert_text_at_cursor(insert_text.substr(matching_chars));
+		insert_text_at_caret(insert_text.substr(0, code_completion_base.length()));
+		set_caret_column(caret_col, false);
+		insert_text_at_caret(insert_text.substr(matching_chars));
 	}
 
 	/* Handle merging of symbols eg strings, brackets. */
 	const String line = get_line(caret_line);
-	char32_t next_char = line[cursor_get_column()];
+	char32_t next_char = line[get_caret_column()];
 	char32_t last_completion_char = insert_text[insert_text.length() - 1];
 	char32_t last_completion_char_display = display_text[display_text.length() - 1];
 
-	int pre_brace_pair = cursor_get_column() > 0 ? _get_auto_brace_pair_open_at_pos(caret_line, cursor_get_column()) : -1;
-	int post_brace_pair = cursor_get_column() < get_line(caret_line).length() ? _get_auto_brace_pair_close_at_pos(caret_line, cursor_get_column()) : -1;
+	int pre_brace_pair = get_caret_column() > 0 ? _get_auto_brace_pair_open_at_pos(caret_line, get_caret_column()) : -1;
+	int post_brace_pair = get_caret_column() < get_line(caret_line).length() ? _get_auto_brace_pair_close_at_pos(caret_line, get_caret_column()) : -1;
 
 	if (post_brace_pair != -1 && (last_completion_char == next_char || last_completion_char_display == next_char)) {
-		_remove_text(caret_line, cursor_get_column(), caret_line, cursor_get_column() + 1);
+		_remove_text(caret_line, get_caret_column(), caret_line, get_caret_column() + 1);
 	}
 
 	if (pre_brace_pair != -1 && pre_brace_pair != post_brace_pair && (last_completion_char == next_char || last_completion_char_display == next_char)) {
-		_remove_text(caret_line, cursor_get_column(), caret_line, cursor_get_column() + 1);
+		_remove_text(caret_line, get_caret_column(), caret_line, get_caret_column() + 1);
 	} else if (auto_brace_completion_enabled && pre_brace_pair != -1 && post_brace_pair == -1) {
-		insert_text_at_cursor(auto_brace_completion_pairs[pre_brace_pair].close_key);
-		cursor_set_column(cursor_get_column() - auto_brace_completion_pairs[pre_brace_pair].close_key.length());
+		insert_text_at_caret(auto_brace_completion_pairs[pre_brace_pair].close_key);
+		set_caret_column(get_caret_column() - auto_brace_completion_pairs[pre_brace_pair].close_key.length());
 	}
 
-	if (pre_brace_pair == -1 && post_brace_pair == -1 && cursor_get_column() > 0 && cursor_get_column() < get_line(caret_line).length()) {
-		pre_brace_pair = _get_auto_brace_pair_open_at_pos(caret_line, cursor_get_column() + 1);
-		if (pre_brace_pair == _get_auto_brace_pair_close_at_pos(caret_line, cursor_get_column() - 1)) {
-			_remove_text(caret_line, cursor_get_column() - 2, caret_line, cursor_get_column());
-			if (_get_auto_brace_pair_close_at_pos(caret_line, cursor_get_column() - 1) != pre_brace_pair) {
-				cursor_set_column(cursor_get_column() - 1);
+	if (pre_brace_pair == -1 && post_brace_pair == -1 && get_caret_column() > 0 && get_caret_column() < get_line(caret_line).length()) {
+		pre_brace_pair = _get_auto_brace_pair_open_at_pos(caret_line, get_caret_column() + 1);
+		if (pre_brace_pair == _get_auto_brace_pair_close_at_pos(caret_line, get_caret_column() - 1)) {
+			_remove_text(caret_line, get_caret_column() - 2, caret_line, get_caret_column());
+			if (_get_auto_brace_pair_close_at_pos(caret_line, get_caret_column() - 1) != pre_brace_pair) {
+				set_caret_column(get_caret_column() - 1);
 			}
 		}
 	}
@@ -2292,8 +2292,8 @@ void CodeEdit::_gutter_clicked(int p_line, int p_gutter) {
 	if (p_gutter == line_number_gutter) {
 		set_selection_mode(TextEdit::SelectionMode::SELECTION_MODE_LINE, p_line, 0);
 		select(p_line, 0, p_line + 1, 0);
-		cursor_set_line(p_line + 1);
-		cursor_set_column(0);
+		set_caret_line(p_line + 1);
+		set_caret_column(0);
 		return;
 	}
 
@@ -2688,8 +2688,8 @@ void CodeEdit::_filter_code_completion_candidates() {
 		return;
 	}
 
-	const int caret_line = cursor_get_line();
-	const int caret_column = cursor_get_column();
+	const int caret_line = get_caret_line();
+	const int caret_column = get_caret_column();
 	const String line = get_line(caret_line);
 
 	if (caret_column > 0 && line[caret_column - 1] == '(' && !code_completion_forced) {

File diff suppressed because it is too large
+ 198 - 228
scene/gui/text_edit.cpp


+ 78 - 58
scene/gui/text_edit.h

@@ -42,12 +42,19 @@ class TextEdit : public Control {
 	GDCLASS(TextEdit, Control);
 
 public:
+	/* Caret. */
+	enum CaretType {
+		CARET_TYPE_LINE,
+		CARET_TYPE_BLOCK
+	};
+
 	enum GutterType {
 		GUTTER_TYPE_STRING,
 		GUTTER_TYPE_ICON,
 		GUTTER_TYPE_CUSTOM
 	};
 
+	/* Selection */
 	enum SelectionMode {
 		SELECTION_MODE_NONE,
 		SELECTION_MODE_SHIFT,
@@ -176,16 +183,39 @@ private:
 	/* Text manipulation */
 	String cut_copy_line = "";
 
-	struct Cursor {
+	/* Caret */
+	struct Caret {
 		Point2 draw_pos;
 		bool visible = false;
 		int last_fit_x = 0;
 		int line = 0;
-		int column = 0; ///< cursor
+		int column = 0;
 		int x_ofs = 0;
 		int line_ofs = 0;
 		int wrap_ofs = 0;
-	} cursor;
+	} caret;
+
+	bool setting_caret_line = false;
+	bool caret_pos_dirty = false;
+
+	Color caret_color = Color(1, 1, 1);
+	Color caret_background_color = Color(0, 0, 0);
+
+	CaretType caret_type = CaretType::CARET_TYPE_LINE;
+
+	bool draw_caret = true;
+
+	bool caret_blink_enabled = false;
+	Timer *caret_blink_timer;
+
+	bool move_caret_on_right_click = true;
+
+	bool caret_mid_grapheme_enabled = false;
+
+	void _emit_caret_changed();
+
+	void _reset_caret_blink_timer();
+	void _toggle_draw_caret();
 
 	struct Selection {
 		SelectionMode selecting_mode = SelectionMode::SELECTION_MODE_NONE;
@@ -263,24 +293,16 @@ private:
 
 	bool readonly = true; // Initialise to opposite first, so we get past the early-out in set_readonly.
 
-	Timer *caret_blink_timer;
-	bool caret_blink_enabled = false;
-	bool draw_caret = true;
 	bool window_has_focus = true;
-	bool block_caret = false;
-	bool right_click_moves_caret = true;
-	bool mid_grapheme_caret_enabled = false;
 
 	bool wrap_enabled = false;
 	int wrap_at = 0;
 	int wrap_right_offset = 10;
 
 	bool first_draw = true;
-	bool setting_row = false;
 	bool draw_tabs = false;
 	bool draw_spaces = false;
 	bool override_selected_font_color = false;
-	bool cursor_changed_dirty = false;
 	bool text_changed_dirty = false;
 	bool undo_enabled = true;
 	bool hiding_enabled = false;
@@ -340,10 +362,9 @@ private:
 
 	int _get_minimap_visible_rows() const;
 
-	void update_cursor_wrap_offset();
+	void _update_caret_wrap_offset();
 	void _update_wrap_at(bool p_force = false);
 	Vector<String> get_wrap_rows_text(int p_line) const;
-	int get_cursor_wrap_index() const;
 
 	double get_scroll_pos_for_line(int p_line, int p_wrap_index = 0) const;
 	void set_line_as_first_visible(int p_line, int p_wrap_index = 0);
@@ -358,7 +379,6 @@ private:
 	int get_char_pos_for_line(int p_px, int p_line, int p_wrap_index = 0) const;
 	int get_column_x_offset_for_line(int p_char, int p_line) const;
 
-	void adjust_viewport_to_cursor();
 	double get_scroll_line_diff() const;
 	void _scroll_moved(double);
 	void _update_scrollbars();
@@ -385,11 +405,7 @@ private:
 
 	int _get_menu_action_accelerator(const String &p_action);
 
-	void _reset_caret_blink_timer();
-	void _toggle_draw_caret();
-
 	void _update_caches();
-	void _cursor_changed_emit();
 	void _text_changed_emit();
 
 	void _push_current_op();
@@ -415,18 +431,18 @@ private:
 	// Methods used in shortcuts
 	void _swap_current_input_direction();
 	void _new_line(bool p_split_current = true, bool p_above = false);
-	void _move_cursor_left(bool p_select, bool p_move_by_word = false);
-	void _move_cursor_right(bool p_select, bool p_move_by_word = false);
-	void _move_cursor_up(bool p_select);
-	void _move_cursor_down(bool p_select);
-	void _move_cursor_to_line_start(bool p_select);
-	void _move_cursor_to_line_end(bool p_select);
-	void _move_cursor_page_up(bool p_select);
-	void _move_cursor_page_down(bool p_select);
+	void _move_caret_left(bool p_select, bool p_move_by_word = false);
+	void _move_caret_right(bool p_select, bool p_move_by_word = false);
+	void _move_caret_up(bool p_select);
+	void _move_caret_down(bool p_select);
+	void _move_caret_to_line_start(bool p_select);
+	void _move_caret_to_line_end(bool p_select);
+	void _move_caret_page_up(bool p_select);
+	void _move_caret_page_down(bool p_select);
 	void _do_backspace(bool p_word = false, bool p_all_to_left = false);
 	void _delete(bool p_word = false, bool p_all_to_right = false);
-	void _move_cursor_document_start(bool p_select);
-	void _move_cursor_document_end(bool p_select);
+	void _move_caret_document_start(bool p_select);
+	void _move_caret_document_end(bool p_select);
 
 protected:
 	bool highlight_matching_braces_enabled = false;
@@ -442,8 +458,6 @@ protected:
 		int font_size = 16;
 		int outline_size = 0;
 		Color outline_color;
-		Color caret_color;
-		Color caret_background_color;
 		Color font_color;
 		Color font_selected_color;
 		Color font_readonly_color;
@@ -496,6 +510,33 @@ public:
 	void copy();
 	void paste();
 
+	/* Caret */
+	void set_caret_type(CaretType p_type);
+	CaretType get_caret_type() const;
+
+	void set_caret_blink_enabled(const bool p_enabled);
+	bool is_caret_blink_enabled() const;
+
+	void set_caret_blink_speed(const float p_speed);
+	float get_caret_blink_speed() const;
+
+	void set_move_caret_on_right_click_enabled(const bool p_enable);
+	bool is_move_caret_on_right_click_enabled() const;
+
+	void set_caret_mid_grapheme_enabled(const bool p_enabled);
+	bool is_caret_mid_grapheme_enabled() const;
+
+	bool is_caret_visible() const;
+	Point2 get_caret_draw_pos() const;
+
+	void set_caret_line(int p_line, bool p_adjust_viewport = true, bool p_can_be_hidden = true, int p_wrap_index = 0);
+	int get_caret_line() const;
+
+	void set_caret_column(int p_col, bool p_adjust_viewport = true);
+	int get_caret_column() const;
+
+	int get_caret_wrap_index() const;
+
 	/* Syntax Highlighting. */
 	Ref<SyntaxHighlighter> get_syntax_highlighter();
 	void set_syntax_highlighter(Ref<SyntaxHighlighter> p_syntax_highlighter);
@@ -619,7 +660,7 @@ public:
 	Array get_structured_text_bidi_override_options() const;
 
 	void set_text(String p_text);
-	void insert_text_at_cursor(const String &p_text);
+	void insert_text_at_caret(const String &p_text);
 	void insert_at(const String &p_text, int at);
 	int get_line_count() const;
 	int get_line_width(int p_line, int p_wrap_offset = -1) const;
@@ -646,31 +687,8 @@ public:
 		update();
 	}
 
-	void center_viewport_to_cursor();
-
-	void set_mid_grapheme_caret_enabled(const bool p_enabled);
-	bool get_mid_grapheme_caret_enabled() const;
-
-	void cursor_set_column(int p_col, bool p_adjust_viewport = true);
-	void cursor_set_line(int p_row, bool p_adjust_viewport = true, bool p_can_be_hidden = true, int p_wrap_index = 0);
-
-	Point2 get_caret_draw_pos() const;
-	bool is_caret_visible() const;
-	int cursor_get_column() const;
-	int cursor_get_line() const;
-	Vector2i _get_cursor_pixel_pos(bool p_adjust_viewport = true);
-
-	bool cursor_get_blink_enabled() const;
-	void cursor_set_blink_enabled(const bool p_enabled);
-
-	float cursor_get_blink_speed() const;
-	void cursor_set_blink_speed(const float p_speed);
-
-	void cursor_set_block_mode(const bool p_enable);
-	bool cursor_is_block_mode() const;
-
-	void set_right_click_moves_caret(bool p_enable);
-	bool is_right_click_moving_caret() const;
+	void adjust_viewport_to_caret();
+	void center_viewport_to_caret();
 
 	SelectionMode get_selection_mode() const;
 	void set_selection_mode(SelectionMode p_mode, int p_line = -1, int p_column = -1);
@@ -708,7 +726,7 @@ public:
 	int get_selection_to_column() const;
 	String get_selection_text() const;
 
-	String get_word_under_cursor() const;
+	String get_word_under_caret() const;
 	String get_word_at_pos(const Vector2 &p_pos) const;
 
 	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;
@@ -781,8 +799,10 @@ public:
 	~TextEdit();
 };
 
-VARIANT_ENUM_CAST(TextEdit::GutterType);
+
+VARIANT_ENUM_CAST(TextEdit::CaretType);
 VARIANT_ENUM_CAST(TextEdit::SelectionMode);
+VARIANT_ENUM_CAST(TextEdit::GutterType);
 VARIANT_ENUM_CAST(TextEdit::MenuItems);
 VARIANT_ENUM_CAST(TextEdit::SearchFlags);
 

Some files were not shown because too many files changed in this diff