From 4f23118ec05ee424ed529be7210d035a155d451a Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Thu, 30 Oct 2025 18:28:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomKeyboard/View/KBFunctionView.m | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) 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(@"点击:发送");