Skip to content

Conversation

@mimecuvalo
Copy link
Member

@mimecuvalo mimecuvalo commented Dec 2, 2025

This deprecates setEditingShape, which is a bit too low-level/footgun-y in favor of a startEditingShape/stopEditingShape that has safer usage semantics.

Right now it's hard to start editing shape without doing several checks to make sure that you're safe to start editing.
It currently involves calling setEditingShape, transitioning or setting the current tool to EditingShape all while checking if we're in readonly mode and making sure the shape is editable (via the canEdit shape API check).

Addresses #7077

Change type

  • bugfix
  • improvement
  • feature
  • api
  • other

Test plan

  • Unit tests
  • End to end tests

Release notes

  • editor: add startEditingShape; deprecate setEditingShape

API changes

editor: add startEditingShape to better encapsulate proper ergonomics around doing an edit. deprecate setEditingShape


Note

Adds safer editing APIs startEditingShape/stopEditingShape (with options), deprecates setEditingShape, updates usages across editor, tools, shapes, examples, and tests, and adjusts related types/exports.

  • Editor API:
    • Add Editor.startEditingShape(shapeOrId?, { info, selectAll }) that validates editability, selects the shape, and transitions to select.editing_shape (emits select-all-text when requested).
    • Add Editor.stopEditingShape() to clear editing state.
    • Mark Editor.setEditingShape as @deprecated and route to internal setter.
  • Types/Exports:
    • Add TLStartEditingShapeOptions.
    • Move TLResizeShapeOptions to types/misc-types and export from index; remove duplicate definition in Editor.ts.
    • Update API report accordingly.
  • tldraw tools/shapes:
    • Replace all calls to setEditingShape with startEditingShape/stopEditingShape across select tool states, text/note/arrow/frame behaviors, and helpers (remove selectHelpers.ts).
    • Simplify edit-on-enter/double-click flows to use new API.
  • Examples:
    • Update cubic-bezier and exam-marking examples to use new APIs and maintain edit mode after interactions.
  • Tests:
    • Add unit tests for startEditingShape/stopEditingShape behavior and update existing tests to new APIs.

Written by Cursor Bugbot for commit 922d268. This will update automatically on new commits. Configure here.

@huppy-bot huppy-bot bot added api API change improvement Product improvement labels Dec 2, 2025
@vercel
Copy link

vercel bot commented Dec 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
analytics Ready Ready Preview Dec 3, 2025 10:16am
examples Ready Ready Preview Dec 3, 2025 10:16am
4 Skipped Deployments
Project Deployment Preview Updated (UTC)
tldraw-docs Ignored Ignored Preview Dec 3, 2025 10:16am
chat-template Skipped Skipped Dec 3, 2025 10:16am
tldraw-shader Skipped Skipped Dec 3, 2025 10:16am
workflow-template Skipped Skipped Dec 3, 2025 10:16am

this.emit('select-all-text', { shapeId: shape.id })
}

return true
Copy link
Collaborator

Choose a reason for hiding this comment

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

The pattern with Editor methods is to return the Editor class instance. I'd add a canEdit method here if the user needs to check, or else check after. Its annoying but that's the pattern, I'd rather not change it.

Copy link
Member Author

Choose a reason for hiding this comment

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

gotcha, we could still do a return this. i don't need to do the return true here

Comment on lines +2294 to +2298
this.setCurrentTool('select.editing_shape', {
...(options.info ?? {}),
target: 'shape',
shape,
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

select is a state that only exists at the tldraw level

Copy link
Member Author

Choose a reason for hiding this comment

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

hah! silly mistake

@steveruizok
Copy link
Collaborator

Hey, let me put up a PR that shows a different way of getting to the same outcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api API change improvement Product improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants