From 62a953539434aad4d67ee80970f614246a2328dc Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 24 Oct 2020 11:26:29 -0400 Subject: [PATCH] Fix crash when ending dictation in Compose CW field Closes #116 --- Tusker/Screens/Compose/ComposeContentWarningTextField.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tusker/Screens/Compose/ComposeContentWarningTextField.swift b/Tusker/Screens/Compose/ComposeContentWarningTextField.swift index 70059cee..973ccd59 100644 --- a/Tusker/Screens/Compose/ComposeContentWarningTextField.swift +++ b/Tusker/Screens/Compose/ComposeContentWarningTextField.swift @@ -147,6 +147,10 @@ struct ComposeContentWarningTextField: UIViewRepresentable { let selectedRangeStartUTF16 = textField.offset(from: textField.beginningOfDocument, to: selectedRange.start) let cursorIndex = text.utf16.index(text.startIndex, offsetBy: selectedRangeStartUTF16) + guard cursorIndex != text.startIndex else { + return nil + } + var lastWordStartIndex = text.index(before: cursorIndex) while true { let c = text[lastWordStartIndex]