diff options
-rw-r--r-- | editor/plugins/animation_player_editor_plugin.cpp | 3 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 37 | ||||
-rw-r--r-- | scene/gui/line_edit.h | 2 |
3 files changed, 38 insertions, 4 deletions
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 80353bab01..718156f12a 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -85,6 +85,9 @@ void AnimationPlayerEditor::_notification(int p_what) { track_editor->set_anim_pos(player->get_current_animation_position()); EditorNode::get_singleton()->get_inspector()->refresh(); + } else if (!player->is_valid()) { + // Reset timeline when the player has been stopped externally + frame->set_value(0); } else if (last_active) { // Need the last frame after it stopped. frame->set_value(player->get_current_animation_position()); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index ab6f80bfa9..e6a27aa63f 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -823,7 +823,7 @@ void LineEdit::_notification(int p_what) { int yofs = y_ofs + (caret_height - font->get_height()) / 2; drawer.draw_char(ci, Point2(x_ofs, yofs + font_ascent), cchar, next, selected ? font_color_selected : font_color); - if (char_ofs == cursor_pos && draw_caret) { + if (char_ofs == cursor_pos && draw_caret && !using_placeholder) { if (ime_text.length() == 0) { #ifdef TOOLS_ENABLED VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color); @@ -866,12 +866,27 @@ void LineEdit::_notification(int p_what) { } } - if (char_ofs == cursor_pos && draw_caret) { // May be at the end. + if ((char_ofs == cursor_pos || using_placeholder) && draw_caret) { // May be at the end, or placeholder. if (ime_text.length() == 0) { + int caret_x_ofs = x_ofs; + if (using_placeholder) { + switch (align) { + case ALIGN_LEFT: + case ALIGN_FILL: { + caret_x_ofs = style->get_offset().x; + } break; + case ALIGN_CENTER: { + caret_x_ofs = ofs_max / 2; + } break; + case ALIGN_RIGHT: { + caret_x_ofs = ofs_max; + } break; + } + } #ifdef TOOLS_ENABLED - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color); #else - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(1, caret_height)), cursor_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(1, caret_height)), cursor_color); #endif } } @@ -970,6 +985,8 @@ void LineEdit::undo() { undo_stack_pos = undo_stack_pos->prev(); TextOperation op = undo_stack_pos->get(); text = op.text; + cached_width = op.cached_width; + window_pos = op.window_pos; set_cursor_position(op.cursor_pos); if (expand_to_text_length) @@ -988,6 +1005,8 @@ void LineEdit::redo() { undo_stack_pos = undo_stack_pos->next(); TextOperation op = undo_stack_pos->get(); text = op.text; + cached_width = op.cached_width; + window_pos = op.window_pos; set_cursor_position(op.cursor_pos); if (expand_to_text_length) @@ -1169,6 +1188,10 @@ void LineEdit::delete_char() { set_cursor_position(get_cursor_position() - 1); + if (align == ALIGN_CENTER || align == ALIGN_RIGHT) { + window_pos = CLAMP(window_pos - 1, 0, text.length() - 1); + } + _text_changed(); } @@ -1196,6 +1219,10 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) { window_pos = cursor_pos; } + if (align == ALIGN_CENTER || align == ALIGN_RIGHT) { + window_pos = CLAMP(window_pos - (p_to_column - p_from_column), 0, text.length() - 1); + } + if (!text_changed_dirty) { if (is_inside_tree()) { MessageQueue::get_singleton()->push_call(this, "_text_changed"); @@ -1677,7 +1704,9 @@ void LineEdit::_clear_undo_stack() { void LineEdit::_create_undo_state() { TextOperation op; op.text = text; + op.cached_width = cached_width; op.cursor_pos = cursor_pos; + op.window_pos = window_pos; undo_stack.push_back(op); } diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 3424131dad..ebe49091eb 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -106,6 +106,8 @@ private: struct TextOperation { int cursor_pos; + int window_pos; + int cached_width; String text; }; List<TextOperation> undo_stack; |