Skip to content

Commit b9d1314

Browse files
committed
Fixed Regex
1 parent d840cc6 commit b9d1314

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

InputTextX/InputBox.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
using Rainmeter;
1010
using System.Windows.Forms;
1111
using System.IO;
12-
12+
using System.Text.RegularExpressions;
1313

1414
namespace InputTextX
1515
{
16+
17+
1618
public class InputOverlay : Form
1719
{
1820
internal static class NativeMethods
@@ -262,6 +264,14 @@ private string EscapeCommandArgument(string input)
262264
return input.Replace("\"", "\\\"");
263265
}
264266

267+
// New helper: case-insensitive replacement for "$UserInput$"
268+
private string ReplacePlaceholder(string command, string replacement)
269+
{
270+
if (string.IsNullOrEmpty(command))
271+
return command;
272+
return Regex.Replace(command, Regex.Escape("$UserInput$"), replacement, RegexOptions.IgnoreCase);
273+
}
274+
265275
private bool ValidateChar(char ch)
266276
{
267277
if (char.IsControl(ch))
@@ -332,7 +342,8 @@ private void TextBox_KeyDown(object sender, KeyEventArgs e)
332342
{
333343
if (e.KeyCode == Keys.Escape)
334344
{
335-
string command = _onESCAction.Replace("$UserInput$", EscapeCommandArgument(textBox.Text));
345+
// Use ReplacePlaceholder for case-insensitive replacement.
346+
string command = ReplacePlaceholder(_onESCAction, EscapeCommandArgument(textBox.Text));
336347
if (!string.IsNullOrWhiteSpace(command))
337348
{
338349
if (logging == 1)
@@ -390,7 +401,7 @@ private void TextBox_KeyDown(object sender, KeyEventArgs e)
390401
}
391402
}
392403
}
393-
string enterCommand = _onEnterAction.Replace("$UserInput$", EscapeCommandArgument(textBox.Text));
404+
string enterCommand = ReplacePlaceholder(_onEnterAction, EscapeCommandArgument(textBox.Text));
394405
if (!string.IsNullOrWhiteSpace(enterCommand))
395406
{
396407
if (logging == 1)
@@ -412,7 +423,7 @@ protected override void OnDeactivate(EventArgs e)
412423
base.OnDeactivate(e);
413424
if (!_isClosing && unFocusDismiss == 1)
414425
{
415-
string command = _onDismissAction.Replace("$UserInput$", EscapeCommandArgument(textBox.Text));
426+
string command = ReplacePlaceholder(_onDismissAction, EscapeCommandArgument(textBox.Text));
416427
if (!string.IsNullOrWhiteSpace(command))
417428
{
418429
if (logging == 1)
@@ -450,7 +461,7 @@ private void CloseInput()
450461
protected override void OnShown(EventArgs e)
451462
{
452463
base.OnShown(e);
453-
this.Opacity = 1;
464+
this.Opacity = 1;
454465
}
455466
}
456467
}

README.md

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,15 @@
66

77
## Features
88

9-
- **Customizable Appearance:**
10-
Configure dimensions, colors, fonts (including custom font files), and borders.
11-
12-
- **Input Types & Validation:**
13-
Supports `String`, `Integer`, `Float`, `Letters`, `Alphanumeric`, `Hexadecimal`, `Email`, and a custom mode with allowed characters.
14-
15-
- **Action Handling:**
16-
Execute custom Rainmeter commands on key events:
9+
- **Customizable Appearance:**Configure dimensions, colors, fonts (including custom font files), and borders.
10+
- **Input Types & Validation:**Supports `String`, `Integer`, `Float`, `Letters`, `Alphanumeric`, `Hexadecimal`, `Email`, and a custom mode with allowed characters.
11+
- **Action Handling:**Execute custom Rainmeter commands on key events:
12+
1713
- **OnEnterAction:** Triggered when the user submits the input.
1814
- **OnESCAction:** Triggered when the user presses the Escape key.
1915
- **OnDismissAction:** Triggered when the input overlay loses focus.
20-
21-
- **Dynamic Placeholder Replacement:**
22-
Replace the placeholder `$UserInput$` with the current text input before executing commands.
23-
<span style="color: red;"><strong>Note:</strong></span> Special characters (e.g., double quotes) are automatically escaped to ensure valid command syntax.
24-
25-
- **Logging:**
16+
- **Dynamic Placeholder Replacement:**Replace the placeholder `$UserInput$` with the current text input before executing commands.`<span style="color: red;"><strong>`Note:`</strong>` Special characters (e.g., double quotes) are automatically escaped to ensure valid command syntax.
17+
- **Logging:**
2618
Detailed logging can be enabled for debugging. All logs are printed only when the `Logging` key is set to `1`.
2719

2820
---
@@ -31,20 +23,18 @@
3123

3224
### Installation
3325

34-
1. **Build the Plugin:**
35-
Compile the C# code into a DLL (e.g., using Visual Studio) and place it into your Rainmeter plugins folder.
26+
1. **Build the Plugin:**Compile the C# code into a DLL (e.g., using Visual Studio) and place it into your Rainmeter plugins folder.
27+
2. **Add the Plugin to Your Skin:**Create a Rainmeter skin and add the following measure:
3628

37-
2. **Add the Plugin to Your Skin:**
38-
Create a Rainmeter skin and add the following measure:
3929
```ini
4030
[MeasureInput]
4131
Measure=Plugin
4232
Plugin=InputTextX.dll
4333
```
44-
45-
3. **Configure the Plugin:**
46-
Set the desired configuration keys (see below) in your Rainmeter skin.
34+
3. **Configure the Plugin:**
35+
Set the desired configuration keys (see below) in your Rainmeter skin.
4736
Example:
37+
4838
```ini
4939
[MeasureInput]
5040
Measure=Plugin
@@ -281,23 +271,21 @@ The `InputType` key supports the following values:
281271

282272
## Usage Notes
283273

284-
> **Note:**
274+
> **Note:**
285275
> The plugin dynamically replaces the placeholder `$UserInput$` in action keys with the current input text. It also escapes special characters (such as double quotes) to ensure the resulting Rainmeter command is valid.
286276
287-
> **Warning:**
277+
> **InputTextX** is incompatible with skins set to **Stay Topmost**, or **AlwaysOnTop=2**, as the conflict between the input field, which requires "focus", and the constant attempts by the skin to stay on "top", in front of the input field, will not allow InputTextX to function correctly.
278+
279+
> **Warning:**
288280
> Ensure that your custom commands (especially those using `$UserInput$`) are properly formatted. Improper command syntax may cause unexpected behavior in Rainmeter.
289281
290282
---
291283

292284
## Troubleshooting
293285

294-
- **Crash on Input:**
295-
If Rainmeter crashes when submitting input, enable logging by setting `Logging=1` to view the final command strings in the Rainmeter log. Verify that the commands are correctly formed.
296-
297-
- **No Command Execution:**
298-
Double-check the action keys (e.g., `OnEnterAction`, `OnESCAction`) in your skin configuration. They must contain valid Rainmeter commands.
299-
300-
- **Positioning Issues:**
286+
- **Crash on Input:**If Rainmeter crashes when submitting input, enable logging by setting `Logging=1` to view the final command strings in the Rainmeter log. Verify that the commands are correctly formed.
287+
- **No Command Execution:**Double-check the action keys (e.g., `OnEnterAction`, `OnESCAction`) in your skin configuration. They must contain valid Rainmeter commands.
288+
- **Positioning Issues:**
301289
If the overlay does not appear in the expected location, adjust the `X` and `Y` offset values.
302290

303291
---

0 commit comments

Comments
 (0)