|
@@ -886,5 +886,208 @@ namespace Terminal.Gui.Views {
|
|
|
Assert.False (fv.CanFocus);
|
|
|
Assert.False (fv.HasFocus);
|
|
|
}
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ [AutoInitShutdown]
|
|
|
+ public void KeyBindings_Command ()
|
|
|
+ {
|
|
|
+ var tf = new TextField ("This is a test.") { Width = 20 };
|
|
|
+ Assert.Equal (15, tf.Text.Length);
|
|
|
+ Assert.Equal (15, tf.CursorPosition);
|
|
|
+ Assert.False (tf.ReadOnly);
|
|
|
+
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("This is a test.", tf.Text);
|
|
|
+ tf.CursorPosition = 0;
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("his is a test.", tf.Text);
|
|
|
+ tf.ReadOnly = true;
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.D | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("his is a test.", tf.Text);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Delete, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("his is a test.", tf.Text);
|
|
|
+ tf.ReadOnly = false;
|
|
|
+ tf.CursorPosition = 1;
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ tf.CursorPosition = 5;
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("is is", tf.SelectedText);
|
|
|
+ tf.CursorPosition = 5;
|
|
|
+ tf.SelectedStart = -1;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("is is", tf.SelectedText);
|
|
|
+ tf.CursorPosition = 5;
|
|
|
+ tf.SelectedStart = -1;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.A | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("is is", tf.SelectedText);
|
|
|
+ tf.CursorPosition = 5;
|
|
|
+ tf.SelectedStart = -1;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (" a test.", tf.SelectedText);
|
|
|
+ tf.CursorPosition = 5;
|
|
|
+ tf.SelectedStart = -1;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (" a test.", tf.SelectedText);
|
|
|
+ tf.CursorPosition = 5;
|
|
|
+ tf.SelectedStart = -1;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.E | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (" a test.", tf.SelectedText);
|
|
|
+ tf.CursorPosition = 5;
|
|
|
+ tf.SelectedStart = -1;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (0, tf.CursorPosition);
|
|
|
+ tf.CursorPosition = 5;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Home | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (0, tf.CursorPosition);
|
|
|
+ tf.CursorPosition = 5;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.A | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (0, tf.CursorPosition);
|
|
|
+ tf.CursorPosition = 5;
|
|
|
+ tf.SelectedStart = -1;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("s", tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("is", tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("s", tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ tf.CursorPosition = 7;
|
|
|
+ tf.SelectedStart = -1;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("a", tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("is a", tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.ShiftMask | Key.AltMask), new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("is is a", tf.SelectedText);
|
|
|
+ tf.CursorPosition = 3;
|
|
|
+ tf.SelectedStart = -1;
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("is ", tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.ShiftMask | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("is a ", tf.SelectedText);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.ShiftMask | Key.AltMask), new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal ("is a test.", tf.SelectedText);
|
|
|
+ Assert.Equal (13, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Null (tf.SelectedText);
|
|
|
+ Assert.Equal (12, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (11, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (13, tf.CursorPosition);
|
|
|
+ tf.CursorPosition = 0;
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.End | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (13, tf.CursorPosition);
|
|
|
+ tf.CursorPosition = 0;
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.E | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (13, tf.CursorPosition);
|
|
|
+ tf.CursorPosition = 0;
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (1, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.F | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.Equal (2, tf.CursorPosition);
|
|
|
+ tf.CursorPosition = 9;
|
|
|
+ tf.ReadOnly = true;
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ tf.ReadOnly = false;
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.Equal ("est.", Clipboard.Contents);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.AltMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a test.", tf.Text);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Y | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.Equal (8, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorUp | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.Equal (6, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'B' + Key.AltMask), new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.Equal (3, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorRight | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.Equal (6, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.CursorDown | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.Equal (8, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent ((Key)((int)'F' + Key.AltMask), new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.Equal (9, tf.CursorPosition);
|
|
|
+ Assert.True (tf.Used);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.InsertChar, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.Equal (9, tf.CursorPosition);
|
|
|
+ Assert.False (tf.Used);
|
|
|
+ tf.SelectedStart = 3;
|
|
|
+ tf.CursorPosition = 7;
|
|
|
+ Assert.Equal ("is a", tf.SelectedText);
|
|
|
+ Assert.Equal ("est.", Clipboard.Contents);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.C | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.Equal ("is a", Clipboard.Contents);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.X | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is t", tf.Text);
|
|
|
+ Assert.Equal ("is a", Clipboard.Contents);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.V | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("is is a t", tf.Text);
|
|
|
+ Assert.Equal ("is a", Clipboard.Contents);
|
|
|
+ Assert.Equal (7, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.K | Key.AltMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal (" t", tf.Text);
|
|
|
+ Assert.Equal ("is is a", Clipboard.Contents);
|
|
|
+ tf.Text = "TAB to jump between text fields.";
|
|
|
+ Assert.Equal (0, tf.CursorPosition);
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.DeleteChar | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("to jump between text fields.", tf.Text);
|
|
|
+ tf.CursorPosition = tf.Text.Length;
|
|
|
+ Assert.True (tf.ProcessKey (new KeyEvent (Key.Backspace | Key.CtrlMask, new KeyModifiers ())));
|
|
|
+ Assert.Equal ("to jump between text ", tf.Text);
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+}
|