Merge pull request #75 from xamarin/fix-selection-crash

Fixes a crash when selecting word or expression
This commit is contained in:
Miguel de Icaza 2020-04-29 11:02:56 -04:00 коммит произвёл GitHub
Родитель 16efd01a6f 252509147b
Коммит 0c61b010aa
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 41 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,32 @@
using Xunit;
namespace XtermSharp.Tests.BufferTests {
public class SelectionTests {
[Fact]
public void DoesNotCrashWhenSelectingWordOrExpressionOutsideColumnRange ()
{
var terminal = new Terminal (null, new TerminalOptions { Rows = 10, Cols = 10 });
var selection = new SelectionService (terminal);
terminal.Feed ("1234567890");
// depending on the size of terminal view, there might be a space near the margin where the user
// clicks which might result in a col or row outside the bounds of terminal,
selection.SelectWordOrExpression (-1, 0);
selection.SelectWordOrExpression (11, 0);
}
[Fact]
public void DoesNotCrashWhenSelectingWordOrExpressionOutsideRowRange ()
{
var terminal = new Terminal (null, new TerminalOptions { Rows = 10, Cols = 10, Scrollback = 0 });
var selection = new SelectionService (terminal);
terminal.Feed ("1234567890");
// depending on the size of terminal view, there might be a space near the margin where the user
// clicks which might result in a col or row outside the bounds of terminal,
selection.SelectWordOrExpression (0, -1);
}
}
}

Просмотреть файл

@ -124,6 +124,9 @@ namespace XtermSharp {
return CharData.Null;
}
if (col >= bufferRow.Length || col < 0)
return CharData.Null;
return bufferRow [col];
}

Просмотреть файл

@ -166,9 +166,14 @@ namespace XtermSharp {
/// </summary>
public void SelectWordOrExpression(int col, int row)
{
row += terminal.Buffer.YDisp;
var buffer = terminal.Buffer;
// ensure the bounds are inside the terminal.
row = Math.Max (row, 0);
col = Math.Max (Math.Min (col, terminal.Buffer.Cols), 0);
row += buffer.YDisp;
Func<CharData, bool> isLetterOrChar = (cd) => {
if (cd.IsNullChar ())
return false;