diff --git a/CustomKeyboard/View/KBFunctionView.m b/CustomKeyboard/View/KBFunctionView.m index b4a99c7..a0e69ef 100644 --- a/CustomKeyboard/View/KBFunctionView.m +++ b/CustomKeyboard/View/KBFunctionView.m @@ -161,6 +161,8 @@ make.top.equalTo(self.barViewInternal.mas_bottom).offset(0); make.height.mas_equalTo(smallH); }]; + // 点击整个粘贴卡片按钮,行为与右侧「Paste」按钮保持一致 + [self.pasteViewInternal.pasBtn addTarget:self action:@selector(onTapPaste) forControlEvents:UIControlEventTouchUpInside]; // 3. Tag List View [self addSubview:self.tagListView]; @@ -299,6 +301,24 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/ self.streamHasOutput = YES; } +/// 统一更新左侧粘贴按钮的展示: +/// - 有粘贴文本:只显示文字,不再展示左侧图标; +/// - 无粘贴文本:恢复原始图标 + 占位文案。 +- (void)kb_updatePasteButtonWithDisplayText:(NSString * _Nullable)text { + if (text.length > 0) { + NSString *displayText = text; + if (displayText.length > 30) { + displayText = [[displayText substringToIndex:30] stringByAppendingString:@"…"]; + } + [self.pasteView.pasBtn setImage:nil forState:UIControlStateNormal]; + [self.pasteView.pasBtn setTitle:displayText forState:UIControlStateNormal]; + } else { + UIImage *img = [UIImage imageNamed:@"kb_zt_icon"]; + [self.pasteView.pasBtn setImage:img forState:UIControlStateNormal]; + [self.pasteView.pasBtn setTitle:KBLocalized(@" Paste Ta's Words") forState:UIControlStateNormal]; + } +} + #pragma mark - KBFunctionTagListViewDelegate - (void)tagListView:(KBFunctionTagListView *)view didSelectIndex:(NSInteger)index title:(NSString *)title { @@ -415,15 +435,22 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C UIPasteboard *pb = [UIPasteboard generalPasteboard]; NSString *text = pb.string; // 读取纯文本(可能触发系统粘贴权限弹窗) - if (text.length > 0) { - // 将粘贴内容展示到左侧“粘贴区”的占位文案上 - self.pasteView.placeholderLabel.text = text; - // 如果需要多行展示,可按需放开(高度由外部约束决定,默认一行会截断) - // self.pasteView.placeholderLabel.numberOfLines = 0; - } else { + if (text.length <= 0) { // 无可用文本或用户拒绝了粘贴权限;保持占位文案不变 NSLog(@"粘贴板无可用文本或未授权粘贴"); + [KBHUD showInfo:KBLocalized(@"Clipboard is empty")]; + return; } + + // 1)把内容真正「粘贴」到当前输入框 + UIInputViewController *ivc = KBFindInputViewController(self); + if (ivc) { + id proxy = ivc.textDocumentProxy; + [proxy insertText:text]; + } + + // 2)顺便把最新的剪贴板内容展示在左侧粘贴区按钮上,便于用户确认 + [self kb_updatePasteButtonWithDisplayText:text]; } #pragma mark - 自动监控剪贴板(复制即弹窗) @@ -448,9 +475,8 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C // 实际读取触发系统弹窗(iOS16+) NSString *text = pb.string; - if (text.length > 0) { - self.pasteView.placeholderLabel.text = text; - } + // 有文字 -> 仅展示文字;无文字/非文本 -> 恢复图标 + 原占位文案 + [self kb_updatePasteButtonWithDisplayText:text]; }]; }