From 86cd00e92a1e7f523f49dce77114b8122de67877 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Sun, 15 Oct 2023 01:22:04 -0400 Subject: [PATCH] Fix crash due to negative caret index when computing text box triple click. Fixes #854 --- .../Behaviors/TextBoxTripleClickBehavior.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/TwitchDownloaderWPF/Behaviors/TextBoxTripleClickBehavior.cs b/TwitchDownloaderWPF/Behaviors/TextBoxTripleClickBehavior.cs index d4f097be..77c9d880 100644 --- a/TwitchDownloaderWPF/Behaviors/TextBoxTripleClickBehavior.cs +++ b/TwitchDownloaderWPF/Behaviors/TextBoxTripleClickBehavior.cs @@ -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) {