Skip to content

Commit

Permalink
Fix crash due to negative caret index when computing text box triple …
Browse files Browse the repository at this point in the history
…click.

Fixes #854
  • Loading branch information
ScrubN committed Oct 15, 2023
1 parent 23f2615 commit 86cd00e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions TwitchDownloaderWPF/Behaviors/TextBoxTripleClickBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ private static (int start, int length) GetCurrentLine(TextBox textBox)
var caretPos = textBox.CaretIndex;
var text = textBox.Text;

var start = text.LastIndexOf('\n', caretPos, caretPos);
var end = text.IndexOf('\n', caretPos);
var start = -1;
var end = -1;

// CaretIndex can be negative for some reason.
if (caretPos >= 0)
{
start = text.LastIndexOf('\n', caretPos, caretPos);
end = text.IndexOf('\n', caretPos);
}

if (start == -1)
{
Expand Down

0 comments on commit 86cd00e

Please sign in to comment.