mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-21 09:27:59 +02:00
Better key chord matching
This commit is contained in:
parent
2e4792d51e
commit
5f5c752f5d
1 changed files with 87 additions and 67 deletions
|
@ -7429,82 +7429,102 @@ namespace IDE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var keyState = scope KeyState();
|
if ((mKeyChordState != null) && (evt.mKeyCode.IsModifier))
|
||||||
keyState.mKeyCode = evt.mKeyCode;
|
|
||||||
keyState.mKeyFlags = evt.mKeyFlags;
|
|
||||||
|
|
||||||
var curKeyMap = mCommands.mKeyMap;
|
|
||||||
bool hadChordState = mKeyChordState != null;
|
|
||||||
if (mKeyChordState != null)
|
|
||||||
curKeyMap = mKeyChordState.mCommandMap;
|
|
||||||
DeleteAndNullify!(mKeyChordState);
|
|
||||||
|
|
||||||
KeyState matchedKey;
|
|
||||||
IDECommandBase commandBase;
|
|
||||||
if (curKeyMap.mMap.TryGet(keyState, out matchedKey, out commandBase))
|
|
||||||
{
|
{
|
||||||
if (var commandMap = commandBase as CommandMap)
|
// Ignore
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var keyState = scope KeyState();
|
||||||
|
keyState.mKeyCode = evt.mKeyCode;
|
||||||
|
keyState.mKeyFlags = evt.mKeyFlags;
|
||||||
|
|
||||||
|
var curKeyMap = mCommands.mKeyMap;
|
||||||
|
|
||||||
|
bool hadChordState = mKeyChordState != null;
|
||||||
|
if (mKeyChordState != null)
|
||||||
|
curKeyMap = mKeyChordState.mCommandMap;
|
||||||
|
var prevKeyChordState = mKeyChordState;
|
||||||
|
defer delete prevKeyChordState;
|
||||||
|
mKeyChordState = null;
|
||||||
|
|
||||||
|
KeyState matchedKey;
|
||||||
|
IDECommandBase commandBase;
|
||||||
|
|
||||||
|
bool hadMatch = curKeyMap.mMap.TryGet(keyState, out matchedKey, out commandBase);
|
||||||
|
if ((!hadMatch) && (prevKeyChordState != null))
|
||||||
{
|
{
|
||||||
mKeyChordState = new .();
|
// If we have a "Ctrl+A, Ctrl+B" style sequence then also try to match that against "Ctrl+A, B"
|
||||||
mKeyChordState.mCommandMap = commandMap;
|
KeyState rawKeyState = keyState;
|
||||||
mKeyChordState.mKeyState = matchedKey;
|
rawKeyState.mKeyFlags &= ~prevKeyChordState.mKeyState.mKeyFlags;
|
||||||
evt.mHandled = true;
|
hadMatch = curKeyMap.mMap.TryGet(rawKeyState, out matchedKey, out commandBase);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (var command = commandBase as IDECommand)
|
|
||||||
|
if (hadMatch)
|
||||||
{
|
{
|
||||||
bool foundMatch = false;
|
if (var commandMap = commandBase as CommandMap)
|
||||||
if (useFlags != .None)
|
|
||||||
{
|
|
||||||
var checkCommand = command;
|
|
||||||
while (checkCommand != null)
|
|
||||||
{
|
|
||||||
bool matches = checkCommand.mContextFlags == .None;
|
|
||||||
if (checkCommand.mContextFlags.HasFlag(.Editor))
|
|
||||||
matches |= useFlags.HasFlag(.Editor);
|
|
||||||
if (checkCommand.mContextFlags.HasFlag(.MainWindow))
|
|
||||||
matches |= useFlags.HasFlag(.MainWindow);
|
|
||||||
if (checkCommand.mContextFlags.HasFlag(.WorkWindow))
|
|
||||||
matches |= useFlags.HasFlag(.WorkWindow);
|
|
||||||
|
|
||||||
if (matches)
|
|
||||||
{
|
|
||||||
checkCommand.mAction();
|
|
||||||
foundMatch = true;
|
|
||||||
}
|
|
||||||
checkCommand = checkCommand.mNext;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!foundMatch)
|
|
||||||
{
|
|
||||||
var checkCommand = command;
|
|
||||||
while (checkCommand != null)
|
|
||||||
{
|
|
||||||
if (checkCommand.mContextFlags == .None)
|
|
||||||
{
|
|
||||||
checkCommand.mAction();
|
|
||||||
foundMatch = true;
|
|
||||||
}
|
|
||||||
checkCommand = checkCommand.mNext;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundMatch)
|
|
||||||
{
|
{
|
||||||
|
mKeyChordState = new .();
|
||||||
|
mKeyChordState.mCommandMap = commandMap;
|
||||||
|
mKeyChordState.mKeyState = matchedKey;
|
||||||
evt.mHandled = true;
|
evt.mHandled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (var command = commandBase as IDECommand)
|
||||||
|
{
|
||||||
|
bool foundMatch = false;
|
||||||
|
if (useFlags != .None)
|
||||||
|
{
|
||||||
|
var checkCommand = command;
|
||||||
|
while (checkCommand != null)
|
||||||
|
{
|
||||||
|
bool matches = checkCommand.mContextFlags == .None;
|
||||||
|
if (checkCommand.mContextFlags.HasFlag(.Editor))
|
||||||
|
matches |= useFlags.HasFlag(.Editor);
|
||||||
|
if (checkCommand.mContextFlags.HasFlag(.MainWindow))
|
||||||
|
matches |= useFlags.HasFlag(.MainWindow);
|
||||||
|
if (checkCommand.mContextFlags.HasFlag(.WorkWindow))
|
||||||
|
matches |= useFlags.HasFlag(.WorkWindow);
|
||||||
|
|
||||||
|
if (matches)
|
||||||
|
{
|
||||||
|
checkCommand.mAction();
|
||||||
|
foundMatch = true;
|
||||||
|
}
|
||||||
|
checkCommand = checkCommand.mNext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundMatch)
|
||||||
|
{
|
||||||
|
var checkCommand = command;
|
||||||
|
while (checkCommand != null)
|
||||||
|
{
|
||||||
|
if (checkCommand.mContextFlags == .None)
|
||||||
|
{
|
||||||
|
checkCommand.mAction();
|
||||||
|
foundMatch = true;
|
||||||
|
}
|
||||||
|
checkCommand = checkCommand.mNext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundMatch)
|
||||||
|
{
|
||||||
|
evt.mHandled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else if (!evt.mKeyCode.IsModifier)
|
|
||||||
{
|
|
||||||
// Not found
|
|
||||||
if (hadChordState)
|
|
||||||
{
|
{
|
||||||
Beep(.Error);
|
// Not found
|
||||||
evt.mHandled = true;
|
if (hadChordState)
|
||||||
return;
|
{
|
||||||
|
Beep(.Error);
|
||||||
|
evt.mHandled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue