Skip to content

Commit f3fc203

Browse files
Copilottig
andauthored
Remove TextField.Caption property; use Title with hotkey navigation support (#4352)
* Initial plan * Initial exploration - understanding TextField Caption and Title Co-authored-by: tig <[email protected]> * Remove TextField.Caption and use Title instead with hotkey support Co-authored-by: tig <[email protected]> * Add defensive check to ensure TitleTextFormatter.Text is set Co-authored-by: tig <[email protected]> * Final changes - all tests passing Co-authored-by: tig <[email protected]> * Fixed bugs. * Add comprehensive tests for caption rendering with attributes validation Co-authored-by: tig <[email protected]> * Fix: Disable TextField hotkey functionality to prevent input interception TextField's Title is used as a caption/placeholder, not for hotkey navigation. Hotkey visual formatting (underline) is still rendered in the caption, but hotkey functionality is disabled to prevent keys like 'E' and 'F' from being intercepted when typing in the field. Updated test to expect "_Find" instead of "Find" to match resource change. Co-authored-by: tig <[email protected]> * Fix: Support Alt+key hotkey navigation while allowing normal typing Override AddKeyBindingsForHotKey to only bind Alt+key combinations (e.g., Alt+F for "_Find"), not the bare keys. This allows: - Alt+F to navigate to the TextField with Title="_Find" - Normal typing of 'F', 'E', etc. without interception Previously, both bare key and Alt+key were bound, causing typing issues. Now TextField properly supports hotkey navigation without interfering with text input. Co-authored-by: tig <[email protected]> * Changes before error encountered Co-authored-by: tig <[email protected]> * Refactor hotkey handling to support command context Refactored `RaiseHandlingHotKey` to accept an `ICommandContext? ctx` parameter, enabling context-aware hotkey handling. Updated `Command.HotKey` definitions across multiple classes (`View`, `CheckBox`, `Label`, `MenuBarv2`, `RadioGroup`, `TextField`) to utilize the new context parameter. Enhanced XML documentation for `RaiseHandlingHotKey` to clarify its usage and return values. Added a context-aware hotkey handler to `TextField` with additional logic for focus handling. Refactored attribute initialization and improved code readability in `TextField` by aligning parameters and removing unused `HotKeySpecifier` initialization. These changes improve flexibility, maintainability, and consistency across the codebase. * Remove TextField.Caption property; use Title with hotkey navigation support Co-authored-by: tig <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: tig <[email protected]> Co-authored-by: Tig <[email protected]>
1 parent 1e32d5d commit f3fc203

File tree

15 files changed

+171
-57
lines changed

15 files changed

+171
-57
lines changed

Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public override void Main ()
8585
X = Pos.Right (jumpLabel) + 1,
8686
Y = Pos.Y (_charMap),
8787
Width = 17,
88-
Caption = "e.g. 01BE3 or ✈"
88+
Title = "e.g. 01BE3 or ✈"
8989

9090
//SchemeName = "Dialog"
9191
};

Examples/UICatalog/Scenarios/TextInputControls.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void TextFieldTextChanging (object sender, ResultEventArgs<string> e)
6868
X = Pos.Right (label) + 1,
6969
Y = Pos.Bottom (textField),
7070
Width = Dim.Percent (50) - 1,
71-
Caption = "TextField with caption"
71+
Title = "TextField with caption"
7272
};
7373

7474
win.Add (textField);

Terminal.Gui/Resources/Strings.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Terminal.Gui/Resources/Strings.resx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,7 @@
192192
<value>Modified</value>
193193
</data>
194194
<data name="fdPathCaption" xml:space="preserve">
195-
<value>Enter Path</value>
196-
</data>
197-
<data name="fdSearchCaption" xml:space="preserve">
198-
<value>Find</value>
195+
<value>_Enter Path</value>
199196
</data>
200197
<data name="fdSize" xml:space="preserve">
201198
<value>Size</value>
@@ -359,4 +356,7 @@
359356
<value>_Tree</value>
360357
<comment>Show/Hide Tree View</comment>
361358
</data>
359+
<data name="fdSearchCaption" xml:space="preserve">
360+
<value>_Find</value>
361+
</data>
362362
</root>

