未验证 提交 d589ddea 编写于 作者: D Dan Field 提交者: GitHub

Fix text range logic for a11y (#16496)

Make sure that a text range at the end of the string is still valid.
上级 5c70356a
......@@ -7,7 +7,7 @@
namespace fml {
NSRange RangeForCharacterAtIndex(NSString* text, NSUInteger index) {
if (text == nil || index >= text.length) {
if (text == nil || index > text.length) {
return NSMakeRange(NSNotFound, 0);
}
if (index < text.length)
......
......@@ -28,3 +28,8 @@ TEST(StringRangeSanitizationTest, CanHandleUnicodeRange) {
EXPECT_EQ(result.location, 0UL);
EXPECT_EQ(result.length, 0UL);
}
TEST(StringRangeSanitizationTest, HandlesEndOfRange) {
EXPECT_EQ(fml::RangeForCharacterAtIndex(@"1234", 4).location, 4UL);
EXPECT_EQ(fml::RangeForCharacterAtIndex(@"1234", 4).length, 0UL);
}
......@@ -312,7 +312,13 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) {
}
- (NSString*)textInRange:(UITextRange*)range {
if (!range) {
return nil;
}
NSAssert([range isKindOfClass:[FlutterTextRange class]],
@"Expected a FlutterTextRange for range (got %@).", [range class]);
NSRange textRange = ((FlutterTextRange*)range).range;
NSAssert(textRange.location != NSNotFound, @"Expected a valid text range.");
return [self.text substringWithRange:textRange];
}
......
......@@ -23,7 +23,13 @@
}
- (NSString*)textInRange:(UITextRange*)range {
if (!range) {
return nil;
}
NSAssert([range isKindOfClass:[FlutterTextRange class]],
@"Expected a FlutterTextRange for range (got %@).", [range class]);
NSRange textRange = ((FlutterTextRange*)range).range;
NSAssert(textRange.location != NSNotFound, @"Expected a valid text range.");
return [self.text substringWithRange:textRange];
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册