diff --git a/ReClass.NET/Controls/HotSpotTextBox.cs b/ReClass.NET/Controls/HotSpotTextBox.cs index 218cdeb7..af104e4e 100644 --- a/ReClass.NET/Controls/HotSpotTextBox.cs +++ b/ReClass.NET/Controls/HotSpotTextBox.cs @@ -1,7 +1,9 @@ using System; using System.ComponentModel; using System.Drawing; +using System.Linq; using System.Windows.Forms; +using ReClassNET.Debugger; using ReClassNET.UI; namespace ReClassNET.Controls @@ -54,6 +56,83 @@ protected override void OnVisibleChanged(EventArgs e) } } + protected override bool ProcessCmdKey(ref Message m, Keys keyData) + { + // Checks if we're on some address. + var selectionPredicate = (char c) => + { + c = Char.ToLower(c); + return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z'); + }; + + if (keyData == (Keys.Control | Keys.Left)) + { + if (SelectionStart > 0 && !string.IsNullOrEmpty(Text)) + { + var atEnd = SelectionStart == Text.Length; + var selectionInText = Math.Min(SelectionStart, Text.Length - 1); + var currChar = () => Text[selectionInText - 1]; + bool currMatchesPredicate = (atEnd && selectionPredicate(Text[selectionInText])) || selectionPredicate(currChar()); + + if (currMatchesPredicate) + { + while (selectionInText > 0 && selectionPredicate(currChar())) + { + selectionInText -= 1; + } + } + else + { + selectionInText -= 1; + while (selectionInText > 0 && !selectionPredicate(currChar())) + { + selectionInText -= 1; + } + } + + selectionInText = Math.Max(selectionInText, 0); + SelectionStart = selectionInText; + SelectionLength = 0; + + return true; + } + } + else if (keyData == (Keys.Control | Keys.Right)) + { + var maxSelectionStart = Text.Length; + if (!string.IsNullOrEmpty(Text) && SelectionStart != maxSelectionStart) + { + var selectionInText = Math.Min(SelectionStart, Text.Length - 1); + var currChar = () => Text[selectionInText]; + bool currMatchesPredicate = selectionPredicate(currChar()); + + if (currMatchesPredicate) + { + while (selectionInText < maxSelectionStart && selectionPredicate(currChar())) + { + selectionInText += 1; + } + } + else + { + selectionInText += 1; + while (selectionInText < maxSelectionStart && !selectionPredicate(currChar())) + { + selectionInText += 1; + } + } + + selectionInText = Math.Min(selectionInText, maxSelectionStart); + SelectionStart = selectionInText; + SelectionLength = 0; + + return true; + } + } + + return base.ProcessCmdKey(ref m, keyData); + } + protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.Enter) @@ -87,7 +166,7 @@ private void OnCommit() Committed?.Invoke(this, new HotSpotTextBoxCommitEventArgs(currentHotSpot)); } - #endregion + #endregion Events public void ShowOnHotSpot(HotSpot hotSpot) { @@ -127,4 +206,4 @@ public HotSpotTextBoxCommitEventArgs(HotSpot hotSpot) HotSpot = hotSpot; } } -} +} \ No newline at end of file