diff options
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r-- | scene/gui/text_edit.cpp | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index cd1450b879..540c999131 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -33,7 +33,6 @@ #include "core/config/project_settings.h" #include "core/input/input.h" #include "core/input/input_map.h" -#include "core/object/message_queue.h" #include "core/object/script_language.h" #include "core/os/keyboard.h" #include "core/os/os.h" @@ -428,10 +427,10 @@ void TextEdit::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { _update_caches(); if (caret_pos_dirty) { - MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed"); + callable_mp(this, &TextEdit::_emit_caret_changed).call_deferred(); } if (text_changed_dirty) { - MessageQueue::get_singleton()->push_call(this, "_text_changed_emit"); + callable_mp(this, &TextEdit::_text_changed_emit).call_deferred(); } _update_wrap_at_column(true); } break; @@ -443,8 +442,8 @@ void TextEdit::_notification(int p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { if (is_visible()) { - call_deferred(SNAME("_update_scrollbars")); - call_deferred(SNAME("_update_wrap_at_column")); + callable_mp(this, &TextEdit::_update_scrollbars).call_deferred(); + callable_mp(this, &TextEdit::_update_wrap_at_column).call_deferred(false); } } break; @@ -989,18 +988,6 @@ void TextEdit::_notification(int p_what) { RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs_x, ofs_y, xmargin_end, row_height), theme_cache.current_line_color); } } - - // Give visual indication of empty selected line. - for (int c = 0; c < carets.size(); c++) { - if (has_selection(c) && line >= get_selection_from_line(c) && line <= get_selection_to_line(c) && char_margin >= xmargin_beg) { - float char_w = theme_cache.font->get_char_size(' ', theme_cache.font_size).width; - if (rtl) { - RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - xmargin_beg - ofs_x - char_w, ofs_y, char_w, row_height), theme_cache.selection_color); - } else { - RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, char_w, row_height), theme_cache.selection_color); - } - } - } } 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 (caret_line_wrap_index_map.has(line) && caret_line_wrap_index_map[line].has(line_wrap_index) && highlight_current_line) { @@ -1093,13 +1080,26 @@ void TextEdit::_notification(int p_what) { char_margin = size.width - char_margin - TS->shaped_text_get_size(rid).x; } + // Draw selections. + float char_w = theme_cache.font->get_char_size(' ', theme_cache.font_size).width; for (int c = 0; c < carets.size(); c++) { - if (!clipped && has_selection(c) && line >= get_selection_from_line(c) && line <= get_selection_to_line(c)) { // Selection + if (!clipped && has_selection(c) && line >= get_selection_from_line(c) && line <= get_selection_to_line(c)) { int sel_from = (line > get_selection_from_line(c)) ? TS->shaped_text_get_range(rid).x : get_selection_from_column(c); int sel_to = (line < get_selection_to_line(c)) ? TS->shaped_text_get_range(rid).y : get_selection_to_column(c); Vector<Vector2> sel = TS->shaped_text_get_selection(rid, sel_from, sel_to); + + // Show selection at the end of line. + if (line < get_selection_to_line(c)) { + if (rtl) { + sel.push_back(Vector2(-char_w, 0)); + } else { + float line_end = TS->shaped_text_get_size(rid).width; + sel.push_back(Vector2(line_end, line_end + char_w)); + } + } + 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, row_height); + Rect2 rect = Rect2(sel[j].x + char_margin + ofs_x, ofs_y, Math::ceil(sel[j].y - sel[j].x), row_height); if (rect.position.x + rect.size.x <= xmargin_beg || rect.position.x > xmargin_end) { continue; } @@ -4007,7 +4007,7 @@ void TextEdit::undo() { if (dirty_carets && !caret_pos_dirty) { if (is_inside_tree()) { - MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed"); + callable_mp(this, &TextEdit::_emit_caret_changed).call_deferred(); } caret_pos_dirty = true; } @@ -4062,7 +4062,7 @@ void TextEdit::redo() { if (dirty_carets && !caret_pos_dirty) { if (is_inside_tree()) { - MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed"); + callable_mp(this, &TextEdit::_emit_caret_changed).call_deferred(); } caret_pos_dirty = true; } @@ -4868,7 +4868,7 @@ void TextEdit::set_caret_line(int p_line, bool p_adjust_viewport, bool p_can_be_ if (caret_moved && !caret_pos_dirty) { if (is_inside_tree()) { - MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed"); + callable_mp(this, &TextEdit::_emit_caret_changed).call_deferred(); } caret_pos_dirty = true; } @@ -4899,7 +4899,7 @@ void TextEdit::set_caret_column(int p_col, bool p_adjust_viewport, int p_caret) if (caret_moved && !caret_pos_dirty) { if (is_inside_tree()) { - MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed"); + callable_mp(this, &TextEdit::_emit_caret_changed).call_deferred(); } caret_pos_dirty = true; } @@ -6026,10 +6026,6 @@ Color TextEdit::get_font_color() const { } void TextEdit::_bind_methods() { - /* Internal. */ - - ClassDB::bind_method(D_METHOD("_text_changed_emit"), &TextEdit::_text_changed_emit); - /* Text */ // Text properties ClassDB::bind_method(D_METHOD("has_ime_text"), &TextEdit::has_ime_text); @@ -6200,9 +6196,6 @@ void TextEdit::_bind_methods() { 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); @@ -6290,9 +6283,6 @@ void TextEdit::_bind_methods() { BIND_ENUM_CONSTANT(LINE_WRAPPING_NONE); BIND_ENUM_CONSTANT(LINE_WRAPPING_BOUNDARY); - // Internal. - ClassDB::bind_method(D_METHOD("_update_wrap_at_column", "force"), &TextEdit::_update_wrap_at_column, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("set_line_wrapping_mode", "mode"), &TextEdit::set_line_wrapping_mode); ClassDB::bind_method(D_METHOD("get_line_wrapping_mode"), &TextEdit::get_line_wrapping_mode); @@ -7826,7 +7816,7 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i if (!text_changed_dirty && !setting_text) { if (is_inside_tree()) { - MessageQueue::get_singleton()->push_call(this, "_text_changed_emit"); + callable_mp(this, &TextEdit::_text_changed_emit).call_deferred(); } text_changed_dirty = true; } @@ -7872,7 +7862,7 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li if (!text_changed_dirty && !setting_text) { if (is_inside_tree()) { - MessageQueue::get_singleton()->push_call(this, "_text_changed_emit"); + callable_mp(this, &TextEdit::_text_changed_emit).call_deferred(); } text_changed_dirty = true; } |