Fix TextEdit::gutters_width (total gutter width) when adding & removing a gutter by calling TextEdit::_update_gutter_width in TextEdit::add_gutter & TextEdit::remove_gutter

Update TextEdit gutters subcase, gutter add and remove to ensure gutter total width is correct

Fix test_code_edit symbol lookup test case to include padding (+2)
This commit is contained in:
Tim Fronsee 2022-08-26 19:00:14 +09:00
parent 6e390fa9ab
commit e5c183b01e
3 changed files with 19 additions and 7 deletions

View File

@ -4786,6 +4786,9 @@ void TextEdit::add_gutter(int p_at) {
}
text.add_gutter(p_at);
_update_gutter_width();
emit_signal(SNAME("gutter_added"));
update();
}
@ -4796,6 +4799,9 @@ void TextEdit::remove_gutter(int p_gutter) {
gutters.remove_at(p_gutter);
text.remove_gutter(p_gutter);
_update_gutter_width();
emit_signal(SNAME("gutter_removed"));
update();
}

View File

@ -3245,7 +3245,7 @@ TEST_CASE("[SceneTree][CodeEdit] symbol lookup") {
code_edit->set_text("this is some text");
Point2 caret_pos = code_edit->get_caret_draw_pos();
caret_pos.x += 58;
caret_pos.x += 60;
SEND_GUI_MOUSE_BUTTON_EVENT(code_edit, caret_pos, MouseButton::NONE, MouseButton::NONE, Key::NONE);
CHECK(code_edit->get_text_for_symbol_lookup() == "this is s" + String::chr(0xFFFF) + "ome text");

View File

@ -3388,6 +3388,8 @@ TEST_CASE("[SceneTree][TextEdit] gutters") {
SUBCASE("[TextEdit] gutter add and remove") {
text_edit->add_gutter();
CHECK(text_edit->get_gutter_count() == 1);
CHECK(text_edit->get_gutter_width(0) == 24);
CHECK(text_edit->get_total_gutter_width() == 24 + 2);
SIGNAL_CHECK("gutter_added", empty_signal_args);
text_edit->set_gutter_name(0, "test_gutter");
@ -3395,39 +3397,43 @@ TEST_CASE("[SceneTree][TextEdit] gutters") {
text_edit->set_gutter_width(0, 10);
CHECK(text_edit->get_gutter_width(0) == 10);
CHECK(text_edit->get_total_gutter_width() > 10);
CHECK(text_edit->get_total_gutter_width() < 20);
CHECK(text_edit->get_total_gutter_width() == 10 + 2);
text_edit->add_gutter(-100);
text_edit->set_gutter_width(1, 10);
CHECK(text_edit->get_total_gutter_width() > 20);
CHECK(text_edit->get_total_gutter_width() < 30);
CHECK(text_edit->get_gutter_width(1) == 10);
CHECK(text_edit->get_total_gutter_width() == 20 + 2);
CHECK(text_edit->get_gutter_count() == 2);
CHECK(text_edit->get_gutter_name(0) == "test_gutter");
SIGNAL_CHECK("gutter_added", empty_signal_args);
text_edit->set_gutter_draw(1, false);
CHECK(text_edit->get_total_gutter_width() > 10);
CHECK(text_edit->get_total_gutter_width() < 20);
CHECK(text_edit->get_total_gutter_width() == 10 + 2);
text_edit->add_gutter(100);
CHECK(text_edit->get_gutter_count() == 3);
CHECK(text_edit->get_gutter_width(2) == 24);
CHECK(text_edit->get_total_gutter_width() == 34 + 2);
CHECK(text_edit->get_gutter_name(0) == "test_gutter");
SIGNAL_CHECK("gutter_added", empty_signal_args);
text_edit->add_gutter(0);
CHECK(text_edit->get_gutter_count() == 4);
CHECK(text_edit->get_gutter_width(0) == 24);
CHECK(text_edit->get_total_gutter_width() == 58 + 2);
CHECK(text_edit->get_gutter_name(1) == "test_gutter");
SIGNAL_CHECK("gutter_added", empty_signal_args);
text_edit->remove_gutter(2);
CHECK(text_edit->get_gutter_name(1) == "test_gutter");
CHECK(text_edit->get_gutter_count() == 3);
CHECK(text_edit->get_total_gutter_width() == 58 + 2);
SIGNAL_CHECK("gutter_removed", empty_signal_args);
text_edit->remove_gutter(0);
CHECK(text_edit->get_gutter_name(0) == "test_gutter");
CHECK(text_edit->get_gutter_count() == 2);
CHECK(text_edit->get_total_gutter_width() == 34 + 2);
SIGNAL_CHECK("gutter_removed", empty_signal_args);
ERR_PRINT_OFF;