Reset cursor blinking after keyboard-activated cursor movement
This commit is contained in:
@@ -62,6 +62,12 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return base.YieldKeyboardFocus();
|
return base.YieldKeyboardFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void ResetBlinkCycle()
|
||||||
|
{
|
||||||
|
blinkCycle = 10;
|
||||||
|
showCursor = true;
|
||||||
|
}
|
||||||
|
|
||||||
public override bool HandleMouseInput(MouseInput mi)
|
public override bool HandleMouseInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
if (IsDisabled())
|
if (IsDisabled())
|
||||||
@@ -74,8 +80,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (!RenderBounds.Contains(mi.Location) || !TakeKeyboardFocus())
|
if (!RenderBounds.Contains(mi.Location) || !TakeKeyboardFocus())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
blinkCycle = 10;
|
ResetBlinkCycle();
|
||||||
showCursor = true;
|
|
||||||
CursorPosition = ClosestCursorPosition(mi.Location.X);
|
CursorPosition = ClosestCursorPosition(mi.Location.X);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -119,17 +124,17 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
Text.Substring(0, CursorPosition).TrimEnd().LastIndexOf(' ') + 1;
|
Text.Substring(0, CursorPosition).TrimEnd().LastIndexOf(' ') + 1;
|
||||||
|
|
||||||
Func<int> getNextWhitespaceIndex = () => {
|
Func<int> getNextWhitespaceIndex = () => {
|
||||||
var substr_len = Text.Substring(CursorPosition).Length;
|
var substr = Text.Substring(CursorPosition);
|
||||||
var substr_trimmed = Text.Substring(CursorPosition).TrimStart();
|
var substrTrimmed = substr.TrimStart();
|
||||||
var trimmed_spaces = substr_len - substr_trimmed.Length;
|
var trimmedSpaces = substr.Length - substrTrimmed.Length;
|
||||||
var next_whitespace = substr_trimmed.IndexOf(' ');
|
var nextWhitespace = substrTrimmed.IndexOf(' ');
|
||||||
if (next_whitespace == -1)
|
if (nextWhitespace == -1)
|
||||||
return Text.Length;
|
return Text.Length;
|
||||||
else
|
else
|
||||||
return CursorPosition + trimmed_spaces + next_whitespace;
|
return CursorPosition + trimmedSpaces + nextWhitespace;
|
||||||
};
|
};
|
||||||
|
|
||||||
Func<bool> isOSX = () => Platform.CurrentPlatform == PlatformType.OSX;
|
var isOSX = Platform.CurrentPlatform == PlatformType.OSX;
|
||||||
|
|
||||||
switch (e.Key) {
|
switch (e.Key) {
|
||||||
case Keycode.RETURN:
|
case Keycode.RETURN:
|
||||||
@@ -154,18 +159,20 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Keycode.LEFT:
|
case Keycode.LEFT:
|
||||||
|
ResetBlinkCycle();
|
||||||
if (CursorPosition > 0)
|
if (CursorPosition > 0)
|
||||||
if ((!isOSX() && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
||||||
(isOSX() && e.Modifiers.HasModifier(Modifiers.Alt)))
|
(isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
CursorPosition = getPrevWhitespaceIndex();
|
CursorPosition = getPrevWhitespaceIndex();
|
||||||
else
|
else
|
||||||
CursorPosition--;
|
CursorPosition--;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Keycode.RIGHT:
|
case Keycode.RIGHT:
|
||||||
|
ResetBlinkCycle();
|
||||||
if (CursorPosition <= Text.Length - 1)
|
if (CursorPosition <= Text.Length - 1)
|
||||||
if ((!isOSX() && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
||||||
(isOSX() && e.Modifiers.HasModifier(Modifiers.Alt)))
|
(isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
CursorPosition = getNextWhitespaceIndex();
|
CursorPosition = getNextWhitespaceIndex();
|
||||||
else
|
else
|
||||||
CursorPosition++;
|
CursorPosition++;
|
||||||
@@ -173,16 +180,19 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Keycode.HOME:
|
case Keycode.HOME:
|
||||||
|
ResetBlinkCycle();
|
||||||
CursorPosition = 0;
|
CursorPosition = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Keycode.END:
|
case Keycode.END:
|
||||||
|
ResetBlinkCycle();
|
||||||
CursorPosition = Text.Length;
|
CursorPosition = Text.Length;
|
||||||
break;
|
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
|
||||||
if (!isOSX() && e.Modifiers.HasModifier(Modifiers.Ctrl) && CursorPosition < Text.Length)
|
ResetBlinkCycle();
|
||||||
|
if (!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl) && CursorPosition < Text.Length)
|
||||||
{
|
{
|
||||||
Text = Text.Remove(CursorPosition);
|
Text = Text.Remove(CursorPosition);
|
||||||
OnTextEdited();
|
OnTextEdited();
|
||||||
@@ -192,7 +202,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
case Keycode.U:
|
case Keycode.U:
|
||||||
// ctrl+u is equivalent to cmd+backspace on osx
|
// ctrl+u is equivalent to cmd+backspace on osx
|
||||||
if (!isOSX() && e.Modifiers.HasModifier(Modifiers.Ctrl) && CursorPosition > 0)
|
ResetBlinkCycle();
|
||||||
|
if (!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl) && CursorPosition > 0)
|
||||||
{
|
{
|
||||||
Text = Text.Substring(CursorPosition);
|
Text = Text.Substring(CursorPosition);
|
||||||
CursorPosition = 0;
|
CursorPosition = 0;
|
||||||
@@ -202,8 +213,9 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Keycode.X:
|
case Keycode.X:
|
||||||
if (((!isOSX() && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
ResetBlinkCycle();
|
||||||
(isOSX() && e.Modifiers.HasModifier(Modifiers.Meta))) &&
|
if (((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
||||||
|
(isOSX && e.Modifiers.HasModifier(Modifiers.Meta))) &&
|
||||||
(!string.IsNullOrEmpty(Text)))
|
(!string.IsNullOrEmpty(Text)))
|
||||||
{
|
{
|
||||||
Text = Text.Remove(0);
|
Text = Text.Remove(0);
|
||||||
@@ -215,12 +227,13 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
case Keycode.DELETE:
|
case Keycode.DELETE:
|
||||||
// cmd+delete is equivalent to ctrl+k on non-osx
|
// cmd+delete is equivalent to ctrl+k on non-osx
|
||||||
|
ResetBlinkCycle();
|
||||||
if (CursorPosition < Text.Length)
|
if (CursorPosition < Text.Length)
|
||||||
{
|
{
|
||||||
if ((!isOSX() && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
||||||
(isOSX() && e.Modifiers.HasModifier(Modifiers.Alt)))
|
(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
|
||||||
Text = Text.Remove(CursorPosition, 1);
|
Text = Text.Remove(CursorPosition, 1);
|
||||||
@@ -232,16 +245,17 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
case Keycode.BACKSPACE:
|
case Keycode.BACKSPACE:
|
||||||
// cmd+backspace is equivalent to ctrl+u on non-osx
|
// cmd+backspace is equivalent to ctrl+u on non-osx
|
||||||
|
ResetBlinkCycle();
|
||||||
if (CursorPosition > 0)
|
if (CursorPosition > 0)
|
||||||
{
|
{
|
||||||
if ((!isOSX() && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
||||||
(isOSX() && e.Modifiers.HasModifier(Modifiers.Alt)))
|
(isOSX && e.Modifiers.HasModifier(Modifiers.Alt)))
|
||||||
{
|
{
|
||||||
var prev_whitespace = getPrevWhitespaceIndex();
|
var prev_whitespace = getPrevWhitespaceIndex();
|
||||||
Text = Text.Substring(0, prev_whitespace) + Text.Substring(CursorPosition);
|
Text = Text.Substring(0, prev_whitespace) + Text.Substring(CursorPosition);
|
||||||
CursorPosition = prev_whitespace;
|
CursorPosition = prev_whitespace;
|
||||||
}
|
}
|
||||||
else if (isOSX() && e.Modifiers.HasModifier(Modifiers.Meta))
|
else if (isOSX && e.Modifiers.HasModifier(Modifiers.Meta))
|
||||||
{
|
{
|
||||||
Text = Text.Substring(CursorPosition);
|
Text = Text.Substring(CursorPosition);
|
||||||
CursorPosition = 0;
|
CursorPosition = 0;
|
||||||
@@ -258,8 +272,9 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Keycode.V:
|
case Keycode.V:
|
||||||
if ((!isOSX() && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
ResetBlinkCycle();
|
||||||
(isOSX() && e.Modifiers.HasModifier(Modifiers.Meta)))
|
if ((!isOSX && e.Modifiers.HasModifier(Modifiers.Ctrl)) ||
|
||||||
|
(isOSX && e.Modifiers.HasModifier(Modifiers.Meta)))
|
||||||
{
|
{
|
||||||
var clipboardText = Game.Renderer.GetClipboardText();
|
var clipboardText = Game.Renderer.GetClipboardText();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user