Merge pull request #3527 from myk002/myk_no_extra_keys

filter out spurious STRING keybindings
develop
Myk 2023-07-05 12:10:51 -07:00 committed by GitHub
commit 8e7d7fefc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 7 deletions

@ -36,6 +36,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## New Plugins
## Fixes
- Fix extra keys appearing in DFHack text boxes when shift (or any other modifier) is released before the other key you were pressing
## Misc Improvements

@ -2604,14 +2604,29 @@ static int screen_doSimulateInput(lua_State *L)
int sz = lua_rawlen(L, 2);
std::set<df::interface_key> keys;
char str = '\0';
for (int j = 1; j <= sz; j++)
{
lua_rawgeti(L, 2, j);
keys.insert((df::interface_key)lua_tointeger(L, -1));
df::interface_key k = (df::interface_key)lua_tointeger(L, -1);
if (!str && k > df::interface_key::STRING_A000 && k <= df::interface_key::STRING_A255)
str = Screen::keyToChar(k);
keys.insert(k);
lua_pop(L, 1);
}
// if we're injecting a text keybinding, ensure it is reflected in the enabler text buffer
std::string prev_input;
if (str) {
prev_input = (const char *)&df::global::enabler->last_text_input[0];
df::global::enabler->last_text_input[0] = str;
df::global::enabler->last_text_input[1] = '\0';
}
screen->feed(&keys);
if (str)
strcpy((char *)&df::global::enabler->last_text_input[0], prev_input.c_str());
return 0;
}

@ -229,8 +229,8 @@ namespace DFHack
DFHACK_EXPORT bool hasActiveScreens(Plugin *p);
DFHACK_EXPORT void raise(df::viewscreen *screen);
// returns a new set with text interface keys from the text buffer added in (if any)
DFHACK_EXPORT std::set<df::interface_key> add_text_keys(const std::set<df::interface_key>& keys);
// returns a new set of interface keys that ensures that string input matches the DF text buffer
DFHACK_EXPORT std::set<df::interface_key> normalize_text_keys(const std::set<df::interface_key>& keys);
/// Retrieve the string representation of the bound key.
DFHACK_EXPORT std::string getKeyDisplay(df::interface_key key);

@ -585,8 +585,10 @@ void Hide::merge() {
}
} }
std::set<df::interface_key> Screen::add_text_keys(const std::set<df::interface_key>& keys) {
std::set<df::interface_key> combined_keys(keys);
std::set<df::interface_key> Screen::normalize_text_keys(const std::set<df::interface_key>& keys) {
std::set<df::interface_key> combined_keys;
std::copy_if(keys.begin(), keys.end(), std::inserter(combined_keys, combined_keys.begin()),
[](df::interface_key k){ return k <= df::interface_key::STRING_A000 || k > df::interface_key::STRING_A255; } );
if (df::global::enabler->last_text_input[0]) {
char c = df::global::enabler->last_text_input[0];
df::interface_key key = charToKey(c);
@ -952,7 +954,7 @@ int dfhack_lua_viewscreen::do_input(lua_State *L)
}
lua_pushvalue(L, -2);
Lua::PushInterfaceKeys(L, Screen::add_text_keys(*keys));
Lua::PushInterfaceKeys(L, Screen::normalize_text_keys(*keys));
lua_call(L, 2, 0);
self->update_focus(L, -1);

@ -76,7 +76,7 @@ struct viewscreen_overlay : T {
[&](lua_State *L) {
Lua::Push(L, T::_identity.getName());
Lua::Push(L, this);
Lua::PushInterfaceKeys(L, Screen::add_text_keys(*input));
Lua::PushInterfaceKeys(L, Screen::normalize_text_keys(*input));
}, [&](lua_State *L) {
input_is_handled = lua_toboolean(L, -1);
});