修改UI
This commit is contained in:
@@ -346,10 +346,28 @@ static inline NSString *KBTrimRight(NSString *s) {
|
||||
if (ivc) {
|
||||
id<UITextDocumentProxy> proxy = ivc.textDocumentProxy;
|
||||
if ([proxy conformsToProtocol:@protocol(UITextDocumentProxy)]) {
|
||||
NSString *context = proxy.documentContextBeforeInput ?: @"";
|
||||
for (NSUInteger i = 0; i < context.length; i++) {
|
||||
[proxy deleteBackward];
|
||||
// 若用户把光标放在中间,需要同时删掉光标前后的内容再插入分片
|
||||
BOOL canAdjustCaret = [proxy respondsToSelector:@selector(adjustTextPositionByCharacterOffset:)];
|
||||
if (canAdjustCaret) {
|
||||
NSString *contextAfter = proxy.documentContextAfterInput ?: @"";
|
||||
while (contextAfter.length > 0) {
|
||||
NSInteger offset = (NSInteger)contextAfter.length;
|
||||
[proxy adjustTextPositionByCharacterOffset:offset];
|
||||
for (NSUInteger i = 0; i < contextAfter.length; i++) {
|
||||
[proxy deleteBackward];
|
||||
}
|
||||
contextAfter = proxy.documentContextAfterInput ?: @"";
|
||||
}
|
||||
}
|
||||
|
||||
NSString *contextBefore = proxy.documentContextBeforeInput ?: @"";
|
||||
while (contextBefore.length > 0) {
|
||||
for (NSUInteger i = 0; i < contextBefore.length; i++) {
|
||||
[proxy deleteBackward];
|
||||
}
|
||||
contextBefore = proxy.documentContextBeforeInput ?: @"";
|
||||
}
|
||||
|
||||
if (rawText.length > 0) {
|
||||
[proxy insertText:rawText];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user