From bb7ccaedf960688b29d76ce39aef077189c36e83 Mon Sep 17 00:00:00 2001 From: zhengzhijie Date: Tue, 26 May 2026 14:52:58 +0800 Subject: [PATCH] fix(sheets): warn when +dropdown source-range exceeds 2000 cells with highlight on MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit byted-sheet's ListFromRangeValidation.checkOptionsValid() sets isOptionError=true when shouldHighlightValidData is on and the source range exceeds LIST_WITH_COLOR_MAX_COUNT (2000 cells) — the highlight + large source combo is unsupported. CLI previously had no signal for this, so users only learned by seeing the dropdown render as option-error in the workbook. Add a Validate-phase stderr warning in +dropdown-set and +dropdown-update when --source-range covers >2000 cells unless --highlight=false. Soft warning, never blocks the request. Inline --options is not subject to this limit — server enforces no count or per-item length cap on inline lists, so no warning fires there. --- shortcuts/sheets/lark_sheet_batch_update.go | 1 + shortcuts/sheets/lark_sheet_write_cells.go | 46 ++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/shortcuts/sheets/lark_sheet_batch_update.go b/shortcuts/sheets/lark_sheet_batch_update.go index 6cef40721..223ab08dd 100644 --- a/shortcuts/sheets/lark_sheet_batch_update.go +++ b/shortcuts/sheets/lark_sheet_batch_update.go @@ -335,6 +335,7 @@ var DropdownUpdate = common.Shortcut{ if _, err := validateDropdownSourceOrOptions(runtime); err != nil { return err } + warnDropdownSourceRangeHighlight(runtime) return nil }, DryRun: func(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI { diff --git a/shortcuts/sheets/lark_sheet_write_cells.go b/shortcuts/sheets/lark_sheet_write_cells.go index b3233c8e3..9f0930930 100644 --- a/shortcuts/sheets/lark_sheet_write_cells.go +++ b/shortcuts/sheets/lark_sheet_write_cells.go @@ -271,7 +271,13 @@ var DropdownSet = common.Shortcut{ AuthTypes: []string{"user", "bot"}, HasFormat: true, Flags: flagsFor("+dropdown-set"), - Validate: validateViaInput(dropdownSetInput), + Validate: func(ctx context.Context, runtime *common.RuntimeContext) error { + if err := validateViaInput(dropdownSetInput)(ctx, runtime); err != nil { + return err + } + warnDropdownSourceRangeHighlight(runtime) + return nil + }, DryRun: func(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI { token, _ := resolveSpreadsheetToken(runtime) sheetID, sheetName, _ := resolveSheetSelector(runtime) @@ -434,6 +440,44 @@ func validateDropdownSourceOrOptions(runtime flagView) (int, error) { return sourceSize, nil } +// dropdownSourceRangeHighlightLimit is the cell-count cap above which the +// server marks the dropdown's options as invalid when highlight is on. +// Source: byted-sheet core LIST_WITH_COLOR_MAX_COUNT +// (sheet-packages/.../dataValidation/list/ListFromRangeValidation.ts:49). +// Beyond this, ListFromRangeValidation.checkOptionsValid() sets +// isOptionError=true (highlight + range > 2000 is an unsupported combo). +const dropdownSourceRangeHighlightLimit = 2000 + +// warnDropdownSourceRangeHighlight emits a soft stderr warning when the user +// targets a --source-range larger than dropdownSourceRangeHighlightLimit while +// highlight is on (the server-side default and the most common path). +// Inline --options is not subject to this limit (server has no inline count +// or per-item length cap; only the listFromRange + highlight combo is). +// Validate phase only — never blocks the request. Caller must already have +// confirmed the source-or-options validation passed. +func warnDropdownSourceRangeHighlight(runtime *common.RuntimeContext) { + sourceRange := strings.TrimSpace(runtime.Str("source-range")) + if sourceRange == "" { + return // inline --options mode — no server-side size cap applies + } + // highlight is tri-state: omitted = ON (server default), --highlight=true + // = ON, --highlight=false = OFF. Only the OFF case avoids the warning. + if runtime.Changed("highlight") && !runtime.Bool("highlight") { + return + } + rows, cols, err := rangeDimensions(sourceRange) + if err != nil { + return // already errored upstream; don't double-report + } + cellCount := rows * cols + if cellCount <= dropdownSourceRangeHighlightLimit { + return + } + fmt.Fprintf(runtime.IO().ErrOut, + "warning: --source-range covers %d cells; server marks the dropdown as option-error when highlight is on and the source exceeds %d cells. Pass --highlight=false to suppress this.\n", + cellCount, dropdownSourceRangeHighlightLimit) +} + // ─── range parsing helpers ──────────────────────────────────────────── // rangeDimensions parses an A1 range like "A1:C5" / "A1" / "sheet1!B2:D10"