Skip to content

Commit 4b02893

Browse files
committed
Change select all keybinding for text inputs
1 parent dd32717 commit 4b02893

File tree

7 files changed

+57
-62
lines changed

7 files changed

+57
-62
lines changed

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: 12 additions & 13 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);
@@ -4466,12 +4465,12 @@ private bool DeleteTextForwards ()
44664465
}
44674466
else
44684467
{
4469-
_historyText.Add ([[.. currentLine]], CursorPosition);
4468+
_historyText.Add ([ [.. currentLine]], CursorPosition);
44704469

44714470
currentLine.RemoveAt (CurrentColumn);
44724471

44734472
_historyText.Add (
4474-
[[.. currentLine]],
4473+
[ [.. currentLine]],
44754474
CursorPosition,
44764475
HistoryText.LineStatus.Replaced
44774476
);
@@ -5058,7 +5057,7 @@ private void KillToEndOfLine ()
50585057
}
50595058

50605059
_historyText.Add (
5061-
[[.. GetCurrentLine ()]],
5060+
[ [.. GetCurrentLine ()]],
50625061
CursorPosition,
50635062
HistoryText.LineStatus.Replaced
50645063
);
@@ -5098,7 +5097,7 @@ private void KillToLeftStart ()
50985097
return;
50995098
}
51005099

5101-
_historyText.Add ([[.. currentLine]], CursorPosition);
5100+
_historyText.Add ([ [.. currentLine]], CursorPosition);
51025101

51035102
if (currentLine.Count == 0)
51045103
{
@@ -5165,7 +5164,7 @@ private void KillToLeftStart ()
51655164
}
51665165

51675166
_historyText.Add (
5168-
[[.. GetCurrentLine ()]],
5167+
[ [.. GetCurrentLine ()]],
51695168
CursorPosition,
51705169
HistoryText.LineStatus.Replaced
51715170
);
@@ -5189,14 +5188,14 @@ private void KillWordBackward ()
51895188

51905189
List<Cell> currentLine = GetCurrentLine ();
51915190

5192-
_historyText.Add ([[.. GetCurrentLine ()]], CursorPosition);
5191+
_historyText.Add ([ [.. GetCurrentLine ()]], CursorPosition);
51935192

51945193
if (CurrentColumn == 0)
51955194
{
51965195
DeleteTextBackwards ();
51975196

51985197
_historyText.ReplaceLast (
5199-
[[.. GetCurrentLine ()]],
5198+
[ [.. GetCurrentLine ()]],
52005199
CursorPosition,
52015200
HistoryText.LineStatus.Replaced
52025201
);
@@ -5235,7 +5234,7 @@ [[.. GetCurrentLine ()]],
52355234
}
52365235

52375236
_historyText.Add (
5238-
[[.. GetCurrentLine ()]],
5237+
[ [.. GetCurrentLine ()]],
52395238
CursorPosition,
52405239
HistoryText.LineStatus.Replaced
52415240
);
@@ -5257,14 +5256,14 @@ private void KillWordForward ()
52575256

52585257
List<Cell> currentLine = GetCurrentLine ();
52595258

5260-
_historyText.Add ([[.. GetCurrentLine ()]], CursorPosition);
5259+
_historyText.Add ([ [.. GetCurrentLine ()]], CursorPosition);
52615260

52625261
if (currentLine.Count == 0 || CurrentColumn == currentLine.Count)
52635262
{
52645263
DeleteTextForwards ();
52655264

52665265
_historyText.ReplaceLast (
5267-
[[.. GetCurrentLine ()]],
5266+
[ [.. GetCurrentLine ()]],
52685267
CursorPosition,
52695268
HistoryText.LineStatus.Replaced
52705269
);
@@ -5294,7 +5293,7 @@ [[.. GetCurrentLine ()]],
52945293
}
52955294

52965295
_historyText.Add (
5297-
[[.. GetCurrentLine ()]],
5296+
[ [.. GetCurrentLine ()]],
52985297
CursorPosition,
52995298
HistoryText.LineStatus.Replaced
53005299
);

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ 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 (tf.SelectedLength, tf.Text.Length);
151151
Assert.True (tf.NewKeyDownEvent (Key.E.WithCtrl));
152152
Assert.Equal (8, tf.CursorPosition);
153153
Assert.True (tf.NewKeyDownEvent (Key.CursorLeft));

0 commit comments

Comments
 (0)