refactor: KeyMap::mapCommandKey to use ranged loop

This commit is contained in:
sithlord48 2025-07-25 11:46:29 -04:00 committed by Nick Bolton
parent db841f71bd
commit 7785c954d5

View file

@ -493,18 +493,16 @@ const KeyMap::KeyItem *KeyMap::mapCommandKey(
for (int32_t groupOffset = 0; groupOffset < numGroups; ++groupOffset) { for (int32_t groupOffset = 0; groupOffset < numGroups; ++groupOffset) {
const auto effectiveGroup = getEffectiveGroup(group, groupOffset); const auto effectiveGroup = getEffectiveGroup(group, groupOffset);
const KeyEntryList &entryList = keyGroupTable[effectiveGroup]; const KeyEntryList &entryList = keyGroupTable[effectiveGroup];
for (size_t i = 0; i < entryList.size(); ++i) { for (const auto &entry : entryList) {
if (entryList[i].size() != 1) { if (entry.size() != 1) {
// ignore multikey entries
continue; continue;
} }
// match based on shift and make sure all required modifiers, // match based on shift and make sure all required modifiers,
// except shift, are already in the desired mask; we're // except shift, are already in the desired mask; we're
// after the right button not the right character. // after the right button not the right character.
// we'll use desiredMask as-is, overriding the key's required // we'll use desiredMask as-is, overriding the key's required
// modifiers, when synthesizing this button. // modifiers, when synthesizing this button.
const KeyItem &item = entryList[i].back(); const auto &item = entry.back();
KeyModifierMask desiredShiftMask = KeyModifierShift & desiredMask; KeyModifierMask desiredShiftMask = KeyModifierShift & desiredMask;
KeyModifierMask requiredIgnoreShiftMask = item.m_required & ~KeyModifierShift; KeyModifierMask requiredIgnoreShiftMask = item.m_required & ~KeyModifierShift;
if ((item.m_required & desiredShiftMask) == (item.m_sensitive & desiredShiftMask) && if ((item.m_required & desiredShiftMask) == (item.m_sensitive & desiredShiftMask) &&
@ -514,11 +512,11 @@ const KeyMap::KeyItem *KeyMap::mapCommandKey(
break; break;
} }
} }
if (keyItem != nullptr) { if (keyItem) {
break; break;
} }
} }
if (keyItem == nullptr) { if (!keyItem) {
// no mapping for this keysym // no mapping for this keysym
LOG((CLOG_DEBUG1 "no mapping for key %04x", id)); LOG((CLOG_DEBUG1 "no mapping for key %04x", id));
return nullptr; return nullptr;