Skip to content

Commit 239a3cd

Browse files
authored
fix sticky notes preserving attribution via nib cloning (tldraw#8614)
issue was: sticky notes would grab the attribution from the prev author when cloning via a "nib" ### Change type - [x] `bugfix` - [ ] `improvement` - [ ] `feature` - [ ] `api` - [ ] `other` ### Test plan - [x] Unit tests - [ ] End to end tests ### Release notes - fix sticky notes preserving attribution via nib cloning
1 parent 57020af commit 239a3cd

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

packages/tldraw/src/lib/shapes/note/noteCloning.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,64 @@ it('Creates an adjacent note when dragging the clone handle', () => {
230230
editor.expectToBeIn('select.editing_shape')
231231
})
232232

233+
describe('Clone handles and attribution', () => {
234+
function createNoteWithAttribution() {
235+
editor.createShape({ type: 'note', x: 1000, y: 1000 })
236+
const shape = editor.getLastCreatedShape<TLNoteShape>()!
237+
editor.updateShape<TLNoteShape>({
238+
id: shape.id,
239+
type: 'note',
240+
props: { richText: toRichText('hello world') },
241+
})
242+
const updated = editor.getShape<TLNoteShape>(shape.id)!
243+
// Sanity check - the source note has attribution set
244+
expect(updated.props.textFirstEditedBy).not.toBeNull()
245+
return updated
246+
}
247+
248+
it('Does not preserve textFirstEditedBy when creating an adjacent note via click', () => {
249+
const shape = createNoteWithAttribution()
250+
251+
editor.select(shape.id)
252+
const handle = editor.getShapeHandles(shape.id)![1]
253+
editor
254+
.pointerDown(handle.x, handle.y, {
255+
target: 'handle',
256+
shape,
257+
handle,
258+
})
259+
.expectToBeIn('select.pointing_handle')
260+
.pointerUp()
261+
262+
const newShape = editor.getLastCreatedShape<TLNoteShape>()
263+
expect(newShape.id).not.toBe(shape.id)
264+
expect(newShape.props.textFirstEditedBy).toBeNull()
265+
})
266+
267+
it('Does not preserve textFirstEditedBy when creating an adjacent note via drag', () => {
268+
const shape = createNoteWithAttribution()
269+
270+
editor.select(shape.id)
271+
const handle = editor.getShapeHandles(shape.id)![1]
272+
editor
273+
.pointerDown(handle.x, handle.y, {
274+
target: 'handle',
275+
shape,
276+
handle,
277+
})
278+
.expectToBeIn('select.pointing_handle')
279+
.pointerMove(handle.x + 30, handle.y + 30)
280+
.forceTick()
281+
.expectToBeIn('select.translating')
282+
283+
const newShape = editor.getLastCreatedShape<TLNoteShape>()
284+
expect(newShape.id).not.toBe(shape.id)
285+
expect(newShape.props.textFirstEditedBy).toBeNull()
286+
287+
editor.pointerUp()
288+
})
289+
})
290+
233291
it('Does not put the new shape into a frame if its center is not in the frame', () => {
234292
editor.createShape({ type: 'frame', x: 1321, y: 1000 }) // one pixel too far...
235293
const frameA = editor.getLastCreatedShape()!

packages/tldraw/src/lib/shapes/note/noteHelpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ export function getNoteShapeForAdjacentPosition(
232232
growY: 0,
233233
fontSizeAdjustment: 1,
234234
url: '',
235+
textFirstEditedBy: null,
235236
},
236237
})
237238

0 commit comments

Comments
 (0)