filter out spurious STRING keybindings

that don't match actual SDL string input
develop
Myk Taylor 2023-07-03 09:09:52 -07:00
parent b5fd877b84
commit fdf2430fc4
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
4 changed files with 9 additions and 6 deletions

@ -36,6 +36,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## New Plugins ## New Plugins
## Fixes ## 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 ## Misc Improvements

@ -229,8 +229,8 @@ namespace DFHack
DFHACK_EXPORT bool hasActiveScreens(Plugin *p); DFHACK_EXPORT bool hasActiveScreens(Plugin *p);
DFHACK_EXPORT void raise(df::viewscreen *screen); DFHACK_EXPORT void raise(df::viewscreen *screen);
// returns a new set with text interface keys from the text buffer added in (if any) // returns a new set of interface keys that ensures that string input matches the DF text buffer
DFHACK_EXPORT std::set<df::interface_key> add_text_keys(const std::set<df::interface_key>& keys); 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. /// Retrieve the string representation of the bound key.
DFHACK_EXPORT std::string getKeyDisplay(df::interface_key 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> Screen::normalize_text_keys(const std::set<df::interface_key>& keys) {
std::set<df::interface_key> combined_keys(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]) { if (df::global::enabler->last_text_input[0]) {
char c = df::global::enabler->last_text_input[0]; char c = df::global::enabler->last_text_input[0];
df::interface_key key = charToKey(c); df::interface_key key = charToKey(c);
@ -952,7 +954,7 @@ int dfhack_lua_viewscreen::do_input(lua_State *L)
} }
lua_pushvalue(L, -2); 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); lua_call(L, 2, 0);
self->update_focus(L, -1); self->update_focus(L, -1);

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