Skip to content

fix: 保留文本格式(换行和段落) - #71

Merged
minorcell merged 1 commit into
mainfrom
xgopilot/claude/issue-70-1764136656
Dec 4, 2025
Merged

minorcell merged 1 commit into
mainfrom
xgopilot/claude/issue-70-1764136656

Conversation

@minorcell

Copy link
Copy Markdown
Member

Requested by @minorcell

修复 #70:保存的文本内容现在能正确保留原始格式

问题描述

之前保存的文本内容会丢失格式,多个段落被压缩成一个段落,换行符也消失了。

修复方案

在文本显示组件中添加 CSS 属性 whiteSpace: "pre-wrap",该属性可以:

  • 保留文本中的换行符和空格
  • 自动换行以适应容器宽度
  • 保持原始文本的段落结构

修改文件

  1. src/components/ItemCard.tsx (第194行)

    • 在卡片视图的文本显示中添加 whiteSpace: "pre-wrap"
  2. src/components/ShareCard.tsx (第111行)

    • 在分享卡片的文本显示中添加 whiteSpace: "pre-wrap"
    • 确保导出的图片也能正确显示格式

测试建议

  1. 保存一段包含多个段落的文本(使用回车键分段)
  2. 在列表视图中查看是否保留了段落分隔
  3. 点击查看详情,确认完整格式正确
  4. 导出为图片,验证图片中的格式也正确

Generated with codeagent

- Add whiteSpace: 'pre-wrap' to ItemCard text display
- Add whiteSpace: 'pre-wrap' to ShareCard text display
- Fixes issue #70 where multi-paragraph text was compressed

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: minorcell <120795714+minorcell@users.noreply.github.com>
@minorcell minorcell mentioned this pull request Nov 26, 2025
@minorcell

Copy link
Copy Markdown
Member Author

Code Review Summary

Overall, this is a well-implemented fix with correct CSS usage. The whiteSpace: "pre-wrap" property appropriately preserves text formatting. No security or performance concerns identified.

Key Finding: Documentation gaps need addressing. The PR description should mention that ItemDialog.tsx already uses this pattern (lines 196, 272), and inline comments would help future maintainers understand why this property is critical for issue #70.

whiteSpace: "pre-wrap",
lineHeight: 1.9,
color: "text.primary",
pl: 2,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding an inline comment explaining why whiteSpace: "pre-wrap" is needed:

sx={{
  // Preserve line breaks and spaces to prevent text collapsing (fixes #70)
  whiteSpace: "pre-wrap",
  lineHeight: 1.9,
  // ...
}}

This helps future maintainers understand the purpose and prevents accidental removal.

whiteSpace: "pre-wrap",
fontFamily: "'Noto Serif SC', 'Songti SC', serif"
}}>
{truncateText(item.content, maxLength)}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as ItemCard.tsx - consider adding a comment:

wordBreak: "break-word",
// Preserve line breaks and spaces (fixes #70)
whiteSpace: "pre-wrap",
fontFamily: "'Noto Serif SC', 'Songti SC', serif"

This ensures the exported share card maintains consistent formatting with the display views.

@minorcell
minorcell merged commit 125cfbe into main Dec 4, 2025
2 checks passed
@minorcell
minorcell deleted the xgopilot/claude/issue-70-1764136656 branch December 4, 2025 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants