diff --git a/CustomKeyboard/Network/KBStreamFetcher.m b/CustomKeyboard/Network/KBStreamFetcher.m index c7264a2..822b05e 100644 --- a/CustomKeyboard/Network/KBStreamFetcher.m +++ b/CustomKeyboard/Network/KBStreamFetcher.m @@ -289,6 +289,15 @@ static NSUInteger kb_validUTF8PrefixLen(NSData *data) { - (void)emitChunk:(NSString *)rawText { if (rawText.length == 0) return; NSString *text = rawText; + // 0) 规范化换行与段起始:去掉位于片段开头的 \r/\n;将 "\n\t"、"\r\n\t"、"\r\t" 归一为 "\t" + text = [text stringByReplacingOccurrencesOfString:@"\r\n\t" withString:@"\t"]; + text = [text stringByReplacingOccurrencesOfString:@"\n\t" withString:@"\t"]; + text = [text stringByReplacingOccurrencesOfString:@"\r\t" withString:@"\t"]; + while (text.length > 0) { + unichar c0 = [text characterAtIndex:0]; + if (c0 == '\n' || c0 == '\r') { text = [text substringFromIndex:1]; continue; } + break; + } // 1) 统一处理 “/t” -> “\t” if (self.treatSlashTAsTab) { text = [text stringByReplacingOccurrencesOfString:@"/t" withString:@"\t"]; diff --git a/CustomKeyboard/View/KBFunctionView.m b/CustomKeyboard/View/KBFunctionView.m index 24ecba2..916cf5c 100644 --- a/CustomKeyboard/View/KBFunctionView.m +++ b/CustomKeyboard/View/KBFunctionView.m @@ -99,7 +99,7 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId"; // 右侧竖排按钮容器 [self addSubview:self.rightButtonContainer]; [self.rightButtonContainer mas_makeConstraints:^(MASConstraintMaker *make) { - make.right.equalTo(self.mas_right).offset(-12); + make.right.equalTo(self.mas_right).offset(-6); make.top.equalTo(self.barViewInternal.mas_bottom).offset(8); make.bottom.equalTo(self.mas_bottom).offset(-10); make.width.mas_equalTo(72); @@ -208,10 +208,15 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId"; [self addSubview:overlay]; [overlay mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.mas_left).offset(12); - make.right.equalTo(self.rightButtonContainer.mas_left).offset(-12); + // 流式期间占满右侧宽度:不再贴 rightButtonContainer,让文本有最大宽度 + make.right.equalTo(self.mas_right).offset(-12); make.top.equalTo(self.pasteViewInternal.mas_bottom).offset(10); make.bottom.equalTo(self.mas_bottom).offset(-10); }]; + // 隐藏右侧按钮栏,最大化文本宽度;关闭 overlay 时再恢复 + self.rightButtonContainer.hidden = YES; + // 适当缩小内部左右留白,进一步提升可用宽度 + overlay.textView.contentHorizontalPadding = 8.0; self.streamOverlay = overlay; // 只创建 UI;网络在点击 cell 时启动,避免重复 start 导致首包重复 @@ -223,6 +228,8 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId"; [self.streamOverlay removeFromSuperview]; self.streamOverlay = nil; self.tagListView.hidden = NO; + // 恢复右侧按钮栏 + self.rightButtonContainer.hidden = NO; } // 叠层关闭回调