Skip to content

feat(docs): auto-resize table column widths after document create/update#56

Closed
SoIomon wants to merge 2 commits intolarksuite:mainfrom
SoIomon:feat/table-auto-width
Closed

feat(docs): auto-resize table column widths after document create/update#56
SoIomon wants to merge 2 commits intolarksuite:mainfrom
SoIomon:feat/table-auto-width

Conversation

@SoIomon
Copy link
Copy Markdown

@SoIomon SoIomon commented Mar 29, 2026

Summary

When creating or updating documents via docs +create or docs +update, table columns are rendered with equal widths regardless of content. This PR adds automatic column width calculation based on cell content, similar to how spreadsheet applications auto-fit column widths.

Changes

  • New file: table_auto_width.go — Post-processing logic that:

    • Fetches all document blocks after creation/update
    • Identifies table blocks
    • Calculates optimal column widths based on content (CJK chars = 2 units, ASCII = 1 unit)
    • Calls batch_update API to apply computed widths
    • Min width: 80px, Max width: 400px, Total constraint: ~700px
  • New file: table_auto_width_test.go — Unit tests for width calculation, wide character detection, and pixel width constraints

  • Modified: docs_create.go — Calls autoResizeTableColumns() after successful document creation

  • Modified: docs_update.go — Calls autoResizeTableColumns() after overwrite/append mode updates

Design decisions

  • Non-blocking degradation: If post-processing fails, only a warning is printed — document creation is never affected
  • Reuses existing patterns: Uses runtime.CallAPI consistent with doc_media_insert.go

Test plan

  • go build ./... passes
  • go test ./shortcuts/doc/... passes
  • Manual test: create document with mixed CJK/ASCII tables and verify column widths

After creating or updating a document via MCP, post-process all table
blocks to calculate optimal column widths based on cell content. CJK
and fullwidth characters count as 2 units, ASCII as 1. Column widths
are clamped between 80px and 400px and normalized to fit within the
700px document container. Failures are non-fatal (degrade to equal
width with a warning).
@SoIomon
Copy link
Copy Markdown
Author

SoIomon commented Mar 29, 2026

实现有 bug,修复后重新提交

@SoIomon SoIomon closed this Mar 29, 2026
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.

1 participant