Skip to content

feat(docs): named-range create / list / delete / replace-content commands #692

@sebsnyk

Description

@sebsnyk

Motivation

Named ranges are the API-native way to maintain a stable anchor inside a doc even as text around it changes. They survive edits to surrounding paragraphs in a way that "find text and compute index" does not. For round-trip workflows (a script writes content, later wants to update just one section), named ranges are the durable solution; text-based locate is a fallback.

The Docs API supports CreateNamedRange, DeleteNamedRange, and ReplaceNamedRangeContent. gog already emits CreateNamedRange via the sed bookmark brace ({B=name} in internal/cmd/docs_sed_brace_structural.go), and DeleteNamedRange is exposed in the sheets path (internal/cmd/sheets_named_ranges.go), but neither is reachable as a top-level docs subcommand. ReplaceNamedRangeContent is not emitted anywhere.

Depends on

Repro

# Today: no way to create a stable anchor; every update is "walk docs raw, find the text".

# Wanted:
gog docs named-range create <DOC_ID> --name=intro-paragraph --at="The introduction begins here."
# Later, regardless of edits above:
gog docs named-range replace <DOC_ID> --name=intro-paragraph --content="<markdown>"

Proposed surface

gog docs named-range create <docId> --name=<id> --at=<text>|--start=N --end=N
gog docs named-range list <docId> [--name=<id>]
gog docs named-range delete <docId> --name=<id>
gog docs named-range replace <docId> --name=<id> --content=<text> [--format=plain|markdown]

Acceptance criteria

  • Create wires to CreateNamedRange with the resolved range; returns the namedRangeId.
  • Delete uses DeleteNamedRange (new request type for the docs side).
  • Replace uses ReplaceNamedRangeContent (preferred) or DeleteContentRange + InsertText fallback when the named range covers complex content.
  • List returns the doc's namedRanges from documents.get.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal priority bug or improvement with limited blast radius.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions