Skip to content

Commit

Permalink
TextEdit & LineEdit caret blink timers run only when focused (fixes g…
Browse files Browse the repository at this point in the history
  • Loading branch information
pouleyKetchoupp committed Sep 4, 2019
1 parent 750f8d4 commit 5fdea32
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
28 changes: 20 additions & 8 deletions scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,9 @@ void LineEdit::_notification(int p_what) {
} break;
case NOTIFICATION_FOCUS_ENTER: {

if (!caret_blink_enabled) {
if (caret_blink_enabled) {
caret_blink_timer->start();
} else {
draw_caret = true;
}

Expand All @@ -886,6 +888,10 @@ void LineEdit::_notification(int p_what) {
} break;
case NOTIFICATION_FOCUS_EXIT: {

if (caret_blink_enabled) {
caret_blink_timer->stop();
}

OS::get_singleton()->set_ime_position(Point2());
OS::get_singleton()->set_ime_active(false);
ime_text = "";
Expand Down Expand Up @@ -1053,11 +1059,15 @@ bool LineEdit::cursor_get_blink_enabled() const {

void LineEdit::cursor_set_blink_enabled(const bool p_enabled) {
caret_blink_enabled = p_enabled;
if (p_enabled) {
caret_blink_timer->start();
} else {
caret_blink_timer->stop();

if (has_focus()) {
if (p_enabled) {
caret_blink_timer->start();
} else {
caret_blink_timer->stop();
}
}

draw_caret = true;
}

Expand All @@ -1072,10 +1082,12 @@ void LineEdit::cursor_set_blink_speed(const float p_speed) {

void LineEdit::_reset_caret_blink_timer() {
if (caret_blink_enabled) {
caret_blink_timer->stop();
caret_blink_timer->start();
draw_caret = true;
update();
if (has_focus()) {
caret_blink_timer->stop();
caret_blink_timer->start();
update();
}
}
}

Expand Down
27 changes: 19 additions & 8 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,9 @@ void TextEdit::_notification(int p_what) {
} break;
case NOTIFICATION_FOCUS_ENTER: {

if (!caret_blink_enabled) {
if (caret_blink_enabled) {
caret_blink_timer->start();
} else {
draw_caret = true;
}

Expand All @@ -1751,6 +1753,10 @@ void TextEdit::_notification(int p_what) {
} break;
case NOTIFICATION_FOCUS_EXIT: {

if (caret_blink_enabled) {
caret_blink_timer->stop();
}

OS::get_singleton()->set_ime_position(Point2());
OS::get_singleton()->set_ime_active(false);
ime_text = "";
Expand Down Expand Up @@ -4396,11 +4402,14 @@ bool TextEdit::cursor_get_blink_enabled() const {
void TextEdit::cursor_set_blink_enabled(const bool p_enabled) {
caret_blink_enabled = p_enabled;

if (p_enabled) {
caret_blink_timer->start();
} else {
caret_blink_timer->stop();
if (has_focus()) {
if (p_enabled) {
caret_blink_timer->start();
} else {
caret_blink_timer->stop();
}
}

draw_caret = true;
}

Expand Down Expand Up @@ -4817,10 +4826,12 @@ int TextEdit::get_max_chars() const {

void TextEdit::_reset_caret_blink_timer() {
if (caret_blink_enabled) {
caret_blink_timer->stop();
caret_blink_timer->start();
draw_caret = true;
update();
if (has_focus()) {
caret_blink_timer->stop();
caret_blink_timer->start();
update();
}
}
}

Expand Down

0 comments on commit 5fdea32

Please sign in to comment.