From 2234ab781a45c7621a9dcc822e1acda06641be2b Mon Sep 17 00:00:00 2001 From: Eduard Bloch Date: Sun, 27 Oct 2024 09:03:48 +0100 Subject: [PATCH] Stop tooltip when space was typed in For #297 --- src/yinputline.cc | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/yinputline.cc b/src/yinputline.cc index e4df84edd..e15b17a41 100644 --- a/src/yinputline.cc +++ b/src/yinputline.cc @@ -26,6 +26,9 @@ struct tCandCollector { for (const auto &s : hits) { if (!all.empty()) all.append("\n"); + + // XXX: both match_string and candidates are supposed to contain + // strings under UTF-8 law?! all.append(s.substr(0, match_string.length()) + " " + s.substr(match_string.length())); } @@ -375,22 +378,27 @@ bool YInputLine::handleKey(const XKeyEvent &key) { auto str = YLocale::narrowString(s, len + 1, reglen); // printf("typed in: %s\n", str); if (str) { - auto wanted_pfx = - lastSeenCandidates->match_string + str; - delete[] str; - - for (auto it = lastSeenCandidates->hits.begin(); - it != lastSeenCandidates->hits.end();) { - - if (0 == it->compare(0, wanted_pfx.length(), - wanted_pfx.c_str())) - ++it; - else - it = lastSeenCandidates->hits.erase(it); + if (isspace((unsigned) *str)) { + setToolTip(null); + toolTipVisibility(false); + } else { + auto wanted_pfx = + lastSeenCandidates->match_string + str; + + for (auto it = lastSeenCandidates->hits.begin(); + it != lastSeenCandidates->hits.end();) { + + if (0 == it->compare(0, wanted_pfx.length(), + wanted_pfx.c_str())) { + ++it; + } else + it = lastSeenCandidates->hits.erase(it); + } + lastSeenCandidates->match_string = wanted_pfx; + auto ttext(lastSeenCandidates->join_candidates()); + setToolTip(mstring(ttext.data(), ttext.length())); } - lastSeenCandidates->match_string = wanted_pfx; - setToolTip( - lastSeenCandidates->join_candidates().c_str()); + delete[] str; } }