Skip to content

feat(docs): auto-resize table column widths based on content#59

Open
SoIomon wants to merge 1 commit intolarksuite:mainfrom
SoIomon:feat/table-auto-width
Open

feat(docs): auto-resize table column widths based on content#59
SoIomon wants to merge 1 commit intolarksuite:mainfrom
SoIomon:feat/table-auto-width

Conversation

@SoIomon
Copy link
Copy Markdown

@SoIomon SoIomon commented Mar 29, 2026

Summary

  • Automatically adjusts table column widths after docs +create and docs +update based on cell content length
  • CJK/fullwidth characters count as 2 units, ASCII as 1, with cell padding compensation
  • Per-column widths clamped to [80px, 400px], total normalized to fit 700px container via two-pass scaling (second pass scales proportionally without min-floor to guarantee total ≤ container)
  • Each column updated via a separate PATCH call (batch_update silently ignores multiple ops on the same table in a single request)
  • Supports text, heading (h1-h7), bullet, ordered list, and todo block types in width calculation
  • Falls back gracefully on API errors — non-fatal warning only, main operation unaffected
  • Adds docx:document:readonly and docx:document:write_only to docs +create scopes — required to read back block structure and apply column-width patches after document creation

Before / After

Before (equal width) After (auto-sized)
Doc Before After

Files changed

  • table_auto_width.go — core logic: fetch blocks, calculate widths, normalize, update via API
  • table_auto_width_test.go — unit tests for width calculation, CJK handling, and normalization
  • docs_create.go / docs_update.go — call autoResizeTableColumns() after doc creation/update

Test plan

  • go build ./... passes
  • go test ./shortcuts/doc/... passes
  • Visual verification on Feishu: 3-table demo doc with mixed CJK/ASCII content

@SoIomon SoIomon force-pushed the feat/table-auto-width branch 4 times, most recently from edbd440 to 07c42ae Compare March 29, 2026 13:34
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 30, 2026

CLA assistant check
All committers have signed the CLA.

- After +create and +update, calculate optimal column widths from cell content
- CJK/fullwidth characters count as 2 units, ASCII as 1, with cell padding
- Clamp per-column widths to [80px, 400px]; normalize total to fit 700px container via two-pass scaling (second pass scales proportionally without min-floor to guarantee total ≤ container)
- Skip update if computed widths are unchanged (avoids redundant PATCH calls)
- Skip auto-resize in +update if markdown contains no tables (including borderless GFM tables: `A | B\n---|---\n1|2`)
- Support text, heading, bullet, ordered, todo block types; handle rich inline elements (mention_doc, equation, link_preview, etc.)
- Recursive cell traversal with cycle detection for nested block structures
- Each column updated via separate PATCH (batch_update ignores multiple ops on same table)
- Falls back gracefully on API errors (non-fatal warning only)
- Adds docx:document:readonly and docx:document:write_only to docs +create scopes (required to read blocks and apply column-width patches post-creation)
@SoIomon SoIomon force-pushed the feat/table-auto-width branch from 07c42ae to 4edfa57 Compare March 30, 2026 10:12
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