This commit is contained in:
2025-12-16 21:43:00 +08:00
parent b43567748c
commit 5bd20a911f
4 changed files with 28 additions and 8 deletions

View File

@@ -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];
}