mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Implementing undo/redo to back tab key. (#1608)
This commit is contained in:
@@ -5575,6 +5575,91 @@ line.
|
||||
Assert.Equal (new Point (1, 1), tv.CursorPosition);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HistoryText_Undo_Redo_Multiline_Simples_Tab_BackTab ()
|
||||
{
|
||||
var text = "First line.\nSecond line.\nThird line.";
|
||||
var tv = new TextView () { Width = 80, Height = 5, Text = text };
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
|
||||
Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||||
Assert.Equal (3, tv.Lines);
|
||||
Assert.Equal (new Point (1, 0), tv.CursorPosition);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
|
||||
Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||||
Assert.Equal (3, tv.Lines);
|
||||
Assert.Equal (new Point (0, 0), tv.CursorPosition);
|
||||
|
||||
// Undo
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||||
Assert.Equal (3, tv.Lines);
|
||||
Assert.Equal (new Point (1, 0), tv.CursorPosition);
|
||||
Assert.True (tv.IsDirty);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||||
Assert.Equal (3, tv.Lines);
|
||||
Assert.Equal (new Point (0, 0), tv.CursorPosition);
|
||||
Assert.False (tv.IsDirty);
|
||||
|
||||
// Redo
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.Equal ($"\tFirst line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||||
Assert.Equal (3, tv.Lines);
|
||||
Assert.Equal (new Point (1, 0), tv.CursorPosition);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||||
Assert.Equal (3, tv.Lines);
|
||||
Assert.Equal (new Point (0, 0), tv.CursorPosition);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HistoryText_Undo_Redo_Multiline_Selected_Tab_BackTab ()
|
||||
{
|
||||
var text = "First line.\nSecond line.\nThird line.";
|
||||
var tv = new TextView () { Width = 80, Height = 5, Text = text };
|
||||
|
||||
tv.SelectionStartColumn = 6;
|
||||
tv.CursorPosition = new Point (6, 2);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
|
||||
Assert.Equal ("First \tline.", tv.Text);
|
||||
Assert.Equal (1, tv.Lines);
|
||||
Assert.Equal (new Point (7, 0), tv.CursorPosition);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.BackTab, new KeyModifiers ())));
|
||||
Assert.Equal ("First line.", tv.Text);
|
||||
Assert.Equal (1, tv.Lines);
|
||||
Assert.Equal (new Point (6, 0), tv.CursorPosition);
|
||||
|
||||
// Undo
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.Equal ("First \tline.", tv.Text);
|
||||
Assert.Equal (1, tv.Lines);
|
||||
Assert.Equal (new Point (7, 0), tv.CursorPosition);
|
||||
Assert.True (tv.IsDirty);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text);
|
||||
Assert.Equal (3, tv.Lines);
|
||||
Assert.Equal (new Point (6, 2), tv.CursorPosition);
|
||||
Assert.False (tv.IsDirty);
|
||||
|
||||
// Redo
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.Equal ("First \tline.", tv.Text);
|
||||
Assert.Equal (1, tv.Lines);
|
||||
Assert.Equal (new Point (7, 0), tv.CursorPosition);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.R | Key.CtrlMask, new KeyModifiers ())));
|
||||
Assert.Equal ("First line.", tv.Text);
|
||||
Assert.Equal (1, tv.Lines);
|
||||
Assert.Equal (new Point (6, 0), tv.CursorPosition);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HistoryText_ClearHistoryChanges ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user