Skip to content

Commit 68daff5

Browse files
authored
Merge pull request #3856 from MaciekWin3/text-inputs-keybindings-update
Fixes #3855 - Text inputs keybindings update
2 parents b856e9a + 292e1a1 commit 68daff5

File tree

8 files changed

+48
-52
lines changed

8 files changed

+48
-52
lines changed

Showcase.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
- **[Muse](https://github.com/MaciekWin3/Muse)** - Muse is terminal music player built with Terminal.Gui and NAudio on .NET platform.
2828
![Muse](https://github.com/user-attachments/assets/94aeb559-a889-4b52-bb0d-453b3e19b290)
29-
z
29+
3030
- **[Whale](https://github.com/MaciekWin3/Whale)** - Lightweight terminal user interface application that helps software engineers manage Docker containers.
3131
![Whale](https://github.com/user-attachments/assets/7ef6e348-c36b-4aee-a63c-4e5c60c3aad2)
3232

Terminal.Gui/Views/DateField.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public override void DeleteCharRight ()
114114
}
115115

116116
/// <inheritdoc/>
117-
protected override bool OnMouseEvent (MouseEventArgs ev)
117+
protected override bool OnMouseEvent (MouseEventArgs ev)
118118
{
119119
if (base.OnMouseEvent (ev) || ev.Handled)
120120
{
@@ -410,7 +410,7 @@ private void SetInitialProperties (DateTime date)
410410
KeyBindings.ReplaceCommands (Key.Backspace, Command.DeleteCharLeft);
411411

412412
KeyBindings.ReplaceCommands (Key.Home, Command.LeftStart);
413-
KeyBindings.ReplaceCommands (Key.A.WithCtrl, Command.LeftStart);
413+
KeyBindings.ReplaceCommands (Key.Home.WithCtrl, Command.LeftStart);
414414

415415
KeyBindings.ReplaceCommands (Key.CursorLeft, Command.Left);
416416
KeyBindings.ReplaceCommands (Key.B.WithCtrl, Command.Left);
@@ -551,35 +551,35 @@ private bool SetText (string text)
551551
private static string StandardizeDateFormat (string format)
552552
{
553553
return format switch
554-
{
555-
"MM/dd/yyyy" => "MM/dd/yyyy",
556-
"yyyy-MM-dd" => "yyyy-MM-dd",
557-
"yyyy/MM/dd" => "yyyy/MM/dd",
558-
"dd/MM/yyyy" => "dd/MM/yyyy",
559-
"d?/M?/yyyy" => "dd/MM/yyyy",
560-
"dd.MM.yyyy" => "dd.MM.yyyy",
561-
"dd-MM-yyyy" => "dd-MM-yyyy",
562-
"dd/MM yyyy" => "dd/MM/yyyy",
563-
"d. M. yyyy" => "dd.MM.yyyy",
564-
"yyyy.MM.dd" => "yyyy.MM.dd",
565-
"g yyyy/M/d" => "yyyy/MM/dd",
566-
"d/M/yyyy" => "dd/MM/yyyy",
567-
"d?/M?/yyyy g" => "dd/MM/yyyy",
568-
"d-M-yyyy" => "dd-MM-yyyy",
569-
"d.MM.yyyy" => "dd.MM.yyyy",
570-
"d.MM.yyyy '?'." => "dd.MM.yyyy",
571-
"M/d/yyyy" => "MM/dd/yyyy",
572-
"d. M. yyyy." => "dd.MM.yyyy",
573-
"d.M.yyyy." => "dd.MM.yyyy",
574-
"g yyyy-MM-dd" => "yyyy-MM-dd",
575-
"d.M.yyyy" => "dd.MM.yyyy",
576-
"d/MM/yyyy" => "dd/MM/yyyy",
577-
"yyyy/M/d" => "yyyy/MM/dd",
578-
"dd. MM. yyyy." => "dd.MM.yyyy",
579-
"yyyy. MM. dd." => "yyyy.MM.dd",
580-
"yyyy. M. d." => "yyyy.MM.dd",
581-
"d. MM. yyyy" => "dd.MM.yyyy",
582-
_ => "dd/MM/yyyy"
583-
};
554+
{
555+
"MM/dd/yyyy" => "MM/dd/yyyy",
556+
"yyyy-MM-dd" => "yyyy-MM-dd",
557+
"yyyy/MM/dd" => "yyyy/MM/dd",
558+
"dd/MM/yyyy" => "dd/MM/yyyy",
559+
"d?/M?/yyyy" => "dd/MM/yyyy",
560+
"dd.MM.yyyy" => "dd.MM.yyyy",
561+
"dd-MM-yyyy" => "dd-MM-yyyy",
562+
"dd/MM yyyy" => "dd/MM/yyyy",
563+
"d. M. yyyy" => "dd.MM.yyyy",
564+
"yyyy.MM.dd" => "yyyy.MM.dd",
565+
"g yyyy/M/d" => "yyyy/MM/dd",
566+
"d/M/yyyy" => "dd/MM/yyyy",
567+
"d?/M?/yyyy g" => "dd/MM/yyyy",
568+
"d-M-yyyy" => "dd-MM-yyyy",
569+
"d.MM.yyyy" => "dd.MM.yyyy",
570+
"d.MM.yyyy '?'." => "dd.MM.yyyy",
571+
"M/d/yyyy" => "MM/dd/yyyy",
572+
"d. M. yyyy." => "dd.MM.yyyy",
573+
"d.M.yyyy." => "dd.MM.yyyy",
574+
"g yyyy-MM-dd" => "yyyy-MM-dd",
575+
"d.M.yyyy" => "dd.MM.yyyy",
576+
"d/MM/yyyy" => "dd/MM/yyyy",
577+
"yyyy/M/d" => "yyyy/MM/dd",
578+
"dd. MM. yyyy." => "dd.MM.yyyy",
579+
"yyyy. MM. dd." => "yyyy.MM.dd",
580+
"yyyy. M. d." => "yyyy.MM.dd",
581+
"d. MM. yyyy" => "dd.MM.yyyy",
582+
_ => "dd/MM/yyyy"
583+
};
584584
}
585585
}

Terminal.Gui/Views/TextField.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ public TextField ()
341341

342342
KeyBindings.Add (Key.Home, Command.LeftStart);
343343
KeyBindings.Add (Key.Home.WithCtrl, Command.LeftStart);
344-
KeyBindings.Add (Key.A.WithCtrl, Command.LeftStart);
345344

346345
KeyBindings.Add (Key.CursorLeft.WithShift, Command.LeftExtend);
347346
KeyBindings.Add (Key.CursorUp.WithShift, Command.LeftExtend);
@@ -393,14 +392,14 @@ public TextField ()
393392
KeyBindings.Add (Key.C.WithCtrl, Command.Copy);
394393
KeyBindings.Add (Key.X.WithCtrl, Command.Cut);
395394
KeyBindings.Add (Key.V.WithCtrl, Command.Paste);
396-
KeyBindings.Add (Key.T.WithCtrl, Command.SelectAll);
395+
KeyBindings.Add (Key.A.WithCtrl, Command.SelectAll);
397396

398397
KeyBindings.Add (Key.R.WithCtrl, Command.DeleteAll);
399398
KeyBindings.Add (Key.D.WithCtrl.WithShift, Command.DeleteAll);
400399

401400
_currentCulture = Thread.CurrentThread.CurrentUICulture;
402401

403-
ContextMenu = new() { Host = this };
402+
ContextMenu = new () { Host = this };
404403
ContextMenu.KeyChanged += ContextMenu_KeyChanged;
405404

406405
KeyBindings.Add (ContextMenu.Key, KeyBindingScope.HotKey, Command.Context);

Terminal.Gui/Views/TextView.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,7 +2347,6 @@ public TextView ()
23472347
KeyBindings.Add (Key.Backspace, Command.DeleteCharLeft);
23482348

23492349
KeyBindings.Add (Key.Home, Command.LeftStart);
2350-
KeyBindings.Add (Key.A.WithCtrl, Command.LeftStart);
23512350

23522351
KeyBindings.Add (Key.Home.WithShift, Command.LeftStartExtend);
23532352

@@ -2387,7 +2386,7 @@ public TextView ()
23872386
KeyBindings.Add (Key.End.WithCtrl.WithShift, Command.EndExtend);
23882387
KeyBindings.Add (Key.Home.WithCtrl, Command.Start);
23892388
KeyBindings.Add (Key.Home.WithCtrl.WithShift, Command.StartExtend);
2390-
KeyBindings.Add (Key.T.WithCtrl, Command.SelectAll);
2389+
KeyBindings.Add (Key.A.WithCtrl, Command.SelectAll);
23912390
KeyBindings.Add (Key.InsertChar, Command.ToggleOverwrite);
23922391
KeyBindings.Add (Key.Tab, Command.Tab);
23932392
KeyBindings.Add (Key.Tab.WithShift, Command.BackTab);

UnitTests/Views/DateFieldTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ public void KeyBindings_Command ()
126126
Assert.Equal (1, df.CursorPosition);
127127
Assert.True (df.NewKeyDownEvent (Key.End));
128128
Assert.Equal (10, df.CursorPosition);
129-
Assert.True (df.NewKeyDownEvent (Key.A.WithCtrl));
130-
Assert.Equal (1, df.CursorPosition);
131129
Assert.True (df.NewKeyDownEvent (Key.E.WithCtrl));
132130
Assert.Equal (10, df.CursorPosition);
133131
Assert.True (df.NewKeyDownEvent (Key.CursorLeft));

UnitTests/Views/TextFieldTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ public void KeyBindings_Command ()
651651
Assert.Null (tf.SelectedText);
652652
Assert.True (tf.NewKeyDownEvent (Key.A.WithCtrl));
653653
Assert.Equal ("is is a test.", tf.Text);
654-
Assert.Equal (0, tf.CursorPosition);
654+
Assert.Equal (tf.Text.Length, tf.CursorPosition);
655655
tf.CursorPosition = 5;
656656
tf.SelectedStart = -1;
657657
Assert.Null (tf.SelectedText);
@@ -804,7 +804,7 @@ public void KeyBindings_Command ()
804804
tf.CursorPosition = tf.Text.Length;
805805
Assert.True (tf.NewKeyDownEvent (Key.Backspace.WithCtrl));
806806
Assert.Equal ("to jump between text fields", tf.Text);
807-
Assert.True (tf.NewKeyDownEvent (Key.T.WithCtrl));
807+
Assert.True (tf.NewKeyDownEvent (Key.A.WithCtrl));
808808
Assert.Equal ("to jump between text fields", tf.SelectedText);
809809
Assert.True (tf.NewKeyDownEvent (Key.D.WithCtrl.WithShift));
810810
Assert.Equal ("", tf.Text);
@@ -2109,10 +2109,10 @@ public void Right_CursorAtEnd_WithSelection_ShouldClearSelection ()
21092109
tf.CursorPosition = 5;
21102110

21112111
// When there is selected text and the cursor is at the end of the text field
2112-
Assert.Equal ("Hello",tf.SelectedText);
2112+
Assert.Equal ("Hello", tf.SelectedText);
21132113

21142114
// Pressing right should not move focus, instead it should clear selection
2115-
Assert.True(tf.NewKeyDownEvent (Key.CursorRight));
2115+
Assert.True (tf.NewKeyDownEvent (Key.CursorRight));
21162116
Assert.Null (tf.SelectedText);
21172117

21182118
// Now that the selection is cleared another right keypress should move focus
@@ -2139,7 +2139,7 @@ public void Left_CursorAtStart_WithSelection_ShouldClearSelection ()
21392139
Assert.Null (tf.SelectedText);
21402140

21412141
// When clearing selected text with left the cursor should be at the start of the selection
2142-
Assert.Equal (0,tf.CursorPosition);
2142+
Assert.Equal (0, tf.CursorPosition);
21432143

21442144
// Now that the selection is cleared another left keypress should move focus
21452145
Assert.False (tf.NewKeyDownEvent (Key.CursorLeft));

UnitTests/Views/TextViewTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.ComponentModel;
21
using System.Reflection;
32
using System.Text;
43
using System.Text.RegularExpressions;
@@ -5137,7 +5136,7 @@ public void KeyBindings_Command ()
51375136
Assert.Equal (0, tv.SelectedLength);
51385137
Assert.Equal ("", tv.SelectedText);
51395138
Assert.False (tv.IsSelecting);
5140-
Assert.True (tv.NewKeyDownEvent (Key.A.WithCtrl));
5139+
Assert.True (tv.NewKeyDownEvent (Key.Home));
51415140
Assert.Equal (Point.Empty, tv.CursorPosition);
51425141
Assert.Equal (0, tv.SelectedLength);
51435142
Assert.Equal ("", tv.SelectedText);
@@ -5474,7 +5473,7 @@ public void KeyBindings_Command ()
54745473
Assert.Equal (Environment.NewLine.Length, tv.SelectedLength);
54755474
Assert.Equal ($"{Environment.NewLine}", tv.SelectedText);
54765475
Assert.True (tv.IsSelecting);
5477-
Assert.True (tv.NewKeyDownEvent (Key.T.WithCtrl));
5476+
Assert.True (tv.NewKeyDownEvent (Key.A.WithCtrl));
54785477

54795478
Assert.Equal (
54805479
$"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ",
@@ -8333,7 +8332,7 @@ public void WordWrap_ReadOnly_CursorPosition_SelectedText_Copy ()
83338332

83348333
var top = new Toplevel ();
83358334
top.Add (tv);
8336-
top.Layout();
8335+
top.Layout ();
83378336
tv.Draw ();
83388337

83398338
TestHelpers.AssertDriverContentsWithFrameAre (
@@ -8810,7 +8809,7 @@ public void Right_CursorAtEnd_WithSelection_ShouldClearSelection ()
88108809
tv.SetFocus ();
88118810

88128811
tv.NewKeyDownEvent (Key.End.WithShift);
8813-
Assert.Equal (5,tv.CursorPosition.X);
8812+
Assert.Equal (5, tv.CursorPosition.X);
88148813

88158814
// When there is selected text and the cursor is at the end of the text field
88168815
Assert.Equal ("Hello", tv.SelectedText);
@@ -8834,7 +8833,7 @@ public void Left_CursorAtStart_WithSelection_ShouldClearSelection ()
88348833
tv.NewKeyDownEvent (Key.CursorRight);
88358834
tv.NewKeyDownEvent (Key.CursorRight);
88368835

8837-
Assert.Equal (2,tv.CursorPosition.X);
8836+
Assert.Equal (2, tv.CursorPosition.X);
88388837

88398838
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));
88408839
Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift));

UnitTests/Views/TimeFieldTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ public void KeyBindings_Command ()
147147
Assert.True (tf.NewKeyDownEvent (Key.End));
148148
Assert.Equal (8, tf.CursorPosition);
149149
Assert.True (tf.NewKeyDownEvent (Key.A.WithCtrl));
150-
Assert.Equal (1, tf.CursorPosition);
150+
Assert.Equal (9, tf.CursorPosition);
151+
Assert.Equal (tf.SelectedLength, tf.Text.Length);
151152
Assert.True (tf.NewKeyDownEvent (Key.E.WithCtrl));
152153
Assert.Equal (8, tf.CursorPosition);
153154
Assert.True (tf.NewKeyDownEvent (Key.CursorLeft));

0 commit comments

Comments
 (0)