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