From fecb1396d2ddfd9dff3fb3c25ea4bdcbaf8d10fc Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Sat, 28 May 2016 01:53:33 -0500 Subject: [PATCH] Fixes bug where pasting into EditCheatViewController's UITextView resulted in incorrect font --- Delta/Pause Menu/Cheats/EditCheatViewController.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Delta/Pause Menu/Cheats/EditCheatViewController.swift b/Delta/Pause Menu/Cheats/EditCheatViewController.swift index 3eb1b9c..1af15b1 100644 --- a/Delta/Pause Menu/Cheats/EditCheatViewController.swift +++ b/Delta/Pause Menu/Cheats/EditCheatViewController.swift @@ -390,7 +390,13 @@ extension EditCheatViewController: UITextViewDelegate guard sanitizedText != text else { return true } - textView.textStorage.replaceCharactersInRange(range, withString: sanitizedText) + // We need to manually add back the attributes when manually modifying the underlying text storage + // Otherwise, pasting text into an empty text view will result in the wrong font being used + let attributedString = NSAttributedString(string: sanitizedText, attributes: textView.typingAttributes) + textView.textStorage.replaceCharactersInRange(range, withAttributedString: attributedString) + + // We must add attributedString.length, not range.length, in case the attributed string's length differs + textView.selectedRange = NSRange(location: range.location + attributedString.length, length: 0) return false }