From f0cb69948e29b10a7bd8d9671ae3e7fa3bd16041 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Wed, 11 Feb 2026 19:40:41 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomKeyboard/KeyboardViewController.m | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CustomKeyboard/KeyboardViewController.m b/CustomKeyboard/KeyboardViewController.m index 420c07e..9576f35 100644 --- a/CustomKeyboard/KeyboardViewController.m +++ b/CustomKeyboard/KeyboardViewController.m @@ -102,6 +102,7 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, @property(nonatomic, strong) NSMutableArray *chatMessages; @property(nonatomic, strong) AVAudioPlayer *chatAudioPlayer; @property(nonatomic, assign) BOOL chatPanelVisible; +@property(nonatomic, copy) NSString *chatPanelBaselineText; // 打开聊天面板时宿主输入框已有的文本 @property(nonatomic, strong, nullable) id kb_fullAccessObserverToken; @property(nonatomic, strong, nullable) id kb_skinObserverToken; @end @@ -563,6 +564,9 @@ static NSString *KBFormatMB(uint64_t bytes) { } self.chatPanelVisible = show; if (show) { + // 记录打开聊天面板时宿主输入框已有的文本,发送时只取新增部分 + [[KBInputBufferManager shared] refreshFromProxyIfPossible:self.textDocumentProxy]; + self.chatPanelBaselineText = [KBInputBufferManager shared].liveText ?: @""; [self kb_ensureChatPanelViewIfNeeded]; self.chatPanelView.hidden = NO; self.chatPanelView.alpha = 0.0; @@ -1033,7 +1037,15 @@ static NSString *KBFormatMB(uint64_t bytes) { return; } [[KBInputBufferManager shared] refreshFromProxyIfPossible:self.textDocumentProxy]; - NSString *rawText = [KBInputBufferManager shared].liveText ?: @""; + NSString *fullText = [KBInputBufferManager shared].liveText ?: @""; + + // 去掉打开聊天面板前宿主输入框里已有的基线文本,只取新增部分 + NSString *baseline = self.chatPanelBaselineText ?: @""; + NSString *rawText = fullText; + if (baseline.length > 0 && [fullText hasPrefix:baseline]) { + rawText = [fullText substringFromIndex:baseline.length]; + } + NSString *trim = [rawText stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; @@ -1042,6 +1054,7 @@ static NSString *KBFormatMB(uint64_t bytes) { return; } [self kb_sendChatText:trim]; + // 只清除新增的文本,保留基线文本 [self kb_clearHostInputForText:rawText]; }