From 4ba3df70823ab648595592e77785466aab235d67 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 5 Jul 2021 17:37:48 +0200 Subject: [PATCH] pgui: Fix missing cursor when typing candidate --- panda/src/pgui/pgEntry.cxx | 20 ++++++++++++++------ panda/src/pgui/pgEntry.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/panda/src/pgui/pgEntry.cxx b/panda/src/pgui/pgEntry.cxx index ee8e05b30b..d3fcad98fc 100644 --- a/panda/src/pgui/pgEntry.cxx +++ b/panda/src/pgui/pgEntry.cxx @@ -41,7 +41,8 @@ PGEntry:: PGEntry(const string &name) : PGItem(name), _text(get_text_node()), - _obscure_text(get_text_node()) + _obscure_text(get_text_node()), + _candidate_text(get_text_node()) { set_cull_callback(); @@ -103,6 +104,7 @@ PGEntry(const PGEntry ©) : PGItem(copy), _text(copy._text), _obscure_text(copy._obscure_text), + _candidate_text(copy._candidate_text), _cursor_position(copy._cursor_position), _cursor_visible(copy._cursor_visible), _candidate_highlight_start(copy._candidate_highlight_start), @@ -813,9 +815,9 @@ update_text() { cseq += wstring(1, (wchar_t)text_pop_properties_key); // Create a special TextAssembler to insert the candidate string. - TextAssembler ctext(_text); - ctext.set_wsubstr(cseq, _cursor_position, 0); - assembled = ctext.assemble_text(); + _candidate_text = _text; + _candidate_text.set_wsubstr(cseq, _cursor_position, 0); + assembled = _candidate_text.assemble_text(); } if (!_current_text.is_empty()) { @@ -897,7 +899,8 @@ update_cursor() { _obscure_text.calc_r_c(row, column, _cursor_position); xpos = _obscure_text.get_xpos(row, column); ypos = _obscure_text.get_ypos(row, column); - } else { + } + else if (_candidate_wtext.empty()) { _text.calc_r_c(row, column, _cursor_position); if (_cursor_position > 0 && _text.get_character(_cursor_position - 1) == '\n') { row += 1; @@ -906,6 +909,11 @@ update_cursor() { xpos = _text.get_xpos(row, column); ypos = _text.get_ypos(row, column); } + else { + _candidate_text.calc_r_c(row, column, _cursor_position + (int)_candidate_cursor_pos); + xpos = _candidate_text.get_xpos(row, column); + ypos = _candidate_text.get_ypos(row, column); + } _cursor_def.set_pos(xpos - _current_padding, 0.0f, ypos); _cursor_stale = false; @@ -914,7 +922,7 @@ update_cursor() { } // Should the cursor be visible? - if (!get_focus() || !_candidate_wtext.empty()) { + if (!get_focus()) { show_hide_cursor(false); } else { double elapsed_time = diff --git a/panda/src/pgui/pgEntry.h b/panda/src/pgui/pgEntry.h index 45548c8b12..a12c4cc70b 100644 --- a/panda/src/pgui/pgEntry.h +++ b/panda/src/pgui/pgEntry.h @@ -149,6 +149,7 @@ private: TextAssembler _text; TextAssembler _obscure_text; + TextAssembler _candidate_text; int _cursor_position; bool _cursor_stale; bool _cursor_visible;