[Quick Accent]Wrap Quick Accent toolbar selection (#20320)

* Wrap Quick Accent toolbar selection

Wraps _selectionIndex at beginning and end of range.

* Holding Shift + Space moves _selectedIndex backwards

Moves toolbar selection from right to left when Shift key is held.

* Fix formatting and typos

* Change EOL of files to LF

Changes PowerAccent.cs and WindowFunctions.cs back from CRLF to LF

* Rename IsCapitalState() to IsCapsLockState()

* Correct Logical Mistake (&& -> ||)

* Removed backward movement when holding Shift
This commit is contained in:
WJKM
2022-09-28 21:36:52 +10:00
committed by GitHub
parent 08be4abd56
commit 82fea7eff1
2 changed files with 21 additions and 5 deletions

View File

@@ -62,7 +62,7 @@ public class PowerAccent : IDisposable
private void ShowToolbar(LetterKey letterKey) private void ShowToolbar(LetterKey letterKey)
{ {
_visible = true; _visible = true;
_characters = WindowsFunctions.IsCapitalState() ? ToUpper(SettingsService.GetDefaultLetterKey(letterKey)) : SettingsService.GetDefaultLetterKey(letterKey); _characters = (WindowsFunctions.IsCapsLockState() || WindowsFunctions.IsShiftState()) ? ToUpper(SettingsService.GetDefaultLetterKey(letterKey)) : SettingsService.GetDefaultLetterKey(letterKey);
Task.Delay(_settingService.InputTime).ContinueWith( Task.Delay(_settingService.InputTime).ContinueWith(
t => t =>
{ {
@@ -144,16 +144,27 @@ public class PowerAccent : IDisposable
} }
} }
if (triggerKey == TriggerKey.Left && _selectedIndex > 0) if (triggerKey == TriggerKey.Left)
{ {
--_selectedIndex; --_selectedIndex;
} }
if (triggerKey == TriggerKey.Right && _selectedIndex < _characters.Length - 1) if (triggerKey == TriggerKey.Right)
{ {
++_selectedIndex; ++_selectedIndex;
} }
// Wrap around at beginning and end of _selectedIndex range
if (_selectedIndex < 0)
{
_selectedIndex = _characters.Length - 1;
}
if (_selectedIndex > _characters.Length - 1)
{
_selectedIndex = 0;
}
OnSelectCharacter?.Invoke(_selectedIndex, _characters[_selectedIndex]); OnSelectCharacter?.Invoke(_selectedIndex, _characters[_selectedIndex]);
} }

View File

@@ -70,10 +70,15 @@ internal static class WindowsFunctions
return (monitorInfo.rcWork.Location, monitorInfo.rcWork.Size, dpi); return (monitorInfo.rcWork.Location, monitorInfo.rcWork.Size, dpi);
} }
public static bool IsCapitalState() public static bool IsCapsLockState()
{ {
var capital = User32.GetKeyState((int)User32.VK.VK_CAPITAL); var capital = User32.GetKeyState((int)User32.VK.VK_CAPITAL);
return capital != 0;
}
public static bool IsShiftState()
{
var shift = User32.GetKeyState((int)User32.VK.VK_SHIFT); var shift = User32.GetKeyState((int)User32.VK.VK_SHIFT);
return capital != 0 || shift < 0; return shift < 0;
} }
} }