diff options
author | Pell Smit <pellsmit@gmail.com> | 2014-08-14 15:20:58 +0900 |
---|---|---|
committer | Pell Smit <pellsmit@gmail.com> | 2014-08-14 15:20:58 +0900 |
commit | e2370f6f2d6c794f74622b379321fafd60f8e8ff (patch) | |
tree | d41390ebdc57414fae1e44ddd3f6e27e94160d73 /indra | |
parent | b021c90e7bccdd0f9a916946e7716a00034254c2 (diff) |
fixed: inline backspace bug
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llwindow/llopenglview-objc.mm | 71 |
1 files changed, 49 insertions, 22 deletions
diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 017ea3769c..e07fc2bd42 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -472,31 +472,58 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange { - if ([aString class] == NSClassFromString(@"NSConcreteMutableAttributedString")) + // Apple says aString can be either an NSString or NSAttributedString instance. + // But actually it's NSConcreteMutableAttributedString or __NSCFConstantString. + // I observed aString was __NSCFConstantString only aString was null string(zero length). + // Apple also says when aString is an NSString object, + // the receiver is expected to render the marked text with distinguishing appearance. + // So I tried to make attributedStringInfo, but it won't be used... (Pell Smit) + + if (mMarkedTextAllowed) { - if (mMarkedTextAllowed) + unsigned int selected[2] = { + selectedRange.location, + selectedRange.length + }; + + unsigned int replacement[2] = { + replacementRange.location, + replacementRange.length + }; + + int string_length = [aString length]; + unichar text[string_length]; + attributedStringInfo segments; + // I used 'respondsToSelector:@selector(string)' + // to judge aString is an attributed string or not. + if ([aString respondsToSelector:@selector(string)]) + { + // aString is attibuted + [[aString string] getCharacters:text range:NSMakeRange(0, string_length)]; + segments = getSegments((NSAttributedString *)aString); + } + else + { + // aString is not attributed + [aString getCharacters:text range:NSMakeRange(0, string_length)]; + segments.seg_lengths.push_back(string_length); + segments.seg_standouts.push_back(true); + } + setMarkedText(text, selected, replacement, string_length, segments); + if (string_length > 0) { - unsigned int selected[2] = { - selectedRange.location, - selectedRange.length - }; - - unsigned int replacement[2] = { - replacementRange.location, - replacementRange.length - }; - - unichar text[[aString length]]; - [[aString mutableString] getCharacters:text range:NSMakeRange(0, [aString length])]; - attributedStringInfo segments = getSegments((NSAttributedString *)aString); - setMarkedText(text, selected, replacement, [aString length], segments); mHasMarkedText = TRUE; - mMarkedTextLength = [aString length]; - } else { - if (mHasMarkedText) - { - [self unmarkText]; - } + mMarkedTextLength = string_length; + } + else + { + // we must clear the marked text when aString is null. + [self unmarkText]; + } + } else { + if (mHasMarkedText) + { + [self unmarkText]; } } } |