From 8da537ee36a55e03704a56ce393436b534057c27 Mon Sep 17 00:00:00 2001 From: Cristei Gabriel Date: Mon, 25 Dec 2023 19:36:02 +0200 Subject: [PATCH 1/4] Implement caret behavior --- ReClass.NET/Controls/HotSpotTextBox.cs | 85 +++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/ReClass.NET/Controls/HotSpotTextBox.cs b/ReClass.NET/Controls/HotSpotTextBox.cs index 218cdeb7..f7beebd4 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,85 @@ protected override void OnVisibleChanged(EventArgs e) } } + protected override bool ProcessCmdKey(ref Message m, Keys keyData) + { + bool state = base.ProcessCmdKey(ref m, keyData); + + // Checks if we're on some address. + var selectionPredicate = (char c) => + { + c = Char.ToLower(c); + return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || c == 'x'; + }; + + 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 > 0 && !selectionPredicate(currChar())) + { + selectionInText += 1; + } + } + + selectionInText = Math.Min(selectionInText, maxSelectionStart); + SelectionStart = selectionInText; + SelectionLength = 0; + + return true; + } + } + + return state; + } + protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.Enter) @@ -87,7 +168,7 @@ private void OnCommit() Committed?.Invoke(this, new HotSpotTextBoxCommitEventArgs(currentHotSpot)); } - #endregion + #endregion Events public void ShowOnHotSpot(HotSpot hotSpot) { @@ -127,4 +208,4 @@ public HotSpotTextBoxCommitEventArgs(HotSpot hotSpot) HotSpot = hotSpot; } } -} +} \ No newline at end of file From eaa990cdf306ca2009ea67f7634944937108e2f1 Mon Sep 17 00:00:00 2001 From: Cristei Gabriel Date: Mon, 25 Dec 2023 19:43:46 +0200 Subject: [PATCH 2/4] fix crash --- ReClass.NET/Controls/HotSpotTextBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReClass.NET/Controls/HotSpotTextBox.cs b/ReClass.NET/Controls/HotSpotTextBox.cs index f7beebd4..3ecc2ad3 100644 --- a/ReClass.NET/Controls/HotSpotTextBox.cs +++ b/ReClass.NET/Controls/HotSpotTextBox.cs @@ -118,7 +118,7 @@ protected override bool ProcessCmdKey(ref Message m, Keys keyData) else { selectionInText += 1; - while (selectionInText > 0 && !selectionPredicate(currChar())) + while (selectionInText < maxSelectionStart && !selectionPredicate(currChar())) { selectionInText += 1; } From 31ea9bc2fcc06b62a32fdc648b978d3527224a65 Mon Sep 17 00:00:00 2001 From: Cristei Gabriel Date: Mon, 25 Dec 2023 20:00:38 +0200 Subject: [PATCH 3/4] this makes more sense --- ReClass.NET/Controls/HotSpotTextBox.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ReClass.NET/Controls/HotSpotTextBox.cs b/ReClass.NET/Controls/HotSpotTextBox.cs index 3ecc2ad3..16348884 100644 --- a/ReClass.NET/Controls/HotSpotTextBox.cs +++ b/ReClass.NET/Controls/HotSpotTextBox.cs @@ -58,8 +58,6 @@ protected override void OnVisibleChanged(EventArgs e) protected override bool ProcessCmdKey(ref Message m, Keys keyData) { - bool state = base.ProcessCmdKey(ref m, keyData); - // Checks if we're on some address. var selectionPredicate = (char c) => { @@ -132,7 +130,7 @@ protected override bool ProcessCmdKey(ref Message m, Keys keyData) } } - return state; + return base.ProcessCmdKey(ref m, keyData); } protected override void OnKeyDown(KeyEventArgs e) From 7aec0834b0fefe182cbd6a511ea360577a21b54f Mon Sep 17 00:00:00 2001 From: Cristei Gabriel Date: Tue, 26 Dec 2023 15:00:53 +0200 Subject: [PATCH 4/4] this handles better for expressions where there's text --- ReClass.NET/Controls/HotSpotTextBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReClass.NET/Controls/HotSpotTextBox.cs b/ReClass.NET/Controls/HotSpotTextBox.cs index 16348884..af104e4e 100644 --- a/ReClass.NET/Controls/HotSpotTextBox.cs +++ b/ReClass.NET/Controls/HotSpotTextBox.cs @@ -62,7 +62,7 @@ protected override bool ProcessCmdKey(ref Message m, Keys keyData) var selectionPredicate = (char c) => { c = Char.ToLower(c); - return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || c == 'x'; + return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z'); }; if (keyData == (Keys.Control | Keys.Left))