mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
* Fixed double delete when wordwrap is enabled * Fixes #1963. Deletes multiple characters editing a TextView with WordWrap enabled. Co-authored-by: BDisp <bd.bdisp@gmail.com> Co-authored-by: Tig Kindel <tig@users.noreply.github.com>
This commit is contained in:
@@ -6044,5 +6044,231 @@ d
|
||||
line.
|
||||
", output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void DeleteTextBackwards_WordWrap_False_Return_Undo ()
|
||||
{
|
||||
const string text = "This is the first line.\nThis is the second line.\n";
|
||||
var tv = new TextView () {
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
Text = text
|
||||
};
|
||||
var envText = tv.Text;
|
||||
Application.Top.Add (tv);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
Assert.False (tv.WordWrap);
|
||||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
This is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
tv.CursorPosition = new Point (3, 0);
|
||||
Assert.Equal (new Point (3, 0), tv.CursorPosition);
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (2, 0), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
tv.CursorPosition = new Point (0, 1);
|
||||
Assert.Equal (new Point (0, 1), tv.CursorPosition);
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (22, 0), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.This is the second line.
|
||||
", output);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (0, 1), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
while (tv.Text != envText) {
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
|
||||
}
|
||||
Assert.Equal (envText, tv.Text);
|
||||
Assert.Equal (new Point (3, 0), tv.CursorPosition);
|
||||
Assert.False (tv.IsDirty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void DeleteTextBackwards_WordWrap_True_Return_Undo ()
|
||||
{
|
||||
const string text = "This is the first line.\nThis is the second line.\n";
|
||||
var tv = new TextView () {
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
Text = text,
|
||||
WordWrap = true
|
||||
};
|
||||
var envText = tv.Text;
|
||||
Application.Top.Add (tv);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
Assert.True (tv.WordWrap);
|
||||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
This is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
tv.CursorPosition = new Point (3, 0);
|
||||
Assert.Equal (new Point (3, 0), tv.CursorPosition);
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (2, 0), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
tv.CursorPosition = new Point (0, 1);
|
||||
Assert.Equal (new Point (0, 1), tv.CursorPosition);
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Backspace, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (22, 0), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.This is the second line.
|
||||
", output);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (0, 1), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
while (tv.Text != envText) {
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
|
||||
}
|
||||
Assert.Equal (envText, tv.Text);
|
||||
Assert.Equal (new Point (3, 0), tv.CursorPosition);
|
||||
Assert.False (tv.IsDirty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void DeleteTextForwards_WordWrap_False_Return_Undo ()
|
||||
{
|
||||
const string text = "This is the first line.\nThis is the second line.\n";
|
||||
var tv = new TextView () {
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
Text = text
|
||||
};
|
||||
var envText = tv.Text;
|
||||
Application.Top.Add (tv);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
Assert.False (tv.WordWrap);
|
||||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
This is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
tv.CursorPosition = new Point (2, 0);
|
||||
Assert.Equal (new Point (2, 0), tv.CursorPosition);
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (2, 0), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
tv.CursorPosition = new Point (22, 0);
|
||||
Assert.Equal (new Point (22, 0), tv.CursorPosition);
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (22, 0), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.This is the second line.
|
||||
", output);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (0, 1), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
while (tv.Text != envText) {
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
|
||||
}
|
||||
Assert.Equal (envText, tv.Text);
|
||||
Assert.Equal (new Point (2, 0), tv.CursorPosition);
|
||||
Assert.False (tv.IsDirty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void DeleteTextForwards_WordWrap_True_Return_Undo ()
|
||||
{
|
||||
const string text = "This is the first line.\nThis is the second line.\n";
|
||||
var tv = new TextView () {
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
Text = text,
|
||||
WordWrap = true
|
||||
};
|
||||
var envText = tv.Text;
|
||||
Application.Top.Add (tv);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
Assert.True (tv.WordWrap);
|
||||
Assert.Equal (Point.Empty, tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
This is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
tv.CursorPosition = new Point (2, 0);
|
||||
Assert.Equal (new Point (2, 0), tv.CursorPosition);
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (2, 0), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
tv.CursorPosition = new Point (22, 0);
|
||||
Assert.Equal (new Point (22, 0), tv.CursorPosition);
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.DeleteChar, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (22, 0), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.This is the second line.
|
||||
", output);
|
||||
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
|
||||
tv.Redraw (tv.Bounds);
|
||||
Assert.Equal (new Point (0, 1), tv.CursorPosition);
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (@"
|
||||
Ths is the first line.
|
||||
This is the second line.
|
||||
", output);
|
||||
|
||||
while (tv.Text != envText) {
|
||||
Assert.True (tv.ProcessKey (new KeyEvent (Key.Z | Key.CtrlMask, new KeyModifiers ())));
|
||||
}
|
||||
Assert.Equal (envText, tv.Text);
|
||||
Assert.Equal (new Point (2, 0), tv.CursorPosition);
|
||||
Assert.False (tv.IsDirty);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user