Skip to content

Commit

Permalink
Fixes gui-cs#3022 & adds unit test to prove it
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Dec 1, 2023
1 parent 538066f commit a044013
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Terminal.Gui/Views/TextField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,9 @@ Attribute GetReadOnlyColor ()

void Adjust ()
{
if (!IsAdded)
if (!IsAdded) {
return;
}

int offB = OffSetBackground ();
bool need = NeedsDisplay || !Used;
Expand Down Expand Up @@ -1180,6 +1181,7 @@ void PrepareSelection (int x, int direction = 0)
} else if (_start > -1 && _length == 0) {
_selectedText = null;
}
SetNeedsDisplay ();
} else if (_length > 0 || _selectedText != null) {
ClearAllSelection ();
}
Expand Down
28 changes: 27 additions & 1 deletion UnitTests/Views/TextViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -35,7 +36,7 @@ public override void Before (MethodInfo methodUnderTest)
// 01234567890123456789012345678901=32 (Length)
var buff = Encoding.Unicode.GetBytes (txt);
var ms = new System.IO.MemoryStream (buff).ToArray ();
_textView = new TextView () { Width = 30, Height = 10 };
_textView = new TextView () { Width = 30, Height = 10, ColorScheme = Colors.Base};
_textView.Text = Encoding.Unicode.GetString (ms);
}

Expand Down Expand Up @@ -273,6 +274,31 @@ public void WordBackward_With_No_Selection ()
}
}

[Fact]
[TextViewTestsAutoInitShutdown]
public void Selected_Text_Shows ()
{
// Proves #3022 is fixed (TextField selected text does not show in v2)
_textView.CursorPosition = new Point (0, 0);
_textView.SelectionStartColumn = 0;
_textView.SelectionStartRow = 0;

var attributes = new Attribute [] {
_textView.ColorScheme.Focus,
new Attribute(_textView.ColorScheme.Focus.Background, _textView.ColorScheme.Focus.Foreground)
};

_textView.OnDrawContent(_textView.Bounds);
// TAB to jump between text fields.
TestHelpers.AssertDriverColorsAre ("0000000", driver: Application.Driver, attributes);

_textView.ProcessKeyPressed (new (Key.CursorRight | Key.CtrlMask | Key.ShiftMask, new KeyModifiers ()));

_textView.OnDrawContent (_textView.Bounds);
// TAB to jump between text fields.
TestHelpers.AssertDriverColorsAre ("1111000", driver: Application.Driver, attributes);
}

[Fact]
[TextViewTestsAutoInitShutdown]
public void WordForward_With_Selection ()
Expand Down

0 comments on commit a044013

Please sign in to comment.