fix github issue #400 - Qt text windows hanging

Text windows only accept a few keys (<escape>, <return>, ':', now
<space>) and if they got other keys they passed those up the call
chain, arriving at the map where they were treated as commands
and were executed while the text window was still displayed.  The
cited example was ',' for pickup while the "things that are here"
popup was shown.  The 'foreign' key's command might be executed
successfully but the undismissed popup could become hung.

This fixes that ('foreign' keys will be ignored).  It also lets
<space> be used to dismiss text windows.

Slightly better but far from perfect:  if you perform a search,
then after it runs you need to type <escape> once, or <return>
or <space> twice, or else search again and pick [done] on the
search popup and then <return> or <space> once, to dismiss a
text window via keyboard.  (Prior to this, typing <escape> or
searching again and picking [done] followed by <return> were the
only ways.)  Also, searching for an empty string will now be
treated as if [done] had been picked.

Fixes #400
This commit is contained in:
PatR
2021-01-14 15:10:41 -08:00
parent c131e6df18
commit 648162b536
2 changed files with 11 additions and 4 deletions

View File

@@ -1175,7 +1175,7 @@ void NetHackQtTextWindow::Search()
this->raise();
}
if (get_a_line) {
if (get_a_line && target[0]) {
int linecount = lines->count();
int current = lines->currentRow();
if (current == -1)
@@ -1215,13 +1215,16 @@ void NetHackQtTextWindow::keyPressEvent(QKeyEvent *key_event)
if (key == MENU_SEARCH) {
if (!use_rip)
Search();
} else if (key == '\n' || key == '\r') {
} else if (key == '\n' || key == '\r' || key == ' ') {
if (!textsearching)
accept();
else
textsearching = FALSE;
} else if (key == '\033') {
reject();
} else {
QDialog::keyPressEvent(key_event);
// ignore the current key instead of passing it along
//- QDialog::keyPressEvent(key_event);
}
}