commit 062424aeffe0cc696f1c0c33b7e4521b211648b0
parent bc6a47a87654aaa416101353d0a5f7ed184c7249
Author: cfillion <cfillion@users.noreply.github.com>
Date: Fri, 19 Aug 2016 01:40:47 -0400
richedit: clear the textview on osx before filling with new contents
Diffstat:
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/richedit.mm b/src/richedit.mm
@@ -52,6 +52,11 @@ bool RichEdit::setRichText(const string &rtf)
NSTextView *textView = (NSTextView *)handle();
+ // Manually clear the view so that invalid content will always result
+ // in this function to return false. Without this, the old text would be
+ // retained, length would stay the same and we would return true.
+ [textView setString: @""];
+
[textView
replaceCharactersInRange: NSMakeRange(0, [[textView string] length])
withRTF: [str dataUsingEncoding: NSUTF8StringEncoding]
@@ -59,10 +64,10 @@ bool RichEdit::setRichText(const string &rtf)
// auto-detect links, equivalent to Windows' EM_AUTOURLDETECT message
const BOOL isEditable = textView.isEditable;
- [textView setEditable:YES];
- [textView setEnabledTextCheckingTypes:NSTextCheckingTypeLink];
- [textView checkTextInDocument:nil];
- [textView setEditable:isEditable];
+ [textView setEditable: YES];
+ [textView setEnabledTextCheckingTypes: NSTextCheckingTypeLink];
+ [textView checkTextInDocument: nil];
+ [textView setEditable: isEditable];
return [[textView string] length];
}