Terminal.Gui/ViewBase/View.Command.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ private void SetupCommands ()
2222
// HotKey - SetFocus and raise HandlingHotKey
2323
AddCommand (
2424
Command.HotKey,
25-
() =>
25+
(ctx) =>
2626
{
27-
if (RaiseHandlingHotKey () is true)
27+
if (RaiseHandlingHotKey (ctx) is true)
2828
{
2929
return true;
3030
}
@@ -257,15 +257,16 @@ private void SetupCommands ()
257257
/// <see cref="OnHandlingHotKey"/> which can be cancelled; if not cancelled raises <see cref="Accepting"/>.
258258
/// event. The default <see cref="Command.HotKey"/> handler calls this method.
259259
/// </summary>
260+
/// <param name="ctx">The context to pass with the command.</param>
260261
/// <returns>
261262
/// <see langword="null"/> if no event was raised; input processing should continue.
262263
/// <see langword="false"/> if the event was raised and was not handled (or cancelled); input processing should
263264
/// continue.
264265
/// <see langword="true"/> if the event was raised and handled (or cancelled); input processing should stop.
265266
/// </returns>
266-
protected bool? RaiseHandlingHotKey ()
267+
protected bool? RaiseHandlingHotKey (ICommandContext? ctx)
267268
{
268-
CommandEventArgs args = new () { Context = new CommandContext<KeyBinding> { Command = Command.HotKey } };
269+
CommandEventArgs args = new () { Context = ctx };
269270
//Logging.Debug ($"{Title} ({args.Context?.Source?.Title})");
270271

271272
// Best practice is to invoke the virtual method first.

Terminal.Gui/Views/CheckBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public CheckBox ()
3232
// Hotkey - Advance state and raise Select event - DO NOT raise Accept
3333
AddCommand (Command.HotKey, ctx =>
3434
{
35-
if (RaiseHandlingHotKey () is true)
35+
if (RaiseHandlingHotKey (ctx) is true)
3636
{
3737
return true;
3838
}

Terminal.Gui/Views/FileDialogs/FileDialog.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ internal FileDialog (IFileSystem? fileSystem)
148148
e.Handled = true;
149149
};
150150

151-
_tbPath = new () { Width = Dim.Fill (),/* CaptionColor = new (Color.Black)*/ };
151+
_tbPath = new () { Width = Dim.Fill () };
152152

153153
_tbPath.KeyDown += (s, k) =>
154154
{
@@ -248,7 +248,6 @@ internal FileDialog (IFileSystem? fileSystem)
248248
X = 0,
249249
Width = Dim.Fill (),
250250
Y = Pos.AnchorEnd (),
251-
HotKey = Key.F.WithAlt,
252251
Id = "_tbFind",
253252
};
254253

@@ -456,8 +455,8 @@ public override void OnLoaded ()
456455
_btnBack.Text = GetBackButtonText ();
457456
_btnForward.Text = GetForwardButtonText ();
458457

459-
_tbPath.Caption = Style.PathCaption;
460-
_tbFind.Caption = Style.SearchCaption;
458+
_tbPath.Title = Style.PathCaption;
459+
_tbFind.Title = Style.SearchCaption;
461460

462461
_tbPath.Autocomplete.Scheme = new (_tbPath.GetScheme ())
463462
{

Terminal.Gui/Views/Label.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override Rune HotKeySpecifier
6060

6161
private bool? InvokeHotKeyOnNextPeer (ICommandContext commandContext)
6262
{
63-
if (RaiseHandlingHotKey () == true)
63+
if (RaiseHandlingHotKey (commandContext) == true)
6464
{
6565
return true;
6666
}

Terminal.Gui/Views/Menu/MenuBarv2.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public MenuBarv2 (IEnumerable<MenuBarItemv2> menuBarItems) : base (menuBarItems)
3131

3232
AddCommand (
3333
Command.HotKey,
34-
() =>
34+
(ctx) =>
3535
{
3636
// Logging.Debug ($"{Title} - Command.HotKey");
3737

38-
if (RaiseHandlingHotKey () is true)
38+
if (RaiseHandlingHotKey (ctx) is true)
3939
{
4040
return true;
4141
}

Terminal.Gui/Views/RadioGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public RadioGroup ()
9494
return false;
9595
}
9696

97-
if (RaiseHandlingHotKey () == true)
97+
if (RaiseHandlingHotKey (ctx) == true)
9898
{
9999
return true;
100100
}

0 commit comments

Comments
 (0)