Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Terminal.Gui/Views/TextField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ public override Rect Frame {
}
return;
}
ClearAllSelection ();
text = TextModel.ToRunes (newText.NewText);

if (!Secret && !historyText.IsFromHistory) {
Expand Down
27 changes: 27 additions & 0 deletions UnitTests/TextFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,5 +1296,32 @@ public void HistoryText_IsDirty_ClearHistoryChanges ()
Assert.Equal ($"{text}A", tf.Text);
Assert.True (tf.IsDirty);
}

[InlineData ("a")] // Lower than selection
[InlineData ("aaaaaaaaaaa")] // Greater than selection
[InlineData ("aaaa")] // Equal than selection
[Theory]
public void TestSetTextAndMoveCursorToEnd_WhenExistingSelection (string newText)
{
var tf = new TextField ();
tf.Text = "fish";
tf.CursorPosition = tf.Text.Length;

tf.ProcessKey (new KeyEvent (Key.CursorLeft, new KeyModifiers ()));

tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers { Shift = true }));
tf.ProcessKey (new KeyEvent (Key.CursorLeft | Key.ShiftMask, new KeyModifiers { Shift = true }));

Assert.Equal (1, tf.CursorPosition);
Assert.Equal (2, tf.SelectedLength);
Assert.Equal ("is", tf.SelectedText);

tf.Text = newText;
tf.CursorPosition = tf.Text.Length;

Assert.Equal (newText.Length, tf.CursorPosition);
Assert.Equal (0, tf.SelectedLength);
Assert.Null (tf.SelectedText);
}
}
}