Add some hotkeys for OSX (cmd + arrow_keys, ctrl + k, and ctrl + d)
This commit is contained in:
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
protected virtual string GetApparentText() { return text; }
|
protected virtual string GetApparentText() { return text; }
|
||||||
|
|
||||||
public int ClosestCursorPosition(int x)
|
int ClosestCursorPosition(int x)
|
||||||
{
|
{
|
||||||
var apparentText = GetApparentText();
|
var apparentText = GetApparentText();
|
||||||
var font = Game.Renderer.Fonts[Font];
|
var font = Game.Renderer.Fonts[Font];
|
||||||
@@ -111,6 +111,23 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return minIndex;
|
return minIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GetPrevWhitespaceIndex()
|
||||||
|
{
|
||||||
|
return Text.Substring(0, CursorPosition).TrimEnd().LastIndexOf(' ') + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetNextWhitespaceIndex()
|
||||||
|
{
|
||||||
|
var substr = Text.Substring(CursorPosition);
|
||||||
|
var substrTrimmed = substr.TrimStart();
|
||||||
|
var trimmedSpaces = substr.Length - substrTrimmed.Length;
|
||||||
|
var nextWhitespace = substrTrimmed.IndexOf(' ');
|
||||||
|
if (nextWhitespace == -1)
|
||||||
|
return Text.Length;
|
||||||
|
|
||||||
|
return CursorPosition + trimmedSpaces + nextWhitespace;
|
||||||
|
}
|
||||||
|
|
||||||
public override bool HandleKeyPress(KeyInput e)
|
public override bool HandleKeyPress(KeyInput e)
|
||||||
{
|
{
|
||||||
if (IsDisabled() || e.Event == KeyInputEvent.Up)
|
if (IsDisabled() || e.Event == KeyInputEvent.Up)
|
||||||
@@ -120,20 +137,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (!HasKeyboardFocus)
|
if (!HasKeyboardFocus)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Func<int> getPrevWhitespaceIndex = () =>
|
|
||||||
Text.Substring(0, CursorPosition).TrimEnd().LastIndexOf(' ') + 1;
|
|
||||||
|
|
||||||
Func<int> getNextWhitespaceIndex = () =>
|
|
||||||
{
|
|
||||||
var substr = Text.Substring(CursorPosition);
|
|
||||||
var substrTrimmed = substr.TrimStart();
|
|
||||||
var trimmedSpaces = substr.Length - substrTrimmed.Length;
|
|
||||||
var nextWhitespace = substrTrimmed.IndexOf(' ');
|
|
||||||
if (nextWhitespace == -1)
|
|
||||||
return Text.Length;
|
|
||||||
return CursorPosition + trimmedSpaces + nextWhitespace;
|
|
||||||
};
|
|
||||||
|
|
||||||
var isOSX = Platform.CurrentPlatform == PlatformType.OSX;
|
var isOSX = Platform.CurrentPlatform == PlatformType.OSX;
|
||||||
|
|
||||||
switch (e.Key) {
|
switch (e.Key) {
|
||||||
@@ -163,7 +166,9 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (CursorPosition > 0)
|
if (CursorPosition > 0)
|
||||||
{
|
{
|
||||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
CursorPosition = getPrevWhitespaceIndex();
|
CursorPosition = GetPrevWhitespaceIndex();
|
||||||
|
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
||||||
|
CursorPosition = 0;
|
||||||
else
|
else
|
||||||
CursorPosition--;
|
CursorPosition--;
|
||||||
}
|
}
|
||||||
@@ -175,7 +180,9 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (CursorPosition <= Text.Length - 1)
|
if (CursorPosition <= Text.Length - 1)
|
||||||
{
|
{
|
||||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
CursorPosition = getNextWhitespaceIndex();
|
CursorPosition = GetNextWhitespaceIndex();
|
||||||
|
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
||||||
|
CursorPosition = Text.Length;
|
||||||
else
|
else
|
||||||
CursorPosition++;
|
CursorPosition++;
|
||||||
}
|
}
|
||||||
@@ -192,10 +199,19 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
CursorPosition = Text.Length;
|
CursorPosition = Text.Length;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Keycode.D:
|
||||||
|
if (e.Modifiers.HasModifier(Modifiers.Ctrl) && CursorPosition < Text.Length)
|
||||||
|
{
|
||||||
|
Text = Text.Remove(CursorPosition, 1);
|
||||||
|
OnTextEdited();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case Keycode.K:
|
case Keycode.K:
|
||||||
// ctrl+k is equivalent to cmd+delete on osx
|
// ctrl+k is equivalent to cmd+delete on osx (but also works on osx)
|
||||||
ResetBlinkCycle();
|
ResetBlinkCycle();
|
||||||
if (!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl) && CursorPosition < Text.Length)
|
if (e.Modifiers.HasModifier(Modifiers.Ctrl) && CursorPosition < Text.Length)
|
||||||
{
|
{
|
||||||
Text = Text.Remove(CursorPosition);
|
Text = Text.Remove(CursorPosition);
|
||||||
OnTextEdited();
|
OnTextEdited();
|
||||||
@@ -234,7 +250,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (CursorPosition < Text.Length)
|
if (CursorPosition < Text.Length)
|
||||||
{
|
{
|
||||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
Text = Text.Substring(0, CursorPosition) + Text.Substring(getNextWhitespaceIndex());
|
Text = Text.Substring(0, CursorPosition) + Text.Substring(GetNextWhitespaceIndex());
|
||||||
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
||||||
Text = Text.Remove(CursorPosition);
|
Text = Text.Remove(CursorPosition);
|
||||||
else
|
else
|
||||||
@@ -252,9 +268,9 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) || (isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
{
|
{
|
||||||
var prev_whitespace = getPrevWhitespaceIndex();
|
var prevWhitespace = GetPrevWhitespaceIndex();
|
||||||
Text = Text.Substring(0, prev_whitespace) + Text.Substring(CursorPosition);
|
Text = Text.Substring(0, prevWhitespace) + Text.Substring(CursorPosition);
|
||||||
CursorPosition = prev_whitespace;
|
CursorPosition = prevWhitespace;
|
||||||
}
|
}
|
||||||
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user