Fixes #1208. Now the selected text is overwritten if SelectedStart is greater than CursorPosition. (#1209)

This commit is contained in:
BDisp
2021-04-16 01:28:10 +01:00
committed by GitHub
parent cec9cc3559
commit 28580de3c5
2 changed files with 13 additions and 4 deletions

View File

@@ -829,7 +829,7 @@ namespace Terminal.Gui {
void SetSelectedStartSelectedLength ()
{
if (SelectedStart > -1 && point < SelectedStart) {
start = point - SelectedStart + SelectedStart;
start = point;
} else {
start = SelectedStart;
}
@@ -861,7 +861,8 @@ namespace Terminal.Gui {
void DeleteSelectedText ()
{
ustring actualText = Text;
int selStart = point < SelectedStart ? SelectedStart - point + SelectedStart : SelectedStart;
SetSelectedStartSelectedLength ();
int selStart = SelectedStart > -1 ? start : point;
(var _, var len) = TextModel.DisplaySize (text, 0, selStart, false);
(var _, var len2) = TextModel.DisplaySize (text, selStart, selStart + length, false);
(var _, var len3) = TextModel.DisplaySize (text, selStart + length, actualText.RuneCount, false);

View File

@@ -56,6 +56,16 @@ namespace Terminal.Gui {
Assert.Null (_textField.SelectedText);
}
[Fact]
public void SelectedStart_Greater_Than_CursorPosition_All_Selection_Is_Overwritten_On_Typing ()
{
_textField.SelectedStart = 19;
_textField.CursorPosition = 12;
Assert.Equal ("TAB to jump between text fields.", _textField.Text);
_textField.ProcessKey (new KeyEvent ((Key)0x75, new KeyModifiers ())); // u
Assert.Equal ("TAB to jump u text fields.", _textField.Text);
}
[Fact]
public void CursorPosition_With_Value_Less_Than_Zero_Changes_To_Zero ()
{
@@ -636,7 +646,6 @@ namespace Terminal.Gui {
Assert.Equal ("TAB to jumusep between text fields.", _textField.Text);
_textField.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
Assert.Equal ("TAB to jumusedp between text fields.", _textField.Text);
}
[Fact]
@@ -653,7 +662,6 @@ namespace Terminal.Gui {
Assert.Equal ("TAB to jumuseetween text fields.", _textField.Text);
_textField.ProcessKey (new KeyEvent ((Key)0x64, new KeyModifiers ())); // d
Assert.Equal ("TAB to jumusedtween text fields.", _textField.Text);
}
}
}