summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulb23 <p_batty@hotmail.co.uk>2021-07-08 18:35:56 +0100
committerPaulb23 <p_batty@hotmail.co.uk>2021-08-12 09:29:13 +0100
commitd5dcaee4c5b41faca64f02888b152f7f05c4a20b (patch)
tree9357d0d289d3cd1089fa298accc7933b97979e5d
parente60900a35395f0aa97d01383e2095c4e50faa500 (diff)
downloadredot-engine-d5dcaee4c5b41faca64f02888b152f7f05c4a20b.tar.gz
Cleanup and rename caret operations
-rw-r--r--doc/classes/TextEdit.xml142
-rw-r--r--editor/code_editor.cpp170
-rw-r--r--editor/editor_settings.cpp3
-rw-r--r--editor/plugins/script_text_editor.cpp87
-rw-r--r--editor/plugins/shader_editor_plugin.cpp23
-rw-r--r--editor/plugins/text_editor.cpp25
-rw-r--r--scene/gui/code_edit.cpp154
-rw-r--r--scene/gui/text_edit.cpp1176
-rw-r--r--scene/gui/text_edit.h136
9 files changed, 981 insertions, 935 deletions
diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml
index 855f19852f..00e15f9f2a 100644
--- a/doc/classes/TextEdit.xml
+++ b/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">
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index eeb99b3677..0aab0463c4 100644
--- a/editor/code_editor.cpp
+++ b/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;
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 16c2a0f028..65d75968f6 100644
--- a/editor/editor_settings.cpp
+++ b/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");
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 64381c0d9e..2faa56e661 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/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();
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index 95973f9dfd..3190a0d8ef 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/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();
}
}
diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp
index faf287b9bd..6eea8ae227 100644
--- a/editor/plugins/text_editor.cpp
+++ b/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();
}
}
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index 0790317380..1e2d601bde 100644
--- a/scene/gui/code_edit.cpp
+++ b/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) {
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 27046570bb..8e624140f2 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -289,8 +289,8 @@ void TextEdit::_update_scrollbars() {
set_v_scroll(get_v_scroll());
} else {
- cursor.line_ofs = 0;
- cursor.wrap_ofs = 0;
+ caret.line_ofs = 0;
+ caret.wrap_ofs = 0;
v_scroll->set_value(0);
v_scroll->hide();
}
@@ -299,15 +299,15 @@ void TextEdit::_update_scrollbars() {
h_scroll->show();
h_scroll->set_max(total_width);
h_scroll->set_page(visible_width);
- if (cursor.x_ofs > (total_width - visible_width)) {
- cursor.x_ofs = (total_width - visible_width);
+ if (caret.x_ofs > (total_width - visible_width)) {
+ caret.x_ofs = (total_width - visible_width);
}
- if (fabs(h_scroll->get_value() - (double)cursor.x_ofs) >= 1) {
- h_scroll->set_value(cursor.x_ofs);
+ if (fabs(h_scroll->get_value() - (double)caret.x_ofs) >= 1) {
+ h_scroll->set_value(caret.x_ofs);
}
} else {
- cursor.x_ofs = 0;
+ caret.x_ofs = 0;
h_scroll->set_value(0);
h_scroll->hide();
}
@@ -356,8 +356,8 @@ void TextEdit::_update_selection_mode_pointer() {
select(selection.selecting_line, selection.selecting_column, row, col);
- cursor_set_line(row, false);
- cursor_set_column(col);
+ set_caret_line(row, false);
+ set_caret_column(col);
update();
click_select_held->start();
@@ -371,12 +371,12 @@ void TextEdit::_update_selection_mode_word() {
_get_mouse_pos(Point2i(mp.x, mp.y), row, col);
String line = text[row];
- int cursor_pos = CLAMP(col, 0, line.length());
- int beg = cursor_pos;
+ int caret_pos = CLAMP(col, 0, line.length());
+ int beg = caret_pos;
int end = beg;
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(row)->get_rid());
for (int i = 0; i < words.size(); i++) {
- if (words[i].x < cursor_pos && words[i].y > cursor_pos) {
+ if (words[i].x < caret_pos && words[i].y > caret_pos) {
beg = words[i].x;
end = words[i].y;
break;
@@ -390,19 +390,19 @@ void TextEdit::_update_selection_mode_word() {
selection.selected_word_beg = beg;
selection.selected_word_end = end;
selection.selected_word_origin = beg;
- cursor_set_line(selection.to_line, false);
- cursor_set_column(selection.to_column);
+ set_caret_line(selection.to_line, false);
+ set_caret_column(selection.to_column);
} else {
if ((col <= selection.selected_word_origin && row == selection.selecting_line) || row < selection.selecting_line) {
selection.selecting_column = selection.selected_word_end;
select(row, beg, selection.selecting_line, selection.selected_word_end);
- cursor_set_line(selection.from_line, false);
- cursor_set_column(selection.from_column);
+ set_caret_line(selection.from_line, false);
+ set_caret_column(selection.from_column);
} else {
selection.selecting_column = selection.selected_word_beg;
select(selection.selecting_line, selection.selected_word_beg, row, end);
- cursor_set_line(selection.to_line, false);
- cursor_set_column(selection.to_column);
+ set_caret_line(selection.to_line, false);
+ set_caret_column(selection.to_column);
}
}
@@ -420,16 +420,16 @@ void TextEdit::_update_selection_mode_line() {
col = 0;
if (row < selection.selecting_line) {
- // Cursor is above us.
- cursor_set_line(row - 1, false);
+ // Caret is above us.
+ set_caret_line(row - 1, false);
selection.selecting_column = text[selection.selecting_line].length();
} else {
- // Cursor is below us.
- cursor_set_line(row + 1, false);
+ // Caret is below us.
+ set_caret_line(row + 1, false);
selection.selecting_column = 0;
col = text[row].length();
}
- cursor_set_column(0);
+ set_caret_column(0);
select(selection.selecting_line, selection.selecting_column, row, col);
update();
@@ -489,8 +489,8 @@ void TextEdit::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_caches();
- if (cursor_changed_dirty) {
- MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
+ if (caret_pos_dirty) {
+ MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed");
}
if (text_changed_dirty) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
@@ -546,8 +546,8 @@ void TextEdit::_notification(int p_what) {
} break;
case NOTIFICATION_DRAW: {
if (first_draw) {
- // Size may not be the final one, so attempts to ensure cursor was visible may have failed.
- adjust_viewport_to_cursor();
+ // Size may not be the final one, so attempts to ensure caret was visible may have failed.
+ adjust_viewport_to_caret();
first_draw = false;
}
@@ -603,10 +603,10 @@ void TextEdit::_notification(int p_what) {
bool brace_close_matching = false;
bool brace_close_mismatch = false;
- if (highlight_matching_braces_enabled && cursor.line >= 0 && cursor.line < text.size() && cursor.column >= 0) {
- if (cursor.column < text[cursor.line].length()) {
+ if (highlight_matching_braces_enabled && caret.line >= 0 && caret.line < text.size() && caret.column >= 0) {
+ if (caret.column < text[caret.line].length()) {
// Check for open.
- char32_t c = text[cursor.line][cursor.column];
+ char32_t c = text[caret.line][caret.column];
char32_t closec = 0;
if (c == '[') {
@@ -620,8 +620,8 @@ void TextEdit::_notification(int p_what) {
if (closec != 0) {
int stack = 1;
- for (int i = cursor.line; i < text.size(); i++) {
- int from = i == cursor.line ? cursor.column + 1 : 0;
+ for (int i = caret.line; i < text.size(); i++) {
+ int from = i == caret.line ? caret.column + 1 : 0;
for (int j = from; j < text[i].length(); j++) {
char32_t cc = text[i][j];
// Ignore any brackets inside a string.
@@ -671,8 +671,8 @@ void TextEdit::_notification(int p_what) {
}
}
- if (cursor.column > 0) {
- char32_t c = text[cursor.line][cursor.column - 1];
+ if (caret.column > 0) {
+ char32_t c = text[caret.line][caret.column - 1];
char32_t closec = 0;
if (c == ']') {
@@ -686,8 +686,8 @@ void TextEdit::_notification(int p_what) {
if (closec != 0) {
int stack = 1;
- for (int i = cursor.line; i >= 0; i--) {
- int from = i == cursor.line ? cursor.column - 2 : text[i].length() - 1;
+ for (int i = caret.line; i >= 0; i--) {
+ int from = i == caret.line ? caret.column - 2 : text[i].length() - 1;
for (int j = from; j >= 0; j--) {
char32_t cc = text[i][j];
// Ignore any brackets inside a string.
@@ -744,7 +744,7 @@ void TextEdit::_notification(int p_what) {
// Check if highlighted words contain only whitespaces (tabs or spaces).
bool only_whitespaces_highlighted = highlighted_text.strip_edges() == String();
- int cursor_wrap_index = get_cursor_wrap_index();
+ const int caret_wrap_index = get_caret_wrap_index();
int first_visible_line = get_first_visible_line() - 1;
int draw_amount = visible_rows + (smooth_scroll_enabled ? 1 : 0);
@@ -828,7 +828,7 @@ void TextEdit::_notification(int p_what) {
last_wrap_column += wrap_rows[line_wrap_index - 1].length();
}
- if (minimap_line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) {
+ if (minimap_line == caret.line && caret_wrap_index == line_wrap_index && highlight_current_line) {
if (rtl) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - cache.minimap_width, i * 3, cache.minimap_width, 2), cache.current_line_color);
} else {
@@ -919,8 +919,7 @@ void TextEdit::_notification(int p_what) {
}
// draw main text
- cursor.visible = false;
- const int caret_wrap_index = get_cursor_wrap_index();
+ caret.visible = false;
int row_height = get_row_height();
int line = first_visible_line;
for (int i = 0; i < draw_amount; i++) {
@@ -960,7 +959,7 @@ void TextEdit::_notification(int p_what) {
}
const String &str = wrap_rows[line_wrap_index];
- int char_margin = xmargin_beg - cursor.x_ofs;
+ int char_margin = xmargin_beg - caret.x_ofs;
int ofs_x = 0;
int ofs_y = 0;
@@ -973,7 +972,7 @@ void TextEdit::_notification(int p_what) {
}
ofs_y += i * row_height + cache.line_spacing / 2;
- ofs_y -= cursor.wrap_ofs * row_height;
+ ofs_y -= caret.wrap_ofs * row_height;
ofs_y -= get_v_scroll_offset() * row_height;
bool clipped = false;
@@ -999,7 +998,7 @@ void TextEdit::_notification(int p_what) {
if (str.length() == 0) {
// Draw line background if empty as we won't loop at all.
- if (line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) {
+ if (line == caret.line && caret_wrap_index == line_wrap_index && highlight_current_line) {
if (rtl) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end, row_height), cache.current_line_color);
} else {
@@ -1018,7 +1017,7 @@ void TextEdit::_notification(int p_what) {
}
} else {
// If it has text, then draw current line marker in the margin, as line number etc will draw over it, draw the rest of line marker later.
- if (line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) {
+ if (line == caret.line && caret_wrap_index == line_wrap_index && highlight_current_line) {
if (rtl) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end, row_height), cache.current_line_color);
} else {
@@ -1246,7 +1245,7 @@ void TextEdit::_notification(int p_what) {
if (char_pos >= xmargin_beg) {
if (highlight_matching_braces_enabled) {
if ((brace_open_match_line == line && brace_open_match_column == glyphs[j].start) ||
- (cursor.column == glyphs[j].start && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) {
+ (caret.column == glyphs[j].start && caret.line == line && caret_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) {
if (brace_open_mismatch) {
current_color = cache.brace_mismatch_color;
}
@@ -1255,7 +1254,7 @@ void TextEdit::_notification(int p_what) {
}
if ((brace_close_match_line == line && brace_close_match_column == glyphs[j].start) ||
- (cursor.column == glyphs[j].start + 1 && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_close_matching || brace_close_mismatch))) {
+ (caret.column == glyphs[j].start + 1 && caret.line == line && caret_wrap_index == line_wrap_index && (brace_close_matching || brace_close_mismatch))) {
if (brace_close_mismatch) {
current_color = cache.brace_mismatch_color;
}
@@ -1307,15 +1306,15 @@ void TextEdit::_notification(int p_what) {
int caret_width = 1;
#endif
- if (!clipped && cursor.line == line && line_wrap_index == caret_wrap_index) {
- cursor.draw_pos.y = ofs_y + ldata->get_line_descent(line_wrap_index);
+ if (!clipped && caret.line == line && line_wrap_index == caret_wrap_index) {
+ caret.draw_pos.y = ofs_y + ldata->get_line_descent(line_wrap_index);
if (ime_text.length() == 0) {
Rect2 l_caret, t_caret;
TextServer::Direction l_dir, t_dir;
if (str.length() != 0) {
// Get carets.
- TS->shaped_text_get_carets(rid, cursor.column, l_caret, l_dir, t_caret, t_dir);
+ TS->shaped_text_get_carets(rid, caret.column, l_caret, l_dir, t_caret, t_dir);
} else {
// No carets, add one at the start.
int h = cache.font->get_height(cache.font_size);
@@ -1329,15 +1328,15 @@ void TextEdit::_notification(int p_what) {
}
if ((l_caret != Rect2() && (l_dir == TextServer::DIRECTION_AUTO || l_dir == (TextServer::Direction)input_direction)) || (t_caret == Rect2())) {
- cursor.draw_pos.x = char_margin + ofs_x + l_caret.position.x;
+ caret.draw_pos.x = char_margin + ofs_x + l_caret.position.x;
} else {
- cursor.draw_pos.x = char_margin + ofs_x + t_caret.position.x;
+ caret.draw_pos.x = char_margin + ofs_x + t_caret.position.x;
}
- if (cursor.draw_pos.x >= xmargin_beg && cursor.draw_pos.x < xmargin_end) {
- cursor.visible = true;
+ if (caret.draw_pos.x >= xmargin_beg && caret.draw_pos.x < xmargin_end) {
+ caret.visible = true;
if (draw_caret) {
- if (block_caret || insert_mode) {
+ if (caret_type == CaretType::CARET_TYPE_BLOCK || insert_mode) {
//Block or underline caret, draw trailing carets at full height.
int h = cache.font->get_height(cache.font_size);
@@ -1351,7 +1350,7 @@ void TextEdit::_notification(int p_what) {
}
t_caret.position += Vector2(char_margin + ofs_x, ofs_y);
- draw_rect(t_caret, cache.caret_color, false);
+ draw_rect(t_caret, caret_color, false);
} else { // End of the line.
if (insert_mode) {
l_caret.position.y = TS->shaped_text_get_descent(rid);
@@ -1363,7 +1362,7 @@ void TextEdit::_notification(int p_what) {
l_caret.position += Vector2(char_margin + ofs_x, ofs_y);
l_caret.size.x = cache.font->get_char_size('M', 0, cache.font_size).x;
- draw_rect(l_caret, cache.caret_color, false);
+ draw_rect(l_caret, caret_color, false);
}
} else {
// Normal caret.
@@ -1371,24 +1370,24 @@ void TextEdit::_notification(int p_what) {
// Draw extra marker on top of mid caret.
Rect2 trect = Rect2(l_caret.position.x - 3 * caret_width, l_caret.position.y, 6 * caret_width, caret_width);
trect.position += Vector2(char_margin + ofs_x, ofs_y);
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, trect, cache.caret_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, trect, caret_color);
}
l_caret.position += Vector2(char_margin + ofs_x, ofs_y);
l_caret.size.x = caret_width;
- draw_rect(l_caret, cache.caret_color);
+ draw_rect(l_caret, caret_color);
t_caret.position += Vector2(char_margin + ofs_x, ofs_y);
t_caret.size.x = caret_width;
- draw_rect(t_caret, cache.caret_color);
+ draw_rect(t_caret, caret_color);
}
}
}
} else {
{
// IME Intermediate text range.
- Vector<Vector2> sel = TS->shaped_text_get_selection(rid, cursor.column, cursor.column + ime_text.length());
+ Vector<Vector2> sel = TS->shaped_text_get_selection(rid, caret.column, caret.column + ime_text.length());
for (int j = 0; j < sel.size(); j++) {
Rect2 rect = Rect2(sel[j].x + char_margin + ofs_x, ofs_y, sel[j].y - sel[j].x, text_height);
if (rect.position.x + rect.size.x <= xmargin_beg || rect.position.x > xmargin_end) {
@@ -1401,13 +1400,13 @@ void TextEdit::_notification(int p_what) {
rect.size.x = xmargin_end - rect.position.x;
}
rect.size.y = caret_width;
- draw_rect(rect, cache.caret_color);
- cursor.draw_pos.x = rect.position.x;
+ draw_rect(rect, caret_color);
+ caret.draw_pos.x = rect.position.x;
}
}
{
// IME caret.
- Vector<Vector2> sel = TS->shaped_text_get_selection(rid, cursor.column + ime_selection.x, cursor.column + ime_selection.x + ime_selection.y);
+ Vector<Vector2> sel = TS->shaped_text_get_selection(rid, caret.column + ime_selection.x, caret.column + ime_selection.x + ime_selection.y);
for (int j = 0; j < sel.size(); j++) {
Rect2 rect = Rect2(sel[j].x + char_margin + ofs_x, ofs_y, sel[j].y - sel[j].x, text_height);
if (rect.position.x + rect.size.x <= xmargin_beg || rect.position.x > xmargin_end) {
@@ -1420,8 +1419,8 @@ void TextEdit::_notification(int p_what) {
rect.size.x = xmargin_end - rect.position.x;
}
rect.size.y = caret_width * 3;
- draw_rect(rect, cache.caret_color);
- cursor.draw_pos.x = rect.position.x;
+ draw_rect(rect, caret_color);
+ caret.draw_pos.x = rect.position.x;
}
}
}
@@ -1432,7 +1431,7 @@ void TextEdit::_notification(int p_what) {
if (has_focus()) {
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id());
- DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor.draw_pos, get_viewport()->get_window_id());
+ DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + caret.draw_pos, get_viewport()->get_window_id());
}
}
} break;
@@ -1445,26 +1444,26 @@ void TextEdit::_notification(int p_what) {
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id());
- DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + _get_cursor_pixel_pos(false), get_viewport()->get_window_id());
+ DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + get_caret_draw_pos(), get_viewport()->get_window_id());
}
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
- int cursor_start = -1;
- int cursor_end = -1;
+ int caret_start = -1;
+ int caret_end = -1;
if (!selection.active) {
- String full_text = _base_get_text(0, 0, cursor.line, cursor.column);
+ String full_text = _base_get_text(0, 0, caret.line, caret.column);
- cursor_start = full_text.length();
+ caret_start = full_text.length();
} else {
String pre_text = _base_get_text(0, 0, selection.from_line, selection.from_column);
String post_text = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
- cursor_start = pre_text.length();
- cursor_end = cursor_start + post_text.length();
+ caret_start = pre_text.length();
+ caret_end = caret_start + post_text.length();
}
- DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect(), true, -1, cursor_start, cursor_end);
+ DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect(), true, -1, caret_start, caret_end);
}
} break;
case NOTIFICATION_FOCUS_EXIT: {
@@ -1478,7 +1477,7 @@ void TextEdit::_notification(int p_what) {
}
ime_text = "";
ime_selection = Point2();
- text.invalidate_cache(cursor.line, cursor.column, ime_text);
+ text.invalidate_cache(caret.line, caret.column, ime_text);
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
@@ -1490,13 +1489,13 @@ void TextEdit::_notification(int p_what) {
ime_selection = DisplayServer::get_singleton()->ime_get_selection();
String t;
- if (cursor.column >= 0) {
- t = text[cursor.line].substr(0, cursor.column) + ime_text + text[cursor.line].substr(cursor.column, text[cursor.line].length());
+ if (caret.column >= 0) {
+ t = text[caret.line].substr(0, caret.column) + ime_text + text[caret.line].substr(caret.column, text[caret.line].length());
} else {
t = ime_text;
}
- text.invalidate_cache(cursor.line, cursor.column, t, structured_text_parser(st_parser, st_args, t));
+ text.invalidate_cache(caret.line, caret.column, t, structured_text_parser(st_parser, st_args, t));
update();
}
} break;
@@ -1509,7 +1508,7 @@ void TextEdit::_swap_current_input_direction() {
} else {
input_direction = TEXT_DIRECTION_LTR;
}
- cursor_set_column(cursor.column);
+ set_caret_column(caret.column);
update();
}
@@ -1523,35 +1522,35 @@ void TextEdit::_new_line(bool p_split_current_line, bool p_above) {
bool first_line = false;
if (!p_split_current_line) {
if (p_above) {
- if (cursor.line > 0) {
- cursor_set_line(cursor.line - 1, false);
- cursor_set_column(text[cursor.line].length());
+ if (caret.line > 0) {
+ set_caret_line(caret.line - 1, false);
+ set_caret_column(text[caret.line].length());
} else {
- cursor_set_column(0);
+ set_caret_column(0);
first_line = true;
}
} else {
- cursor_set_column(text[cursor.line].length());
+ set_caret_column(text[caret.line].length());
}
}
- insert_text_at_cursor("\n");
+ insert_text_at_caret("\n");
if (first_line) {
- cursor_set_line(0);
+ set_caret_line(0);
}
end_complex_operation();
}
-void TextEdit::_move_cursor_left(bool p_select, bool p_move_by_word) {
+void TextEdit::_move_caret_left(bool p_select, bool p_move_by_word) {
// Handle selection
if (p_select) {
_pre_shift_selection();
} else if (selection.active && !p_move_by_word) {
// If a selection is active, move cursor to start of selection
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
+ set_caret_line(selection.from_line);
+ set_caret_column(selection.from_column);
deselect();
return;
} else {
@@ -1559,33 +1558,33 @@ void TextEdit::_move_cursor_left(bool p_select, bool p_move_by_word) {
}
if (p_move_by_word) {
- int cc = cursor.column;
+ int cc = caret.column;
- if (cc == 0 && cursor.line > 0) {
- cursor_set_line(cursor.line - 1);
- cursor_set_column(text[cursor.line].length());
+ if (cc == 0 && caret.line > 0) {
+ set_caret_line(caret.line - 1);
+ set_caret_column(text[caret.line].length());
} else {
- Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(cursor.line)->get_rid());
+ Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid());
for (int i = words.size() - 1; i >= 0; i--) {
if (words[i].x < cc) {
cc = words[i].x;
break;
}
}
- cursor_set_column(cc);
+ set_caret_column(cc);
}
} else {
- // If the cursor is at the start of the line, and not on the first line, move it up to the end of the previous line.
- if (cursor.column == 0) {
- if (cursor.line > 0) {
- cursor_set_line(cursor.line - num_lines_from(CLAMP(cursor.line - 1, 0, text.size() - 1), -1));
- cursor_set_column(text[cursor.line].length());
+ // If the caret is at the start of the line, and not on the first line, move it up to the end of the previous line.
+ if (caret.column == 0) {
+ if (caret.line > 0) {
+ set_caret_line(caret.line - num_lines_from(CLAMP(caret.line - 1, 0, text.size() - 1), -1));
+ set_caret_column(text[caret.line].length());
}
} else {
- if (mid_grapheme_caret_enabled) {
- cursor_set_column(cursor_get_column() - 1);
+ if (caret_mid_grapheme_enabled) {
+ set_caret_column(get_caret_column() - 1);
} else {
- cursor_set_column(TS->shaped_text_prev_grapheme_pos(text.get_line_data(cursor.line)->get_rid(), cursor_get_column()));
+ set_caret_column(TS->shaped_text_prev_grapheme_pos(text.get_line_data(caret.line)->get_rid(), get_caret_column()));
}
}
}
@@ -1595,14 +1594,14 @@ void TextEdit::_move_cursor_left(bool p_select, bool p_move_by_word) {
}
}
-void TextEdit::_move_cursor_right(bool p_select, bool p_move_by_word) {
+void TextEdit::_move_caret_right(bool p_select, bool p_move_by_word) {
// Handle selection
if (p_select) {
_pre_shift_selection();
} else if (selection.active && !p_move_by_word) {
// If a selection is active, move cursor to end of selection
- cursor_set_line(selection.to_line);
- cursor_set_column(selection.to_column);
+ set_caret_line(selection.to_line);
+ set_caret_column(selection.to_column);
deselect();
return;
} else {
@@ -1610,33 +1609,33 @@ void TextEdit::_move_cursor_right(bool p_select, bool p_move_by_word) {
}
if (p_move_by_word) {
- int cc = cursor.column;
+ int cc = caret.column;
- if (cc == text[cursor.line].length() && cursor.line < text.size() - 1) {
- cursor_set_line(cursor.line + 1);
- cursor_set_column(0);
+ if (cc == text[caret.line].length() && caret.line < text.size() - 1) {
+ set_caret_line(caret.line + 1);
+ set_caret_column(0);
} else {
- Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(cursor.line)->get_rid());
+ Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid());
for (int i = 0; i < words.size(); i++) {
if (words[i].y > cc) {
cc = words[i].y;
break;
}
}
- cursor_set_column(cc);
+ set_caret_column(cc);
}
} else {
// If we are at the end of the line, move the caret to the next line down.
- if (cursor.column == text[cursor.line].length()) {
- if (cursor.line < text.size() - 1) {
- cursor_set_line(cursor_get_line() + num_lines_from(CLAMP(cursor.line + 1, 0, text.size() - 1), 1), true, false);
- cursor_set_column(0);
+ if (caret.column == text[caret.line].length()) {
+ if (caret.line < text.size() - 1) {
+ set_caret_line(get_caret_line() + num_lines_from(CLAMP(caret.line + 1, 0, text.size() - 1), 1), true, false);
+ set_caret_column(0);
}
} else {
- if (mid_grapheme_caret_enabled) {
- cursor_set_column(cursor_get_column() + 1);
+ if (caret_mid_grapheme_enabled) {
+ set_caret_column(get_caret_column() + 1);
} else {
- cursor_set_column(TS->shaped_text_next_grapheme_pos(text.get_line_data(cursor.line)->get_rid(), cursor_get_column()));
+ set_caret_column(TS->shaped_text_next_grapheme_pos(text.get_line_data(caret.line)->get_rid(), get_caret_column()));
}
}
}
@@ -1646,24 +1645,24 @@ void TextEdit::_move_cursor_right(bool p_select, bool p_move_by_word) {
}
}
-void TextEdit::_move_cursor_up(bool p_select) {
+void TextEdit::_move_caret_up(bool p_select) {
if (p_select) {
_pre_shift_selection();
} else {
deselect();
}
- int cur_wrap_index = get_cursor_wrap_index();
+ int cur_wrap_index = get_caret_wrap_index();
if (cur_wrap_index > 0) {
- cursor_set_line(cursor.line, true, false, cur_wrap_index - 1);
- } else if (cursor.line == 0) {
- cursor_set_column(0);
+ set_caret_line(caret.line, true, false, cur_wrap_index - 1);
+ } else if (caret.line == 0) {
+ set_caret_column(0);
} else {
- int new_line = cursor.line - num_lines_from(cursor.line - 1, -1);
+ int new_line = caret.line - num_lines_from(caret.line - 1, -1);
if (line_wraps(new_line)) {
- cursor_set_line(new_line, true, false, times_line_wraps(new_line));
+ set_caret_line(new_line, true, false, times_line_wraps(new_line));
} else {
- cursor_set_line(new_line, true, false);
+ set_caret_line(new_line, true, false);
}
}
@@ -1672,21 +1671,21 @@ void TextEdit::_move_cursor_up(bool p_select) {
}
}
-void TextEdit::_move_cursor_down(bool p_select) {
+void TextEdit::_move_caret_down(bool p_select) {
if (p_select) {
_pre_shift_selection();
} else {
deselect();
}
- int cur_wrap_index = get_cursor_wrap_index();
- if (cur_wrap_index < times_line_wraps(cursor.line)) {
- cursor_set_line(cursor.line, true, false, cur_wrap_index + 1);
- } else if (cursor.line == get_last_unhidden_line()) {
- cursor_set_column(text[cursor.line].length());
+ int cur_wrap_index = get_caret_wrap_index();
+ if (cur_wrap_index < times_line_wraps(caret.line)) {
+ set_caret_line(caret.line, true, false, cur_wrap_index + 1);
+ } else if (caret.line == get_last_unhidden_line()) {
+ set_caret_column(text[caret.line].length());
} else {
- int new_line = cursor.line + num_lines_from(CLAMP(cursor.line + 1, 0, text.size() - 1), 1);
- cursor_set_line(new_line, true, false, 0);
+ int new_line = caret.line + num_lines_from(CLAMP(caret.line + 1, 0, text.size() - 1), 1);
+ set_caret_line(new_line, true, false, 0);
}
if (p_select) {
@@ -1694,38 +1693,38 @@ void TextEdit::_move_cursor_down(bool p_select) {
}
}
-void TextEdit::_move_cursor_to_line_start(bool p_select) {
+void TextEdit::_move_caret_to_line_start(bool p_select) {
if (p_select) {
_pre_shift_selection();
} else {
deselect();
}
- // Move cursor column to start of wrapped row and then to start of text.
- Vector<String> rows = get_wrap_rows_text(cursor.line);
- int wi = get_cursor_wrap_index();
+ // Move caret column to start of wrapped row and then to start of text.
+ Vector<String> rows = get_wrap_rows_text(caret.line);
+ int wi = get_caret_wrap_index();
int row_start_col = 0;
for (int i = 0; i < wi; i++) {
row_start_col += rows[i].length();
}
- if (cursor.column == row_start_col || wi == 0) {
+ if (caret.column == row_start_col || wi == 0) {
// Compute whitespace symbols sequence length.
int current_line_whitespace_len = 0;
- while (current_line_whitespace_len < text[cursor.line].length()) {
- char32_t c = text[cursor.line][current_line_whitespace_len];
+ while (current_line_whitespace_len < text[caret.line].length()) {
+ char32_t c = text[caret.line][current_line_whitespace_len];
if (c != '\t' && c != ' ') {
break;
}
current_line_whitespace_len++;
}
- if (cursor_get_column() == current_line_whitespace_len) {
- cursor_set_column(0);
+ if (get_caret_column() == current_line_whitespace_len) {
+ set_caret_column(0);
} else {
- cursor_set_column(current_line_whitespace_len);
+ set_caret_column(current_line_whitespace_len);
}
} else {
- cursor_set_column(row_start_col);
+ set_caret_column(row_start_col);
}
if (p_select) {
@@ -1733,24 +1732,24 @@ void TextEdit::_move_cursor_to_line_start(bool p_select) {
}
}
-void TextEdit::_move_cursor_to_line_end(bool p_select) {
+void TextEdit::_move_caret_to_line_end(bool p_select) {
if (p_select) {
_pre_shift_selection();
} else {
deselect();
}
- // Move cursor column to end of wrapped row and then to end of text.
- Vector<String> rows = get_wrap_rows_text(cursor.line);
- int wi = get_cursor_wrap_index();
+ // Move caret column to end of wrapped row and then to end of text.
+ Vector<String> rows = get_wrap_rows_text(caret.line);
+ int wi = get_caret_wrap_index();
int row_end_col = -1;
for (int i = 0; i < wi + 1; i++) {
row_end_col += rows[i].length();
}
- if (wi == rows.size() - 1 || cursor.column == row_end_col) {
- cursor_set_column(text[cursor.line].length());
+ if (wi == rows.size() - 1 || caret.column == row_end_col) {
+ set_caret_column(text[caret.line].length());
} else {
- cursor_set_column(row_end_col);
+ set_caret_column(row_end_col);
}
if (p_select) {
@@ -1758,7 +1757,7 @@ void TextEdit::_move_cursor_to_line_end(bool p_select) {
}
}
-void TextEdit::_move_cursor_page_up(bool p_select) {
+void TextEdit::_move_caret_page_up(bool p_select) {
if (p_select) {
_pre_shift_selection();
} else {
@@ -1766,15 +1765,15 @@ void TextEdit::_move_cursor_page_up(bool p_select) {
}
int wi;
- int n_line = cursor.line - num_lines_from_rows(cursor.line, get_cursor_wrap_index(), -get_visible_rows(), wi) + 1;
- cursor_set_line(n_line, true, false, wi);
+ int n_line = caret.line - num_lines_from_rows(caret.line, get_caret_wrap_index(), -get_visible_rows(), wi) + 1;
+ set_caret_line(n_line, true, false, wi);
if (p_select) {
_post_shift_selection();
}
}
-void TextEdit::_move_cursor_page_down(bool p_select) {
+void TextEdit::_move_caret_page_down(bool p_select) {
if (p_select) {
_pre_shift_selection();
} else {
@@ -1782,8 +1781,8 @@ void TextEdit::_move_cursor_page_down(bool p_select) {
}
int wi;
- int n_line = cursor.line + num_lines_from_rows(cursor.line, get_cursor_wrap_index(), get_visible_rows(), wi) - 1;
- cursor_set_line(n_line, true, false, wi);
+ int n_line = caret.line + num_lines_from_rows(caret.line, get_caret_wrap_index(), get_visible_rows(), wi) - 1;
+ set_caret_line(n_line, true, false, wi);
if (p_select) {
_post_shift_selection();
@@ -1801,15 +1800,15 @@ void TextEdit::_do_backspace(bool p_word, bool p_all_to_left) {
}
if (p_all_to_left) {
- int cursor_current_column = cursor.column;
- cursor.column = 0;
- _remove_text(cursor.line, 0, cursor.line, cursor_current_column);
+ int caret_current_column = caret.column;
+ caret.column = 0;
+ _remove_text(caret.line, 0, caret.line, caret_current_column);
return;
}
if (p_word) {
- int line = cursor.line;
- int column = cursor.column;
+ int line = caret.line;
+ int column = caret.column;
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(line)->get_rid());
for (int i = words.size() - 1; i >= 0; i--) {
@@ -1819,10 +1818,10 @@ void TextEdit::_do_backspace(bool p_word, bool p_all_to_left) {
}
}
- _remove_text(line, column, cursor.line, cursor.column);
+ _remove_text(line, column, caret.line, caret.column);
- cursor_set_line(line, false);
- cursor_set_column(column);
+ set_caret_line(line, false);
+ set_caret_column(column);
return;
}
}
@@ -1836,23 +1835,23 @@ void TextEdit::_delete(bool p_word, bool p_all_to_right) {
delete_selection();
return;
}
- int curline_len = text[cursor.line].length();
+ int curline_len = text[caret.line].length();
- if (cursor.line == text.size() - 1 && cursor.column == curline_len) {
+ if (caret.line == text.size() - 1 && caret.column == curline_len) {
return; // Last line, last column: Nothing to do.
}
- int next_line = cursor.column < curline_len ? cursor.line : cursor.line + 1;
+ int next_line = caret.column < curline_len ? caret.line : caret.line + 1;
int next_column;
if (p_all_to_right) {
- // Delete everything to right of cursor
+ // Delete everything to right of caret
next_column = curline_len;
- next_line = cursor.line;
- } else if (p_word && cursor.column < curline_len - 1) {
- // Delete next word to right of cursor
- int line = cursor.line;
- int column = cursor.column;
+ next_line = caret.line;
+ } else if (p_word && caret.column < curline_len - 1) {
+ // Delete next word to right of caret
+ int line = caret.line;
+ int column = caret.column;
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(line)->get_rid());
for (int i = 0; i < words.size(); i++) {
@@ -1866,15 +1865,15 @@ void TextEdit::_delete(bool p_word, bool p_all_to_right) {
next_column = column;
} else {
// Delete one character
- next_column = cursor.column < curline_len ? (cursor.column + 1) : 0;
- if (mid_grapheme_caret_enabled) {
- next_column = cursor.column < curline_len ? (cursor.column + 1) : 0;
+ next_column = caret.column < curline_len ? (caret.column + 1) : 0;
+ if (caret_mid_grapheme_enabled) {
+ next_column = caret.column < curline_len ? (caret.column + 1) : 0;
} else {
- next_column = cursor.column < curline_len ? TS->shaped_text_next_grapheme_pos(text.get_line_data(cursor.line)->get_rid(), (cursor.column)) : 0;
+ next_column = caret.column < curline_len ? TS->shaped_text_next_grapheme_pos(text.get_line_data(caret.line)->get_rid(), (caret.column)) : 0;
}
}
- _remove_text(cursor.line, cursor.column, next_line, next_column);
+ _remove_text(caret.line, caret.column, next_line, next_column);
update();
}
@@ -1886,35 +1885,35 @@ void TextEdit::delete_selection() {
selection.active = false;
selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE;
_remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
- cursor_set_line(selection.from_line, false, false);
- cursor_set_column(selection.from_column);
+ set_caret_line(selection.from_line, false, false);
+ set_caret_column(selection.from_column);
update();
}
-void TextEdit::_move_cursor_document_start(bool p_select) {
+void TextEdit::_move_caret_document_start(bool p_select) {
if (p_select) {
_pre_shift_selection();
} else {
deselect();
}
- cursor_set_line(0);
- cursor_set_column(0);
+ set_caret_line(0);
+ set_caret_column(0);
if (p_select) {
_post_shift_selection();
}
}
-void TextEdit::_move_cursor_document_end(bool p_select) {
+void TextEdit::_move_caret_document_end(bool p_select) {
if (p_select) {
_pre_shift_selection();
} else {
deselect();
}
- cursor_set_line(get_last_unhidden_line(), true, false, 9999);
- cursor_set_column(text[cursor.line].length());
+ set_caret_line(get_last_unhidden_line(), true, false, 9999);
+ set_caret_column(text[caret.line].length());
if (p_select) {
_post_shift_selection();
@@ -1931,7 +1930,7 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
int wrap_index = 0;
if (is_wrap_enabled() || is_hiding_enabled()) {
- int f_ofs = num_lines_from_rows(first_vis_line, cursor.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
+ int f_ofs = num_lines_from_rows(first_vis_line, caret.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
if (rows < 0) {
row = first_vis_line - f_ofs;
} else {
@@ -1950,7 +1949,7 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
col = text[row].size();
} else {
int colx = p_mouse.x - (cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding);
- colx += cursor.x_ofs;
+ colx += caret.x_ofs;
col = get_char_pos_for_line(colx, row, wrap_index);
if (is_wrap_enabled() && wrap_index < times_line_wraps(row)) {
// Move back one if we are at the end of the row.
@@ -1975,35 +1974,6 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
r_col = col;
}
-Vector2i TextEdit::_get_cursor_pixel_pos(bool p_adjust_viewport) {
- if (p_adjust_viewport) {
- adjust_viewport_to_cursor();
- }
- int row = 1;
- for (int i = get_first_visible_line(); i < cursor.line; i++) {
- if (!is_line_hidden(i)) {
- row += times_line_wraps(i) + 1;
- }
- }
- row += cursor.wrap_ofs;
-
- // Calculate final pixel position
- int y = (row - get_v_scroll_offset()) * get_row_height();
- int x = cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding - cursor.x_ofs;
-
- Rect2 l_caret, t_caret;
- TextServer::Direction l_dir, t_dir;
- RID text_rid = text.get_line_data(cursor.line)->get_line_rid(cursor.wrap_ofs);
- TS->shaped_text_get_carets(text_rid, cursor.column, l_caret, l_dir, t_caret, t_dir);
- if ((l_caret != Rect2() && (l_dir == TextServer::DIRECTION_AUTO || l_dir == (TextServer::Direction)input_direction)) || (t_caret == Rect2())) {
- x += l_caret.position.x;
- } else {
- x += t_caret.position.x;
- }
-
- return Vector2i(x, y);
-}
-
void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const {
float rows = p_mouse.y;
rows -= cache.style_normal->get_margin(SIDE_TOP);
@@ -2038,7 +2008,7 @@ void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const
int wrap_index = 0;
if (is_wrap_enabled() || is_hiding_enabled()) {
- int f_ofs = num_lines_from_rows(minimap_line, cursor.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
+ int f_ofs = num_lines_from_rows(minimap_line, caret.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
if (rows < 0) {
row = minimap_line - f_ofs;
} else {
@@ -2136,20 +2106,20 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- int prev_col = cursor.column;
- int prev_line = cursor.line;
+ int prev_col = caret.column;
+ int prev_line = caret.line;
- cursor_set_line(row, false, false);
- cursor_set_column(col);
+ set_caret_line(row, false, false);
+ set_caret_column(col);
- if (mb->is_shift_pressed() && (cursor.column != prev_col || cursor.line != prev_line)) {
+ if (mb->is_shift_pressed() && (caret.column != prev_col || caret.line != prev_line)) {
if (!selection.active) {
selection.active = true;
selection.selecting_mode = SelectionMode::SELECTION_MODE_POINTER;
selection.from_column = prev_col;
selection.from_line = prev_line;
- selection.to_column = cursor.column;
- selection.to_line = cursor.line;
+ selection.to_column = caret.column;
+ selection.to_line = caret.line;
if (selection.from_line > selection.to_line || (selection.from_line == selection.to_line && selection.from_column > selection.to_column)) {
SWAP(selection.from_column, selection.to_column);
@@ -2162,21 +2132,21 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
selection.selecting_column = prev_col;
update();
} else {
- if (cursor.line < selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column < selection.selecting_column)) {
+ if (caret.line < selection.selecting_line || (caret.line == selection.selecting_line && caret.column < selection.selecting_column)) {
if (selection.shiftclick_left) {
selection.shiftclick_left = !selection.shiftclick_left;
}
- selection.from_column = cursor.column;
- selection.from_line = cursor.line;
+ selection.from_column = caret.column;
+ selection.from_line = caret.line;
- } else if (cursor.line > selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column > selection.selecting_column)) {
+ } else if (caret.line > selection.selecting_line || (caret.line == selection.selecting_line && caret.column > selection.selecting_column)) {
if (!selection.shiftclick_left) {
SWAP(selection.from_column, selection.to_column);
SWAP(selection.from_line, selection.to_line);
selection.shiftclick_left = !selection.shiftclick_left;
}
- selection.to_column = cursor.column;
- selection.to_line = cursor.line;
+ selection.to_column = caret.column;
+ selection.to_line = caret.line;
} else {
selection.active = false;
@@ -2199,7 +2169,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
selection.selecting_mode = SelectionMode::SELECTION_MODE_LINE;
_update_selection_mode_line();
last_dblclk = 0;
- } else if (mb->is_double_click() && text[cursor.line].length()) {
+ } else if (mb->is_double_click() && text[caret.line].length()) {
// Double-click select word.
selection.selecting_mode = SelectionMode::SELECTION_MODE_WORD;
_update_selection_mode_word();
@@ -2216,7 +2186,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int row, col;
_get_mouse_pos(Point2i(mpos.x, mpos.y), row, col);
- if (is_right_click_moving_caret()) {
+ if (is_move_caret_on_right_click_enabled()) {
if (is_selection_active()) {
int from_line = get_selection_from_line();
int to_line = get_selection_to_line();
@@ -2229,8 +2199,8 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
if (!is_selection_active()) {
- cursor_set_line(row, true, false);
- cursor_set_column(col);
+ set_caret_line(row, true, false);
+ set_caret_column(col);
}
}
@@ -2434,7 +2404,8 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (k->is_action("ui_menu", true)) {
if (context_menu_enabled) {
_ensure_menu();
- menu->set_position(get_screen_transform().xform(_get_cursor_pixel_pos()));
+ adjust_viewport_to_caret();
+ menu->set_position(get_screen_transform().xform(get_caret_draw_pos()));
menu->set_size(Vector2(1, 1));
menu->popup();
menu->grab_focus();
@@ -2453,79 +2424,79 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
return;
}
- // CURSOR MOVEMENT
+ // CARET MOVEMENT
k = k->duplicate();
bool shift_pressed = k->is_shift_pressed();
// Remove shift or else actions will not match. Use above variable for selection.
k->set_shift_pressed(false);
- // CURSOR MOVEMENT - LEFT, RIGHT.
+ // CARET MOVEMENT - LEFT, RIGHT.
if (k->is_action("ui_text_caret_word_left", true)) {
- _move_cursor_left(shift_pressed, true);
+ _move_caret_left(shift_pressed, true);
accept_event();
return;
}
if (k->is_action("ui_text_caret_left", true)) {
- _move_cursor_left(shift_pressed, false);
+ _move_caret_left(shift_pressed, false);
accept_event();
return;
}
if (k->is_action("ui_text_caret_word_right", true)) {
- _move_cursor_right(shift_pressed, true);
+ _move_caret_right(shift_pressed, true);
accept_event();
return;
}
if (k->is_action("ui_text_caret_right", true)) {
- _move_cursor_right(shift_pressed, false);
+ _move_caret_right(shift_pressed, false);
accept_event();
return;
}
- // CURSOR MOVEMENT - UP, DOWN.
+ // CARET MOVEMENT - UP, DOWN.
if (k->is_action("ui_text_caret_up", true)) {
- _move_cursor_up(shift_pressed);
+ _move_caret_up(shift_pressed);
accept_event();
return;
}
if (k->is_action("ui_text_caret_down", true)) {
- _move_cursor_down(shift_pressed);
+ _move_caret_down(shift_pressed);
accept_event();
return;
}
- // CURSOR MOVEMENT - DOCUMENT START/END.
+ // CARET MOVEMENT - DOCUMENT START/END.
if (k->is_action("ui_text_caret_document_start", true)) { // && shift_pressed) {
- _move_cursor_document_start(shift_pressed);
+ _move_caret_document_start(shift_pressed);
accept_event();
return;
}
if (k->is_action("ui_text_caret_document_end", true)) { // && shift_pressed) {
- _move_cursor_document_end(shift_pressed);
+ _move_caret_document_end(shift_pressed);
accept_event();
return;
}
- // CURSOR MOVEMENT - LINE START/END.
+ // CARET MOVEMENT - LINE START/END.
if (k->is_action("ui_text_caret_line_start", true)) {
- _move_cursor_to_line_start(shift_pressed);
+ _move_caret_to_line_start(shift_pressed);
accept_event();
return;
}
if (k->is_action("ui_text_caret_line_end", true)) {
- _move_cursor_to_line_end(shift_pressed);
+ _move_caret_to_line_end(shift_pressed);
accept_event();
return;
}
- // CURSOR MOVEMENT - PAGE UP/DOWN.
+ // CARET MOVEMENT - PAGE UP/DOWN.
if (k->is_action("ui_text_caret_page_up", true)) {
- _move_cursor_page_up(shift_pressed);
+ _move_caret_page_up(shift_pressed);
accept_event();
return;
}
if (k->is_action("ui_text_caret_page_down", true)) {
- _move_cursor_page_down(shift_pressed);
+ _move_caret_page_down(shift_pressed);
accept_event();
return;
}
@@ -2596,8 +2567,8 @@ void TextEdit::_scroll_down(real_t p_delta) {
void TextEdit::_pre_shift_selection() {
if (!selection.active || selection.selecting_mode == SelectionMode::SELECTION_MODE_NONE) {
- selection.selecting_line = cursor.line;
- selection.selecting_column = cursor.column;
+ selection.selecting_line = caret.line;
+ selection.selecting_column = caret.column;
selection.active = true;
}
@@ -2606,7 +2577,7 @@ void TextEdit::_pre_shift_selection() {
void TextEdit::_post_shift_selection() {
if (selection.active && selection.selecting_mode == SelectionMode::SELECTION_MODE_SHIFT) {
- select(selection.selecting_line, selection.selecting_column, cursor.line, cursor.column);
+ select(selection.selecting_line, selection.selecting_column, caret.line, caret.column);
update();
}
@@ -2620,15 +2591,15 @@ void TextEdit::_scroll_lines_up() {
// Adjust the vertical scroll.
set_v_scroll(get_v_scroll() - 1);
- // Adjust the cursor to viewport.
+ // Adjust the caret to viewport.
if (!selection.active) {
- int cur_line = cursor.line;
- int cur_wrap = get_cursor_wrap_index();
+ int cur_line = caret.line;
+ int cur_wrap = get_caret_wrap_index();
int last_vis_line = get_last_full_visible_line();
int last_vis_wrap = get_last_full_visible_line_wrap_index();
if (cur_line > last_vis_line || (cur_line == last_vis_line && cur_wrap > last_vis_wrap)) {
- cursor_set_line(last_vis_line, false, false, last_vis_wrap);
+ set_caret_line(last_vis_line, false, false, last_vis_wrap);
}
}
}
@@ -2640,15 +2611,15 @@ void TextEdit::_scroll_lines_down() {
// Adjust the vertical scroll.
set_v_scroll(get_v_scroll() + 1);
- // Adjust the cursor to viewport.
+ // Adjust the caret to viewport.
if (!selection.active) {
- int cur_line = cursor.line;
- int cur_wrap = get_cursor_wrap_index();
+ int cur_line = caret.line;
+ int cur_wrap = get_caret_wrap_index();
int first_vis_line = get_first_visible_line();
- int first_vis_wrap = cursor.wrap_ofs;
+ int first_vis_wrap = caret.wrap_ofs;
if (cur_line < first_vis_line || (cur_line == first_vis_line && cur_wrap < first_vis_wrap)) {
- cursor_set_line(first_vis_line, false, false, first_vis_wrap);
+ set_caret_line(first_vis_line, false, false, first_vis_wrap);
}
}
}
@@ -2703,7 +2674,7 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
r_end_line = p_line + substrings.size() - 1;
r_end_column = text[r_end_line].length() - postinsert_text.length();
- TextServer::Direction dir = TS->shaped_text_get_dominant_direciton_in_range(text.get_line_data(r_end_line)->get_rid(), (r_end_line == p_line) ? cursor.column : 0, r_end_column);
+ TextServer::Direction dir = TS->shaped_text_get_dominant_direciton_in_range(text.get_line_data(r_end_line)->get_rid(), (r_end_line == p_line) ? caret.column : 0, r_end_column);
if (dir != TextServer::DIRECTION_AUTO) {
input_direction = (TextDirection)dir;
}
@@ -2957,27 +2928,27 @@ void TextEdit::_update_wrap_at(bool p_force) {
text.invalidate_all_lines();
}
- update_cursor_wrap_offset();
+ _update_caret_wrap_offset();
}
-void TextEdit::adjust_viewport_to_cursor() {
- // Make sure cursor is visible on the screen.
+void TextEdit::adjust_viewport_to_caret() {
+ // Make sure Caret is visible on the screen.
scrolling = false;
minimap_clicked = false;
- int cur_line = cursor.line;
- int cur_wrap = get_cursor_wrap_index();
+ int cur_line = caret.line;
+ int cur_wrap = get_caret_wrap_index();
int first_vis_line = get_first_visible_line();
- int first_vis_wrap = cursor.wrap_ofs;
+ int first_vis_wrap = caret.wrap_ofs;
int last_vis_line = get_last_full_visible_line();
int last_vis_wrap = get_last_full_visible_line_wrap_index();
if (cur_line < first_vis_line || (cur_line == first_vis_line && cur_wrap < first_vis_wrap)) {
- // Cursor is above screen.
+ // Caret is above screen.
set_line_as_first_visible(cur_line, cur_wrap);
} else if (cur_line > last_vis_line || (cur_line == last_vis_line && cur_wrap > last_vis_wrap)) {
- // Cursor is below screen.
+ // Caret is below screen.
set_line_as_last_visible(cur_line, cur_wrap);
}
@@ -2989,47 +2960,47 @@ void TextEdit::adjust_viewport_to_cursor() {
if (!is_wrap_enabled()) {
// Adjust x offset.
- Vector2i cursor_pos;
+ Vector2i caret_pos;
// Get position of the start of caret.
if (ime_text.length() != 0 && ime_selection.x != 0) {
- cursor_pos.x = get_column_x_offset_for_line(cursor.column + ime_selection.x, cursor.line);
+ caret_pos.x = get_column_x_offset_for_line(caret.column + ime_selection.x, caret.line);
} else {
- cursor_pos.x = get_column_x_offset_for_line(cursor.column, cursor.line);
+ caret_pos.x = get_column_x_offset_for_line(caret.column, caret.line);
}
// Get position of the end of caret.
if (ime_text.length() != 0) {
if (ime_selection.y != 0) {
- cursor_pos.y = get_column_x_offset_for_line(cursor.column + ime_selection.x + ime_selection.y, cursor.line);
+ caret_pos.y = get_column_x_offset_for_line(caret.column + ime_selection.x + ime_selection.y, caret.line);
} else {
- cursor_pos.y = get_column_x_offset_for_line(cursor.column + ime_text.size(), cursor.line);
+ caret_pos.y = get_column_x_offset_for_line(caret.column + ime_text.size(), caret.line);
}
} else {
- cursor_pos.y = cursor_pos.x;
+ caret_pos.y = caret_pos.x;
}
- if (MAX(cursor_pos.x, cursor_pos.y) > (cursor.x_ofs + visible_width)) {
- cursor.x_ofs = MAX(cursor_pos.x, cursor_pos.y) - visible_width + 1;
+ if (MAX(caret_pos.x, caret_pos.y) > (caret.x_ofs + visible_width)) {
+ caret.x_ofs = MAX(caret_pos.x, caret_pos.y) - visible_width + 1;
}
- if (MIN(cursor_pos.x, cursor_pos.y) < cursor.x_ofs) {
- cursor.x_ofs = MIN(cursor_pos.x, cursor_pos.y);
+ if (MIN(caret_pos.x, caret_pos.y) < caret.x_ofs) {
+ caret.x_ofs = MIN(caret_pos.x, caret_pos.y);
}
} else {
- cursor.x_ofs = 0;
+ caret.x_ofs = 0;
}
- h_scroll->set_value(cursor.x_ofs);
+ h_scroll->set_value(caret.x_ofs);
update();
}
-void TextEdit::center_viewport_to_cursor() {
- // Move viewport so the cursor is in the center of the screen.
+void TextEdit::center_viewport_to_caret() {
+ // Move viewport so the caret is in the center of the screen.
scrolling = false;
minimap_clicked = false;
- set_line_as_center_visible(cursor.line, get_cursor_wrap_index());
+ set_line_as_center_visible(caret.line, get_caret_wrap_index());
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - gutters_width - gutter_padding - cache.minimap_width;
if (v_scroll->is_visible_in_tree()) {
visible_width -= v_scroll->get_combined_minimum_size().width;
@@ -3039,49 +3010,49 @@ void TextEdit::center_viewport_to_cursor() {
if (is_wrap_enabled()) {
// Center x offset.
- Vector2i cursor_pos;
+ Vector2i caret_pos;
// Get position of the start of caret.
if (ime_text.length() != 0 && ime_selection.x != 0) {
- cursor_pos.x = get_column_x_offset_for_line(cursor.column + ime_selection.x, cursor.line);
+ caret_pos.x = get_column_x_offset_for_line(caret.column + ime_selection.x, caret.line);
} else {
- cursor_pos.x = get_column_x_offset_for_line(cursor.column, cursor.line);
+ caret_pos.x = get_column_x_offset_for_line(caret.column, caret.line);
}
// Get position of the end of caret.
if (ime_text.length() != 0) {
if (ime_selection.y != 0) {
- cursor_pos.y = get_column_x_offset_for_line(cursor.column + ime_selection.x + ime_selection.y, cursor.line);
+ caret_pos.y = get_column_x_offset_for_line(caret.column + ime_selection.x + ime_selection.y, caret.line);
} else {
- cursor_pos.y = get_column_x_offset_for_line(cursor.column + ime_text.size(), cursor.line);
+ caret_pos.y = get_column_x_offset_for_line(caret.column + ime_text.size(), caret.line);
}
} else {
- cursor_pos.y = cursor_pos.x;
+ caret_pos.y = caret_pos.x;
}
- if (MAX(cursor_pos.x, cursor_pos.y) > (cursor.x_ofs + visible_width)) {
- cursor.x_ofs = MAX(cursor_pos.x, cursor_pos.y) - visible_width + 1;
+ if (MAX(caret_pos.x, caret_pos.y) > (caret.x_ofs + visible_width)) {
+ caret.x_ofs = MAX(caret_pos.x, caret_pos.y) - visible_width + 1;
}
- if (MIN(cursor_pos.x, cursor_pos.y) < cursor.x_ofs) {
- cursor.x_ofs = MIN(cursor_pos.x, cursor_pos.y);
+ if (MIN(caret_pos.x, caret_pos.y) < caret.x_ofs) {
+ caret.x_ofs = MIN(caret_pos.x, caret_pos.y);
}
} else {
- cursor.x_ofs = 0;
+ caret.x_ofs = 0;
}
- h_scroll->set_value(cursor.x_ofs);
+ h_scroll->set_value(caret.x_ofs);
update();
}
-void TextEdit::update_cursor_wrap_offset() {
+void TextEdit::_update_caret_wrap_offset() {
int first_vis_line = get_first_visible_line();
if (line_wraps(first_vis_line)) {
- cursor.wrap_ofs = MIN(cursor.wrap_ofs, times_line_wraps(first_vis_line));
+ caret.wrap_ofs = MIN(caret.wrap_ofs, times_line_wraps(first_vis_line));
} else {
- cursor.wrap_ofs = 0;
+ caret.wrap_ofs = 0;
}
- set_line_as_first_visible(cursor.line_ofs, cursor.wrap_ofs);
+ set_line_as_first_visible(caret.line_ofs, caret.wrap_ofs);
}
bool TextEdit::line_wraps(int line) const {
@@ -3120,10 +3091,6 @@ Vector<String> TextEdit::get_wrap_rows_text(int p_line) const {
return lines;
}
-int TextEdit::get_cursor_wrap_index() const {
- return get_line_wrap_index_at_col(cursor.line, cursor.column);
-}
-
int TextEdit::get_line_wrap_index_at_col(int p_line, int p_column) const {
ERR_FAIL_INDEX_V(p_line, text.size(), 0);
@@ -3146,156 +3113,6 @@ int TextEdit::get_line_wrap_index_at_col(int p_line, int p_column) const {
return wrap_index;
}
-void TextEdit::set_mid_grapheme_caret_enabled(const bool p_enabled) {
- mid_grapheme_caret_enabled = p_enabled;
-}
-
-bool TextEdit::get_mid_grapheme_caret_enabled() const {
- return mid_grapheme_caret_enabled;
-}
-
-void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) {
- if (p_col < 0) {
- p_col = 0;
- }
-
- cursor.column = p_col;
- if (cursor.column > get_line(cursor.line).length()) {
- cursor.column = get_line(cursor.line).length();
- }
-
- cursor.last_fit_x = get_column_x_offset_for_line(cursor.column, cursor.line);
-
- if (p_adjust_viewport) {
- adjust_viewport_to_cursor();
- }
-
- if (!cursor_changed_dirty) {
- if (is_inside_tree()) {
- MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
- }
- cursor_changed_dirty = true;
- }
-}
-
-void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_hidden, int p_wrap_index) {
- if (setting_row) {
- return;
- }
-
- setting_row = true;
- if (p_row < 0) {
- p_row = 0;
- }
-
- if (p_row >= text.size()) {
- p_row = text.size() - 1;
- }
-
- if (!p_can_be_hidden) {
- if (is_line_hidden(CLAMP(p_row, 0, text.size() - 1))) {
- int move_down = num_lines_from(p_row, 1) - 1;
- if (p_row + move_down <= text.size() - 1 && !is_line_hidden(p_row + move_down)) {
- p_row += move_down;
- } else {
- int move_up = num_lines_from(p_row, -1) - 1;
- if (p_row - move_up > 0 && !is_line_hidden(p_row - move_up)) {
- p_row -= move_up;
- } else {
- WARN_PRINT(("Cursor set to hidden line " + itos(p_row) + " and there are no nonhidden lines."));
- }
- }
- }
- }
- cursor.line = p_row;
-
- int n_col = get_char_pos_for_line(cursor.last_fit_x, p_row, p_wrap_index);
- if (n_col != 0 && is_wrap_enabled() && p_wrap_index < times_line_wraps(p_row)) {
- Vector<String> rows = get_wrap_rows_text(p_row);
- int row_end_col = 0;
- for (int i = 0; i < p_wrap_index + 1; i++) {
- row_end_col += rows[i].length();
- }
- if (n_col >= row_end_col) {
- n_col -= 1;
- }
- }
- cursor.column = n_col;
-
- if (p_adjust_viewport) {
- adjust_viewport_to_cursor();
- }
-
- setting_row = false;
-
- if (!cursor_changed_dirty) {
- if (is_inside_tree()) {
- MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
- }
- cursor_changed_dirty = true;
- }
-}
-
-Point2 TextEdit::get_caret_draw_pos() const {
- return cursor.draw_pos;
-}
-
-bool TextEdit::is_caret_visible() const {
- return cursor.visible;
-}
-
-int TextEdit::cursor_get_column() const {
- return cursor.column;
-}
-
-int TextEdit::cursor_get_line() const {
- return cursor.line;
-}
-
-bool TextEdit::cursor_get_blink_enabled() const {
- return caret_blink_enabled;
-}
-
-void TextEdit::cursor_set_blink_enabled(const bool p_enabled) {
- caret_blink_enabled = p_enabled;
-
- if (has_focus()) {
- if (p_enabled) {
- caret_blink_timer->start();
- } else {
- caret_blink_timer->stop();
- }
- }
-
- draw_caret = true;
-}
-
-float TextEdit::cursor_get_blink_speed() const {
- return caret_blink_timer->get_wait_time();
-}
-
-void TextEdit::cursor_set_blink_speed(const float p_speed) {
- ERR_FAIL_COND(p_speed <= 0);
- caret_blink_timer->set_wait_time(p_speed);
-}
-
-void TextEdit::cursor_set_block_mode(const bool p_enable) {
- block_caret = p_enable;
- update();
-}
-
-bool TextEdit::cursor_is_block_mode() const {
- return block_caret;
-}
-
-void TextEdit::set_right_click_moves_caret(bool p_enable) {
- right_click_moves_caret = p_enable;
-}
-
-bool TextEdit::is_right_click_moving_caret() const {
- return right_click_moves_caret;
-}
-
TextEdit::SelectionMode TextEdit::get_selection_mode() const {
return selection.selecting_mode;
}
@@ -3331,7 +3148,7 @@ void TextEdit::_scroll_moved(double p_to_val) {
}
if (h_scroll->is_visible_in_tree()) {
- cursor.x_ofs = h_scroll->get_value();
+ caret.x_ofs = h_scroll->get_value();
}
if (v_scroll->is_visible_in_tree()) {
// Set line ofs and wrap ofs.
@@ -3352,8 +3169,8 @@ void TextEdit::_scroll_moved(double p_to_val) {
int wi = line_wrap_amount - (sc - v_scroll_i - 1);
wi = CLAMP(wi, 0, line_wrap_amount);
- cursor.line_ofs = n_line;
- cursor.wrap_ofs = wi;
+ caret.line_ofs = n_line;
+ caret.wrap_ofs = wi;
}
update();
}
@@ -3394,7 +3211,7 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
Rect2 l_caret, t_caret;
TextServer::Direction l_dir, t_dir;
RID text_rid = text.get_line_data(p_line)->get_line_rid(row);
- TS->shaped_text_get_carets(text_rid, cursor.column, l_caret, l_dir, t_caret, t_dir);
+ TS->shaped_text_get_carets(text_rid, caret.column, l_caret, l_dir, t_caret, t_dir);
if ((l_caret != Rect2() && (l_dir == TextServer::DIRECTION_AUTO || l_dir == (TextServer::Direction)input_direction)) || (t_caret == Rect2())) {
return l_caret.position.x;
} else {
@@ -3402,17 +3219,17 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
}
}
-void TextEdit::insert_text_at_cursor(const String &p_text) {
+void TextEdit::insert_text_at_caret(const String &p_text) {
if (selection.active) {
delete_selection();
}
int new_column, new_line;
- _insert_text(cursor.line, cursor.column, p_text, &new_line, &new_column);
+ _insert_text(caret.line, caret.column, p_text, &new_line, &new_column);
_update_scrollbars();
- cursor_set_line(new_line, false);
- cursor_set_column(new_column);
+ set_caret_line(new_line, false);
+ set_caret_column(new_column);
update();
}
@@ -3449,22 +3266,22 @@ void TextEdit::set_text(String p_text) {
setting_text = true;
if (!undo_enabled) {
_clear();
- insert_text_at_cursor(p_text);
+ insert_text_at_caret(p_text);
}
if (undo_enabled) {
- cursor_set_line(0);
- cursor_set_column(0);
+ set_caret_line(0);
+ set_caret_column(0);
begin_complex_operation();
_remove_text(0, 0, MAX(0, get_line_count() - 1), MAX(get_line(MAX(get_line_count() - 1, 0)).size() - 1, 0));
- insert_text_at_cursor(p_text);
+ insert_text_at_caret(p_text);
end_complex_operation();
selection.active = false;
}
- cursor_set_line(0);
- cursor_set_column(0);
+ set_caret_line(0);
+ set_caret_column(0);
update();
setting_text = false;
@@ -3614,12 +3431,12 @@ bool TextEdit::has_ime_text() const {
void TextEdit::_clear() {
clear_undo_history();
text.clear();
- cursor.column = 0;
- cursor.line = 0;
- cursor.x_ofs = 0;
- cursor.line_ofs = 0;
- cursor.wrap_ofs = 0;
- cursor.last_fit_x = 0;
+ caret.column = 0;
+ caret.line = 0;
+ caret.x_ofs = 0;
+ caret.line_ofs = 0;
+ caret.wrap_ofs = 0;
+ caret.last_fit_x = 0;
selection.active = false;
}
@@ -3654,25 +3471,11 @@ bool TextEdit::is_wrap_enabled() const {
return wrap_enabled;
}
-void TextEdit::_reset_caret_blink_timer() {
- if (caret_blink_enabled) {
- draw_caret = true;
- if (has_focus()) {
- caret_blink_timer->stop();
- caret_blink_timer->start();
- update();
- }
- }
-}
-
-void TextEdit::_toggle_draw_caret() {
- draw_caret = !draw_caret;
- if (is_visible_in_tree() && has_focus() && window_has_focus) {
- update();
- }
-}
-
void TextEdit::_update_caches() {
+ /* Caret */
+ caret_color = get_theme_color(SNAME("caret_color"));
+ caret_background_color = get_theme_color(SNAME("caret_background_color"));
+
cache.style_normal = get_theme_stylebox(SNAME("normal"));
cache.style_focus = get_theme_stylebox(SNAME("focus"));
cache.style_readonly = get_theme_stylebox(SNAME("read_only"));
@@ -3680,8 +3483,6 @@ void TextEdit::_update_caches() {
cache.font_size = get_theme_font_size(SNAME("font_size"));
cache.outline_color = get_theme_color(SNAME("font_outline_color"));
cache.outline_size = get_theme_constant(SNAME("outline_size"));
- cache.caret_color = get_theme_color(SNAME("caret_color"));
- cache.caret_background_color = get_theme_color(SNAME("caret_background_color"));
cache.font_color = get_theme_color(SNAME("font_color"));
cache.font_selected_color = get_theme_color(SNAME("font_selected_color"));
cache.font_readonly_color = get_theme_color(SNAME("font_readonly_color"));
@@ -3768,6 +3569,160 @@ void TextEdit::paste() {
_paste();
}
+/* Caret */
+void TextEdit::set_caret_type(CaretType p_type) {
+ caret_type = p_type;
+ update();
+}
+
+TextEdit::CaretType TextEdit::get_caret_type() const {
+ return caret_type;
+}
+
+void TextEdit::set_caret_blink_enabled(const bool p_enabled) {
+ caret_blink_enabled = p_enabled;
+
+ if (has_focus()) {
+ if (p_enabled) {
+ caret_blink_timer->start();
+ } else {
+ caret_blink_timer->stop();
+ }
+ }
+ draw_caret = true;
+}
+
+bool TextEdit::is_caret_blink_enabled() const {
+ return caret_blink_enabled;
+}
+
+float TextEdit::get_caret_blink_speed() const {
+ return caret_blink_timer->get_wait_time();
+}
+
+void TextEdit::set_caret_blink_speed(const float p_speed) {
+ ERR_FAIL_COND(p_speed <= 0);
+ caret_blink_timer->set_wait_time(p_speed);
+}
+
+void TextEdit::set_move_caret_on_right_click_enabled(const bool p_enable) {
+ move_caret_on_right_click = p_enable;
+}
+
+bool TextEdit::is_move_caret_on_right_click_enabled() const {
+ return move_caret_on_right_click;
+}
+
+void TextEdit::set_caret_mid_grapheme_enabled(const bool p_enabled) {
+ caret_mid_grapheme_enabled = p_enabled;
+}
+
+bool TextEdit::is_caret_mid_grapheme_enabled() const {
+ return caret_mid_grapheme_enabled;
+}
+
+bool TextEdit::is_caret_visible() const {
+ return caret.visible;
+}
+
+Point2 TextEdit::get_caret_draw_pos() const {
+ return caret.draw_pos;
+}
+
+void TextEdit::set_caret_line(int p_line, bool p_adjust_viewport, bool p_can_be_hidden, int p_wrap_index) {
+ if (setting_caret_line) {
+ return;
+ }
+
+ setting_caret_line = true;
+ if (p_line < 0) {
+ p_line = 0;
+ }
+
+ if (p_line >= text.size()) {
+ p_line = text.size() - 1;
+ }
+
+ if (!p_can_be_hidden) {
+ if (is_line_hidden(CLAMP(p_line, 0, text.size() - 1))) {
+ int move_down = num_lines_from(p_line, 1) - 1;
+ if (p_line + move_down <= text.size() - 1 && !is_line_hidden(p_line + move_down)) {
+ p_line += move_down;
+ } else {
+ int move_up = num_lines_from(p_line, -1) - 1;
+ if (p_line - move_up > 0 && !is_line_hidden(p_line - move_up)) {
+ p_line -= move_up;
+ } else {
+ WARN_PRINT(("Caret set to hidden line " + itos(p_line) + " and there are no nonhidden lines."));
+ }
+ }
+ }
+ }
+ caret.line = p_line;
+
+ int n_col = get_char_pos_for_line(caret.last_fit_x, p_line, p_wrap_index);
+ if (n_col != 0 && is_wrap_enabled() && p_wrap_index < times_line_wraps(p_line)) {
+ Vector<String> rows = get_wrap_rows_text(p_line);
+ int row_end_col = 0;
+ for (int i = 0; i < p_wrap_index + 1; i++) {
+ row_end_col += rows[i].length();
+ }
+ if (n_col >= row_end_col) {
+ n_col -= 1;
+ }
+ }
+ caret.column = n_col;
+
+ if (p_adjust_viewport) {
+ adjust_viewport_to_caret();
+ }
+
+ setting_caret_line = false;
+
+ if (!caret_pos_dirty) {
+ if (is_inside_tree()) {
+ MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed");
+ }
+ caret_pos_dirty = true;
+ }
+}
+
+int TextEdit::get_caret_line() const {
+ return caret.line;
+}
+
+void TextEdit::set_caret_column(int p_col, bool p_adjust_viewport) {
+ if (p_col < 0) {
+ p_col = 0;
+ }
+
+ caret.column = p_col;
+ if (caret.column > get_line(caret.line).length()) {
+ caret.column = get_line(caret.line).length();
+ }
+
+ caret.last_fit_x = get_column_x_offset_for_line(caret.column, caret.line);
+
+ if (p_adjust_viewport) {
+ adjust_viewport_to_caret();
+ }
+
+ if (!caret_pos_dirty) {
+ if (is_inside_tree()) {
+ MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed");
+ }
+ caret_pos_dirty = true;
+ }
+}
+
+int TextEdit::get_caret_column() const {
+ return caret.column;
+}
+
+int TextEdit::get_caret_wrap_index() const {
+ return get_line_wrap_index_at_col(caret.line, caret.column);
+}
+
/* Syntax Highlighting. */
Ref<SyntaxHighlighter> TextEdit::get_syntax_highlighter() {
return syntax_highlighter;
@@ -4028,8 +3983,8 @@ void TextEdit::select_all() {
selection.to_column = text[selection.to_line].length();
selection.selecting_mode = SelectionMode::SELECTION_MODE_SHIFT;
selection.shiftclick_left = true;
- cursor_set_line(selection.to_line, false);
- cursor_set_column(selection.to_column, false);
+ set_caret_line(selection.to_line, false);
+ set_caret_column(selection.to_column, false);
update();
}
@@ -4052,18 +4007,18 @@ void TextEdit::select_word_under_caret() {
int begin = 0;
int end = 0;
- const Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(cursor.line)->get_rid());
+ const Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid());
for (int i = 0; i < words.size(); i++) {
- if (words[i].x <= cursor.column && words[i].y >= cursor.column) {
+ if (words[i].x <= caret.column && words[i].y >= caret.column) {
begin = words[i].x;
end = words[i].y;
break;
}
}
- select(cursor.line, begin, cursor.line, end);
- // Move the cursor to the end of the word for easier editing.
- cursor_set_column(end, false);
+ select(caret.line, begin, caret.line, end);
+ // Move the caret to the end of the word for easier editing.
+ set_caret_column(end, false);
}
void TextEdit::deselect() {
@@ -4167,11 +4122,11 @@ String TextEdit::get_selection_text() const {
return _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
}
-String TextEdit::get_word_under_cursor() const {
- Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(cursor.line)->get_rid());
+String TextEdit::get_word_under_caret() const {
+ Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid());
for (int i = 0; i < words.size(); i++) {
- if (words[i].x <= cursor.column && words[i].y > cursor.column) {
- return text[cursor.line].substr(words[i].x, words[i].y - words[i].x);
+ if (words[i].x <= caret.column && words[i].y > caret.column) {
+ return text[caret.line].substr(words[i].x, words[i].y - words[i].x);
}
}
return "";
@@ -4362,11 +4317,6 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
return true;
}
-void TextEdit::_cursor_changed_emit() {
- emit_signal(SNAME("cursor_changed"));
- cursor_changed_dirty = false;
-}
-
void TextEdit::_text_changed_emit() {
emit_signal(SNAME("text_changed"));
text_changed_dirty = false;
@@ -4605,11 +4555,11 @@ void TextEdit::undo() {
_update_scrollbars();
if (undo_stack_pos->get().type == TextOperation::TYPE_REMOVE) {
- cursor_set_line(undo_stack_pos->get().to_line, false);
- cursor_set_column(undo_stack_pos->get().to_column);
+ set_caret_line(undo_stack_pos->get().to_line, false);
+ set_caret_column(undo_stack_pos->get().to_column);
} else {
- cursor_set_line(undo_stack_pos->get().from_line, false);
- cursor_set_column(undo_stack_pos->get().from_column);
+ set_caret_line(undo_stack_pos->get().from_line, false);
+ set_caret_column(undo_stack_pos->get().from_column);
}
update();
}
@@ -4643,8 +4593,8 @@ void TextEdit::redo() {
}
_update_scrollbars();
- cursor_set_line(undo_stack_pos->get().to_line, false);
- cursor_set_column(undo_stack_pos->get().to_column);
+ set_caret_line(undo_stack_pos->get().to_line, false);
+ set_caret_column(undo_stack_pos->get().to_column);
undo_stack_pos = undo_stack_pos->next();
update();
}
@@ -4796,14 +4746,14 @@ void TextEdit::set_line_as_last_visible(int p_line, int p_wrap_index) {
}
int TextEdit::get_first_visible_line() const {
- return CLAMP(cursor.line_ofs, 0, text.size() - 1);
+ return CLAMP(caret.line_ofs, 0, text.size() - 1);
}
int TextEdit::get_last_full_visible_line() const {
int first_vis_line = get_first_visible_line();
int last_vis_line = 0;
int wi;
- last_vis_line = first_vis_line + num_lines_from_rows(first_vis_line, cursor.wrap_ofs, get_visible_rows(), wi) - 1;
+ last_vis_line = first_vis_line + num_lines_from_rows(first_vis_line, caret.wrap_ofs, get_visible_rows(), wi) - 1;
last_vis_line = CLAMP(last_vis_line, 0, text.size() - 1);
return last_vis_line;
}
@@ -4811,7 +4761,7 @@ int TextEdit::get_last_full_visible_line() const {
int TextEdit::get_last_full_visible_line_wrap_index() const {
int first_vis_line = get_first_visible_line();
int wi;
- num_lines_from_rows(first_vis_line, cursor.wrap_ofs, get_visible_rows(), wi);
+ num_lines_from_rows(first_vis_line, caret.wrap_ofs, get_visible_rows(), wi);
return wi;
}
@@ -4939,8 +4889,8 @@ void TextEdit::set_line(int line, String new_text) {
}
_remove_text(line, 0, line, text[line].length());
_insert_text(line, 0, new_text);
- if (cursor.line == line) {
- cursor.column = MIN(cursor.column, new_text.length());
+ if (caret.line == line) {
+ caret.column = MIN(caret.column, new_text.length());
}
if (is_selection_active() && line == selection.to_line && selection.to_column > text[line].length()) {
selection.to_column = text[line].length();
@@ -4949,9 +4899,9 @@ void TextEdit::set_line(int line, String new_text) {
void TextEdit::insert_at(const String &p_text, int at) {
_insert_text(at, 0, p_text + "\n");
- if (cursor.line >= at) {
+ if (caret.line >= at) {
// offset cursor when located after inserted line
- ++cursor.line;
+ ++caret.line;
}
if (is_selection_active()) {
if (selection.from_line >= at) {
@@ -5060,82 +5010,82 @@ void TextEdit::menu_option(int p_option) {
} break;
case MENU_INSERT_LRM: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x200E));
+ insert_text_at_caret(String::chr(0x200E));
}
} break;
case MENU_INSERT_RLM: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x200F));
+ insert_text_at_caret(String::chr(0x200F));
}
} break;
case MENU_INSERT_LRE: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x202A));
+ insert_text_at_caret(String::chr(0x202A));
}
} break;
case MENU_INSERT_RLE: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x202B));
+ insert_text_at_caret(String::chr(0x202B));
}
} break;
case MENU_INSERT_LRO: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x202D));
+ insert_text_at_caret(String::chr(0x202D));
}
} break;
case MENU_INSERT_RLO: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x202E));
+ insert_text_at_caret(String::chr(0x202E));
}
} break;
case MENU_INSERT_PDF: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x202C));
+ insert_text_at_caret(String::chr(0x202C));
}
} break;
case MENU_INSERT_ALM: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x061C));
+ insert_text_at_caret(String::chr(0x061C));
}
} break;
case MENU_INSERT_LRI: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x2066));
+ insert_text_at_caret(String::chr(0x2066));
}
} break;
case MENU_INSERT_RLI: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x2067));
+ insert_text_at_caret(String::chr(0x2067));
}
} break;
case MENU_INSERT_FSI: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x2068));
+ insert_text_at_caret(String::chr(0x2068));
}
} break;
case MENU_INSERT_PDI: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x2069));
+ insert_text_at_caret(String::chr(0x2069));
}
} break;
case MENU_INSERT_ZWJ: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x200D));
+ insert_text_at_caret(String::chr(0x200D));
}
} break;
case MENU_INSERT_ZWNJ: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x200C));
+ insert_text_at_caret(String::chr(0x200C));
}
} break;
case MENU_INSERT_WJ: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x2060));
+ insert_text_at_caret(String::chr(0x2060));
}
} break;
case MENU_INSERT_SHY: {
if (!readonly) {
- insert_text_at_cursor(String::chr(0x00AD));
+ insert_text_at_caret(String::chr(0x00AD));
}
}
}
@@ -5246,7 +5196,6 @@ void TextEdit::_get_property_list(List<PropertyInfo> *p_list) const {
void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &TextEdit::_gui_input);
- ClassDB::bind_method(D_METHOD("_cursor_changed_emit"), &TextEdit::_cursor_changed_emit);
ClassDB::bind_method(D_METHOD("_text_changed_emit"), &TextEdit::_text_changed_emit);
ClassDB::bind_method(D_METHOD("_update_wrap_at", "force"), &TextEdit::_update_wrap_at, DEFVAL(false));
@@ -5276,7 +5225,7 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tab_size"), &TextEdit::get_tab_size);
ClassDB::bind_method(D_METHOD("set_text", "text"), &TextEdit::set_text);
- ClassDB::bind_method(D_METHOD("insert_text_at_cursor", "text"), &TextEdit::insert_text_at_cursor);
+ ClassDB::bind_method(D_METHOD("insert_text_at_caret", "text"), &TextEdit::insert_text_at_caret);
ClassDB::bind_method(D_METHOD("get_line_count"), &TextEdit::get_line_count);
ClassDB::bind_method(D_METHOD("get_text"), &TextEdit::get_text);
@@ -5289,26 +5238,7 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override_options", "args"), &TextEdit::set_structured_text_bidi_override_options);
ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override_options"), &TextEdit::get_structured_text_bidi_override_options);
- ClassDB::bind_method(D_METHOD("center_viewport_to_cursor"), &TextEdit::center_viewport_to_cursor);
- ClassDB::bind_method(D_METHOD("cursor_set_column", "column", "adjust_viewport"), &TextEdit::cursor_set_column, DEFVAL(true));
- ClassDB::bind_method(D_METHOD("cursor_set_line", "line", "adjust_viewport", "can_be_hidden", "wrap_index"), &TextEdit::cursor_set_line, DEFVAL(true), DEFVAL(true), DEFVAL(0));
-
- ClassDB::bind_method(D_METHOD("get_caret_draw_pos"), &TextEdit::get_caret_draw_pos);
- ClassDB::bind_method(D_METHOD("is_caret_visible"), &TextEdit::is_caret_visible);
- ClassDB::bind_method(D_METHOD("cursor_get_column"), &TextEdit::cursor_get_column);
- ClassDB::bind_method(D_METHOD("cursor_get_line"), &TextEdit::cursor_get_line);
- ClassDB::bind_method(D_METHOD("cursor_set_blink_enabled", "enable"), &TextEdit::cursor_set_blink_enabled);
- ClassDB::bind_method(D_METHOD("cursor_get_blink_enabled"), &TextEdit::cursor_get_blink_enabled);
- ClassDB::bind_method(D_METHOD("cursor_set_blink_speed", "blink_speed"), &TextEdit::cursor_set_blink_speed);
- ClassDB::bind_method(D_METHOD("cursor_get_blink_speed"), &TextEdit::cursor_get_blink_speed);
- ClassDB::bind_method(D_METHOD("cursor_set_block_mode", "enable"), &TextEdit::cursor_set_block_mode);
- ClassDB::bind_method(D_METHOD("cursor_is_block_mode"), &TextEdit::cursor_is_block_mode);
-
- ClassDB::bind_method(D_METHOD("set_mid_grapheme_caret_enabled", "enabled"), &TextEdit::set_mid_grapheme_caret_enabled);
- ClassDB::bind_method(D_METHOD("get_mid_grapheme_caret_enabled"), &TextEdit::get_mid_grapheme_caret_enabled);
-
- ClassDB::bind_method(D_METHOD("set_right_click_moves_caret", "enable"), &TextEdit::set_right_click_moves_caret);
- ClassDB::bind_method(D_METHOD("is_right_click_moving_caret"), &TextEdit::is_right_click_moving_caret);
+ ClassDB::bind_method(D_METHOD("center_viewport_to_caret"), &TextEdit::center_viewport_to_caret);
ClassDB::bind_method(D_METHOD("get_selection_mode"), &TextEdit::get_selection_mode);
ClassDB::bind_method(D_METHOD("set_selection_mode", "mode", "line", "column"), &TextEdit::set_selection_mode, DEFVAL(-1), DEFVAL(-1));
@@ -5342,7 +5272,7 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_selection_to_line"), &TextEdit::get_selection_to_line);
ClassDB::bind_method(D_METHOD("get_selection_to_column"), &TextEdit::get_selection_to_column);
ClassDB::bind_method(D_METHOD("get_selection_text"), &TextEdit::get_selection_text);
- ClassDB::bind_method(D_METHOD("get_word_under_cursor"), &TextEdit::get_word_under_cursor);
+ ClassDB::bind_method(D_METHOD("get_word_under_caret"), &TextEdit::get_word_under_caret);
ClassDB::bind_method(D_METHOD("search", "key", "flags", "from_line", "from_column"), &TextEdit::_search_bind);
ClassDB::bind_method(D_METHOD("undo"), &TextEdit::undo);
@@ -5376,6 +5306,39 @@ void TextEdit::_bind_methods() {
BIND_VMETHOD(MethodInfo("_copy"));
BIND_VMETHOD(MethodInfo("_paste"));
+ /* Caret. */
+ BIND_ENUM_CONSTANT(CARET_TYPE_LINE);
+ BIND_ENUM_CONSTANT(CARET_TYPE_BLOCK);
+
+ // internal.
+ ClassDB::bind_method(D_METHOD("_emit_caret_changed"), &TextEdit::_emit_caret_changed);
+
+ ClassDB::bind_method(D_METHOD("set_caret_type", "type"), &TextEdit::set_caret_type);
+ ClassDB::bind_method(D_METHOD("get_caret_type"), &TextEdit::get_caret_type);
+
+ ClassDB::bind_method(D_METHOD("set_caret_blink_enabled", "enable"), &TextEdit::set_caret_blink_enabled);
+ ClassDB::bind_method(D_METHOD("is_caret_blink_enabled"), &TextEdit::is_caret_blink_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_caret_blink_speed", "blink_speed"), &TextEdit::set_caret_blink_speed);
+ ClassDB::bind_method(D_METHOD("get_caret_blink_speed"), &TextEdit::get_caret_blink_speed);
+
+ ClassDB::bind_method(D_METHOD("set_move_caret_on_right_click_enabled", "enable"), &TextEdit::set_move_caret_on_right_click_enabled);
+ ClassDB::bind_method(D_METHOD("is_move_caret_on_right_click_enabled"), &TextEdit::is_move_caret_on_right_click_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_caret_mid_grapheme_enabled", "enabled"), &TextEdit::set_caret_mid_grapheme_enabled);
+ ClassDB::bind_method(D_METHOD("is_caret_mid_grapheme_enabled"), &TextEdit::is_caret_mid_grapheme_enabled);
+
+ ClassDB::bind_method(D_METHOD("is_caret_visible"), &TextEdit::is_caret_visible);
+ ClassDB::bind_method(D_METHOD("get_caret_draw_pos"), &TextEdit::get_caret_draw_pos);
+
+ ClassDB::bind_method(D_METHOD("set_caret_line", "line", "adjust_viewport", "can_be_hidden", "wrap_index"), &TextEdit::set_caret_line, DEFVAL(true), DEFVAL(true), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_caret_line"), &TextEdit::get_caret_line);
+
+ ClassDB::bind_method(D_METHOD("set_caret_column", "column", "adjust_viewport"), &TextEdit::set_caret_column, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("get_caret_column"), &TextEdit::get_caret_column);
+
+ ClassDB::bind_method(D_METHOD("get_caret_wrap_index"), &TextEdit::get_caret_wrap_index);
+
/* Syntax Highlighting. */
ClassDB::bind_method(D_METHOD("set_syntax_highlighter", "syntax_highlighter"), &TextEdit::set_syntax_highlighter);
ClassDB::bind_method(D_METHOD("get_syntax_highlighter"), &TextEdit::get_syntax_highlighter);
@@ -5468,17 +5431,20 @@ void TextEdit::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "minimap_width"), "set_minimap_width", "get_minimap_width");
ADD_GROUP("Caret", "caret_");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), "cursor_set_block_mode", "cursor_is_block_mode");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "cursor_set_blink_speed", "cursor_get_blink_speed");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_moving_by_right_click"), "set_right_click_moves_caret", "is_right_click_moving_caret");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_mid_grapheme"), "set_mid_grapheme_caret_enabled", "get_mid_grapheme_caret_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "caret_type", PROPERTY_HINT_ENUM, "Line,Block"), "set_caret_type", "get_caret_type");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "set_caret_blink_enabled", "is_caret_blink_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "set_caret_blink_speed", "get_caret_blink_speed");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_move_on_right_click"), "set_move_caret_on_right_click_enabled", "is_move_caret_on_right_click_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_mid_grapheme"), "set_caret_mid_grapheme_enabled", "is_caret_mid_grapheme_enabled");
ADD_GROUP("Structured Text", "structured_text_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "structured_text_bidi_override", PROPERTY_HINT_ENUM, "Default,URI,File,Email,List,None,Custom"), "set_structured_text_bidi_override", "get_structured_text_bidi_override");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "structured_text_bidi_override_options"), "set_structured_text_bidi_override_options", "get_structured_text_bidi_override_options");
- ADD_SIGNAL(MethodInfo("cursor_changed"));
+ /* Signals */
+ /* Caret. */
+ ADD_SIGNAL(MethodInfo("caret_changed"));
+
ADD_SIGNAL(MethodInfo("text_changed"));
ADD_SIGNAL(MethodInfo("lines_edited_from", PropertyInfo(Variant::INT, "from_line"), PropertyInfo(Variant::INT, "to_line")));
ADD_SIGNAL(MethodInfo("gutter_clicked", PropertyInfo(Variant::INT, "line"), PropertyInfo(Variant::INT, "gutter")));
@@ -5613,15 +5579,15 @@ void TextEdit::_handle_unicode_input(const uint32_t p_unicode) {
begin_complex_operation();
/* Make sure we don't try and remove empty space. */
- int cl = cursor_get_line();
- int cc = cursor_get_column();
+ int cl = get_caret_line();
+ int cc = get_caret_column();
if (cc < get_line(cl).length()) {
_remove_text(cl, cc, cl, cc + 1);
}
}
const char32_t chr[2] = { (char32_t)p_unicode, 0 };
- insert_text_at_cursor(chr);
+ insert_text_at_caret(chr);
if ((insert_mode && !had_selection) || (had_selection)) {
end_complex_operation();
@@ -5633,8 +5599,8 @@ void TextEdit::_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;
@@ -5655,8 +5621,8 @@ void TextEdit::_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);
}
void TextEdit::_cut() {
@@ -5671,19 +5637,19 @@ void TextEdit::_cut() {
return;
}
- int cl = cursor_get_line();
+ int cl = get_caret_line();
String clipboard = text[cl];
DisplayServer::get_singleton()->clipboard_set(clipboard);
- cursor_set_line(cl);
- cursor_set_column(0);
+ set_caret_line(cl);
+ set_caret_column(0);
if (cl == 0 && get_line_count() > 1) {
_remove_text(cl, 0, cl + 1, 0);
} else {
_remove_text(cl, 0, cl, text[cl].length());
backspace();
- cursor_set_line(cursor_get_line() + 1);
+ set_caret_line(get_caret_line() + 1);
}
cut_copy_line = clipboard;
@@ -5696,7 +5662,7 @@ void TextEdit::_copy() {
return;
}
- int cl = cursor_get_line();
+ int cl = get_caret_line();
if (text[cl].length() != 0) {
String clipboard = _base_get_text(cl, 0, cl, text[cl].length());
DisplayServer::get_singleton()->clipboard_set(clipboard);
@@ -5715,15 +5681,41 @@ void TextEdit::_paste() {
if (is_selection_active()) {
delete_selection();
} else if (!cut_copy_line.is_empty() && cut_copy_line == clipboard) {
- cursor_set_column(0);
+ set_caret_column(0);
String ins = "\n";
clipboard += ins;
}
- insert_text_at_cursor(clipboard);
+ insert_text_at_caret(clipboard);
end_complex_operation();
}
+/* Caret */
+void TextEdit::_emit_caret_changed() {
+ emit_signal(SNAME("caret_changed"));
+ caret_pos_dirty = false;
+}
+
+void TextEdit::_reset_caret_blink_timer() {
+ if (!caret_blink_enabled) {
+ return;
+ }
+
+ draw_caret = true;
+ if (has_focus()) {
+ caret_blink_timer->stop();
+ caret_blink_timer->start();
+ update();
+ }
+}
+
+void TextEdit::_toggle_draw_caret() {
+ draw_caret = !draw_caret;
+ if (is_visible_in_tree() && has_focus() && window_has_focus) {
+ update();
+ }
+}
+
TextEdit::TextEdit() {
clear();
set_focus_mode(FOCUS_ALL);
@@ -5748,7 +5740,7 @@ TextEdit::TextEdit() {
add_child(caret_blink_timer);
caret_blink_timer->set_wait_time(0.65);
caret_blink_timer->connect("timeout", callable_mp(this, &TextEdit::_toggle_draw_caret));
- cursor_set_blink_enabled(false);
+ set_caret_blink_enabled(false);
idle_detect = memnew(Timer);
add_child(idle_detect);
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index eee0f72f18..816718a0a3 100644
--- a/scene/gui/text_edit.h
+++ b/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);