修改逻辑
This commit is contained in:
@@ -234,29 +234,26 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId";
|
|||||||
}
|
}
|
||||||
- (void)onTapDelete {
|
- (void)onTapDelete {
|
||||||
NSLog(@"点击:删除");
|
NSLog(@"点击:删除");
|
||||||
// 单次删除一个字符(从宿主 App 的文本框光标前)
|
|
||||||
UIInputViewController *ivc = [self findInputViewController];
|
UIInputViewController *ivc = [self findInputViewController];
|
||||||
id<UITextDocumentProxy> proxy = ivc.textDocumentProxy;
|
id<UITextDocumentProxy> proxy = ivc.textDocumentProxy;
|
||||||
[proxy deleteBackward];
|
[proxy deleteBackward];
|
||||||
}
|
}
|
||||||
- (void)onTapClear {
|
- (void)onTapClear {
|
||||||
NSLog(@"点击:清空");
|
NSLog(@"点击:清空");
|
||||||
// 连续删除,直到当前输入位置之前无文本
|
// 连续删除:仅清空光标之前的输入(不改动 pasteView 的内容)
|
||||||
UIInputViewController *ivc = [self findInputViewController];
|
UIInputViewController *ivc = [self findInputViewController];
|
||||||
id<UITextDocumentProxy> proxy = ivc.textDocumentProxy;
|
id<UITextDocumentProxy> proxy = ivc.textDocumentProxy;
|
||||||
// 为避免极端情况下的长时间阻塞,按块删除
|
// 逐批读取 documentContextBeforeInput 并删除,避免 50 字符窗口限制带来的残留
|
||||||
NSInteger guard = 0;
|
NSInteger guard = 0; // 上限保护,避免极端情况下长时间阻塞
|
||||||
while (proxy.hasText && guard < 10000) { // 合理的上限保护
|
while (guard < 10000) {
|
||||||
NSString *before = proxy.documentContextBeforeInput ?: @"";
|
NSString *before = proxy.documentContextBeforeInput ?: @"";
|
||||||
// 优先批量删除当前可见的 before 字符数
|
NSInteger count = before.length;
|
||||||
NSInteger count = before.length > 0 ? before.length : 1;
|
if (count <= 0) { break; } // 光标前已无内容
|
||||||
for (NSInteger i = 0; i < count; i++) {
|
for (NSInteger i = 0; i < count; i++) {
|
||||||
[proxy deleteBackward];
|
[proxy deleteBackward];
|
||||||
}
|
}
|
||||||
guard += count;
|
guard += count;
|
||||||
}
|
}
|
||||||
// 同步重置功能区里的占位文案
|
|
||||||
self.pasteView.placeholderLabel.text = @"点击粘贴TA的话";
|
|
||||||
}
|
}
|
||||||
- (void)onTapSend {
|
- (void)onTapSend {
|
||||||
NSLog(@"点击:发送");
|
NSLog(@"点击:发送");
|
||||||
|
|||||||
Reference in New Issue
Block a user