Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Instance Methods | Properties | List of all members
FlutterTokenizer Class Reference

#include <FlutterTextInputPlugin.h>

Inheritance diagram for FlutterTokenizer:

Instance Methods

(instancetype) - initWithTextInput: [implementation]
 
(UITextRange *) - rangeEnclosingPosition:withGranularity:inDirection: [implementation]
 
(UITextRange *) - lineEnclosingPosition:inDirection: [implementation]
 

Properties

FlutterTextInputViewtextInputView [implementation]
 

Detailed Description

A tokenizer used by FlutterTextInputView to customize string parsing.

Definition at line 90 of file FlutterTextInputPlugin.h.

Method Documentation

◆ initWithTextInput:

- (instancetype) initWithTextInput: (UIResponder<UITextInput>*)  textInput
implementation

Definition at line 581 of file FlutterTextInputPlugin.mm.

587 :(UIResponder<UITextInput>*)textInput {
588 NSAssert([textInput isKindOfClass:[FlutterTextInputView class]],
589 @"The FlutterTokenizer can only be used in a FlutterTextInputView");
590 self = [super initWithTextInput:textInput];
591 if (self) {
592 _textInputView = (FlutterTextInputView*)textInput;
593 }
594 return self;
595}

◆ lineEnclosingPosition:inDirection:

- (UITextRange *) lineEnclosingPosition: (UITextPosition*)  position
inDirection: (UITextDirection)  direction 
implementation

Definition at line 581 of file FlutterTextInputPlugin.mm.

621 :(UITextPosition*)position
622 inDirection:(UITextDirection)direction {
623 // TODO(hellohuanlin): remove iOS 17 check. The same logic should apply to older iOS version.
624 if (@available(iOS 17.0, *)) {
625 // According to the API doc if the text position is at a text-unit boundary, it is considered
626 // enclosed only if the next position in the given direction is entirely enclosed. Link:
627 // https://developer.apple.com/documentation/uikit/uitextinputtokenizer/1614464-rangeenclosingposition?language=objc
628 FlutterTextPosition* flutterPosition = (FlutterTextPosition*)position;
629 if (flutterPosition.index > _textInputView.text.length ||
630 (flutterPosition.index == _textInputView.text.length &&
631 direction == UITextStorageDirectionForward)) {
632 return nil;
633 }
634 }
635
636 // Gets the first line break position after the input position.
637 NSString* textAfter = [_textInputView
638 textInRange:[_textInputView textRangeFromPosition:position
639 toPosition:[_textInputView endOfDocument]]];
640 NSArray<NSString*>* linesAfter = [textAfter componentsSeparatedByString:@"\n"];
641 NSInteger offSetToLineBreak = [linesAfter firstObject].length;
642 UITextPosition* lineBreakAfter = [_textInputView positionFromPosition:position
643 offset:offSetToLineBreak];
644 // Gets the first line break position before the input position.
645 NSString* textBefore = [_textInputView
646 textInRange:[_textInputView textRangeFromPosition:[_textInputView beginningOfDocument]
647 toPosition:position]];
648 NSArray<NSString*>* linesBefore = [textBefore componentsSeparatedByString:@"\n"];
649 NSInteger offSetFromLineBreak = [linesBefore lastObject].length;
650 UITextPosition* lineBreakBefore = [_textInputView positionFromPosition:position
651 offset:-offSetFromLineBreak];
652
653 return [_textInputView textRangeFromPosition:lineBreakBefore toPosition:lineBreakAfter];
654}
if(end==-1)

◆ rangeEnclosingPosition:withGranularity:inDirection:

- (UITextRange *) rangeEnclosingPosition: (UITextPosition*)  position
withGranularity: (UITextGranularity)  granularity
inDirection: (UITextDirection)  direction 
implementation

Definition at line 581 of file FlutterTextInputPlugin.mm.

597 :(UITextPosition*)position
598 withGranularity:(UITextGranularity)granularity
599 inDirection:(UITextDirection)direction {
600 UITextRange* result;
601 switch (granularity) {
602 case UITextGranularityLine:
603 // The default UITextInputStringTokenizer does not handle line granularity
604 // correctly. We need to implement our own line tokenizer.
605 result = [self lineEnclosingPosition:position inDirection:direction];
606 break;
607 case UITextGranularityCharacter:
608 case UITextGranularityWord:
609 case UITextGranularitySentence:
610 case UITextGranularityParagraph:
611 case UITextGranularityDocument:
612 // The UITextInputStringTokenizer can handle all these cases correctly.
613 result = [super rangeEnclosingPosition:position
614 withGranularity:granularity
615 inDirection:direction];
616 break;
617 }
618 return result;
619}
GAsyncResult * result

Property Documentation

◆ textInputView

- (FlutterTextInputView*) textInputView
readwritenonatomicweakimplementation

Provided by category FlutterTokenizer().

Definition at line 581 of file FlutterTextInputPlugin.mm.


The documentation for this class was generated from the following files: