Fixes #1963. Only remove one character on backspace when wordwrap is on (#1964)

* 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:
Jeff Greene
2022-09-05 07:16:32 -07:00
committed by GitHub
parent c6af956e22
commit bbbacf4514
2 changed files with 234 additions and 13 deletions

View File

@@ -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);
}
}
}