Fix select word under caret using caret col instead of line
This commit is contained in:
parent
042e81f663
commit
f3eb543e67
2 changed files with 69 additions and 24 deletions
|
@ -4825,10 +4825,11 @@ void TextEdit::select_word_under_caret(int p_caret) {
|
|||
continue;
|
||||
}
|
||||
|
||||
select(get_caret_line(c), begin, get_caret_column(c), end, c);
|
||||
select(get_caret_line(c), begin, get_caret_line(c), end, c);
|
||||
// Move the caret to the end of the word for easier editing.
|
||||
set_caret_column(end, false, c);
|
||||
}
|
||||
merge_overlapping_carets();
|
||||
}
|
||||
|
||||
void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_to_column, int p_caret) {
|
||||
|
|
|
@ -637,17 +637,42 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
|
|||
}
|
||||
|
||||
SUBCASE("[TextEdit] select word under caret") {
|
||||
text_edit->set_text("test test");
|
||||
text_edit->set_text("\ntest test\ntest test");
|
||||
|
||||
text_edit->set_caret_column(0);
|
||||
text_edit->set_caret_line(1);
|
||||
|
||||
text_edit->add_caret(2, 0);
|
||||
text_edit->add_caret(2, 2);
|
||||
CHECK(text_edit->get_caret_count() == 3);
|
||||
|
||||
MessageQueue::get_singleton()->flush();
|
||||
|
||||
SIGNAL_DISCARD("text_set");
|
||||
SIGNAL_DISCARD("text_changed");
|
||||
SIGNAL_DISCARD("lines_edited_from");
|
||||
SIGNAL_DISCARD("caret_changed");
|
||||
|
||||
text_edit->select_word_under_caret();
|
||||
CHECK(text_edit->get_selected_text() == "test");
|
||||
CHECK(text_edit->has_selection());
|
||||
CHECK(text_edit->get_selection_from_line() == 0);
|
||||
CHECK(text_edit->get_selection_from_column() == 0);
|
||||
CHECK(text_edit->get_selection_to_line() == 0);
|
||||
CHECK(text_edit->get_selection_to_column() == 4);
|
||||
CHECK(text_edit->get_caret_line() == 0);
|
||||
CHECK(text_edit->get_caret_column() == 4);
|
||||
CHECK(text_edit->has_selection(0));
|
||||
CHECK(text_edit->get_selected_text(0) == "test");
|
||||
CHECK(text_edit->get_selection_from_line(0) == 1);
|
||||
CHECK(text_edit->get_selection_from_column(0) == 0);
|
||||
CHECK(text_edit->get_selection_to_line(0) == 1);
|
||||
CHECK(text_edit->get_selection_to_column(0) == 4);
|
||||
CHECK(text_edit->get_caret_line(0) == 1);
|
||||
CHECK(text_edit->get_caret_column(0) == 4);
|
||||
|
||||
CHECK(text_edit->has_selection(1));
|
||||
CHECK(text_edit->get_selected_text(1) == "test");
|
||||
CHECK(text_edit->get_selection_from_line(1) == 2);
|
||||
CHECK(text_edit->get_selection_from_column(1) == 0);
|
||||
CHECK(text_edit->get_selection_to_line(1) == 2);
|
||||
CHECK(text_edit->get_selection_to_column(1) == 4);
|
||||
CHECK(text_edit->get_caret_line(1) == 2);
|
||||
CHECK(text_edit->get_caret_column(1) == 4);
|
||||
|
||||
CHECK(text_edit->get_caret_count() == 2);
|
||||
|
||||
text_edit->select_word_under_caret();
|
||||
CHECK_FALSE(text_edit->has_selection());
|
||||
|
@ -656,27 +681,44 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
|
|||
SEND_GUI_ACTION(text_edit, "ui_text_select_word_under_caret");
|
||||
CHECK(text_edit->get_viewport()->is_input_handled());
|
||||
MessageQueue::get_singleton()->flush();
|
||||
CHECK(text_edit->has_selection());
|
||||
CHECK(text_edit->get_selected_text() == "test");
|
||||
CHECK(text_edit->get_selection_from_line() == 0);
|
||||
CHECK(text_edit->get_selection_from_column() == 0);
|
||||
CHECK(text_edit->get_selection_to_line() == 0);
|
||||
CHECK(text_edit->get_selection_to_column() == 4);
|
||||
CHECK(text_edit->get_caret_line() == 0);
|
||||
CHECK(text_edit->get_caret_column() == 4);
|
||||
CHECK(text_edit->has_selection(0));
|
||||
CHECK(text_edit->get_selected_text(0) == "test");
|
||||
CHECK(text_edit->get_selection_from_line(0) == 1);
|
||||
CHECK(text_edit->get_selection_from_column(0) == 0);
|
||||
CHECK(text_edit->get_selection_to_line(0) == 1);
|
||||
CHECK(text_edit->get_selection_to_column(0) == 4);
|
||||
CHECK(text_edit->get_caret_line(0) == 1);
|
||||
CHECK(text_edit->get_caret_column(0) == 4);
|
||||
|
||||
CHECK(text_edit->has_selection(1));
|
||||
CHECK(text_edit->get_selected_text(1) == "test");
|
||||
CHECK(text_edit->get_selection_from_line(1) == 2);
|
||||
CHECK(text_edit->get_selection_from_column(1) == 0);
|
||||
CHECK(text_edit->get_selection_to_line(1) == 2);
|
||||
CHECK(text_edit->get_selection_to_column(1) == 4);
|
||||
CHECK(text_edit->get_caret_line(1) == 2);
|
||||
CHECK(text_edit->get_caret_column(1) == 4);
|
||||
|
||||
CHECK(text_edit->get_selected_text() == "test\ntest");
|
||||
SIGNAL_CHECK("caret_changed", empty_signal_args);
|
||||
|
||||
text_edit->set_selecting_enabled(false);
|
||||
text_edit->select_word_under_caret();
|
||||
CHECK_FALSE(text_edit->has_selection());
|
||||
CHECK(text_edit->get_selected_text() == "");
|
||||
CHECK(text_edit->get_caret_line() == 0);
|
||||
CHECK(text_edit->get_caret_column() == 4);
|
||||
CHECK(text_edit->get_caret_line(0) == 1);
|
||||
CHECK(text_edit->get_caret_column(0) == 4);
|
||||
CHECK(text_edit->get_caret_line(1) == 2);
|
||||
CHECK(text_edit->get_caret_column(1) == 4);
|
||||
SIGNAL_CHECK_FALSE("caret_changed");
|
||||
text_edit->set_selecting_enabled(true);
|
||||
|
||||
text_edit->set_caret_line(0);
|
||||
text_edit->set_caret_column(5);
|
||||
text_edit->set_caret_line(1, false, true, 0, 0);
|
||||
text_edit->set_caret_column(5, false, 0);
|
||||
|
||||
text_edit->set_caret_line(2, false, true, 0, 1);
|
||||
text_edit->set_caret_column(5, false, 1);
|
||||
|
||||
text_edit->select_word_under_caret();
|
||||
CHECK_FALSE(text_edit->has_selection());
|
||||
CHECK(text_edit->get_selected_text() == "");
|
||||
|
@ -684,8 +726,10 @@ TEST_CASE("[SceneTree][TextEdit] text entry") {
|
|||
text_edit->select_word_under_caret();
|
||||
CHECK_FALSE(text_edit->has_selection());
|
||||
CHECK(text_edit->get_selected_text() == "");
|
||||
CHECK(text_edit->get_caret_line() == 0);
|
||||
CHECK(text_edit->get_caret_column() == 5);
|
||||
CHECK(text_edit->get_caret_line(0) == 1);
|
||||
CHECK(text_edit->get_caret_column(0) == 5);
|
||||
CHECK(text_edit->get_caret_line(1) == 2);
|
||||
CHECK(text_edit->get_caret_column(1) == 5);
|
||||
SIGNAL_CHECK_FALSE("caret_changed");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue