key remapping: don't remap space in options dialog

The options dialog never accepts space, so remapping a key to it doesn't make sense, and it is possible the original key was one of the keys actually being listened for
This commit is contained in:
Adam
2020-10-28 16:05:48 -04:00
parent c4f019aff0
commit d3c0713969
3 changed files with 26 additions and 1 deletions

View File

@@ -155,7 +155,9 @@ class KeyRemappingListener implements KeyListener
}
}
if (plugin.isDialogOpen() && config.space().matches(e))
// Do not remap to space key when the options dialog is open, since the options dialog never
// listens for space, and the remapped key may be one of keys it listens for.
if (plugin.isDialogOpen() && !plugin.isOptionsDialogOpen() && config.space().matches(e))
{
mappedKeyCode = KeyEvent.VK_SPACE;
}

View File

@@ -144,6 +144,11 @@ public class KeyRemappingPlugin extends Plugin
|| !isHidden(WidgetInfo.BANK_PIN_CONTAINER);
}
boolean isOptionsDialogOpen()
{
return client.getWidget(WidgetInfo.DIALOG_OPTION) != null;
}
private boolean isHidden(WidgetInfo widgetInfo)
{
Widget w = client.getWidget(widgetInfo);

View File

@@ -105,4 +105,22 @@ public class KeyRemappingListenerTest
verify(event).setKeyCode(KeyEvent.VK_RIGHT);
verify(event).setKeyChar(KeyEvent.CHAR_UNDEFINED);
}
@Test
public void testSpaceRemap()
{
when(keyRemappingConfig.space()).thenReturn(new ModifierlessKeybind(KeyEvent.VK_NUMPAD1, 0));
when(keyRemappingPlugin.chatboxFocused()).thenReturn(true);
when(keyRemappingPlugin.isDialogOpen()).thenReturn(true);
KeyEvent event = mock(KeyEvent.class);
when(event.getKeyChar()).thenReturn('1');
when(event.getKeyCode()).thenReturn(KeyEvent.VK_NUMPAD1);
when(event.getExtendedKeyCode()).thenReturn(KeyEvent.VK_NUMPAD1); // for keybind matches()
keyRemappingListener.keyPressed(event);
verify(event).setKeyCode(KeyEvent.VK_SPACE);
}
}