зеркало из https://github.com/xamarin/XtermSharp.git
Merge pull request #75 from xamarin/fix-selection-crash
Fixes a crash when selecting word or expression
This commit is contained in:
Коммит
0c61b010aa
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче