mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
chore(editor): improve index of new edgeless note from dnd (#12357)
Close [BS-3500](https://linear.app/affine-design/issue/BS-3500/剪刀没问题了,通过拖动形成的段落能不能也有同样的表现?) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved the behavior when dragging blocks between notes, ensuring that new note blocks are inserted as siblings when appropriate, instead of always creating them at the root level. - **Tests** - Enhanced and enabled tests to verify correct drag-and-drop behavior across multiple notes and to ensure the relative order of note content is preserved during drag operations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
import {
|
||||
captureEventTarget,
|
||||
type DropTarget as DropResult,
|
||||
findNoteBlockModel,
|
||||
getBlockComponentsExcludeSubtrees,
|
||||
getRectByBlockComponent,
|
||||
getScrollContainer,
|
||||
@@ -1247,20 +1248,50 @@ export class DragEventWatcher {
|
||||
console.error
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// create note to wrap the snapshot
|
||||
const noteId = store.addBlock(
|
||||
'affine:note',
|
||||
{
|
||||
xywh: new Bound(
|
||||
point.x,
|
||||
point.y,
|
||||
DEFAULT_NOTE_WIDTH,
|
||||
DEFAULT_NOTE_HEIGHT
|
||||
).serialize(),
|
||||
},
|
||||
this.widget.store.root!
|
||||
);
|
||||
}
|
||||
// create note to wrap the snapshot
|
||||
else {
|
||||
const originalModel = store.getModelById(snapshot.content[0].id);
|
||||
const originalNote = originalModel
|
||||
? findNoteBlockModel(originalModel)
|
||||
: null;
|
||||
|
||||
let noteId: string;
|
||||
if (originalNote) {
|
||||
const placement =
|
||||
originalNote.children[0].id === snapshot.content[0].id
|
||||
? 'before'
|
||||
: 'after';
|
||||
|
||||
noteId = store.addSiblingBlocks(
|
||||
originalNote,
|
||||
[
|
||||
{
|
||||
flavour: 'affine:note',
|
||||
xywh: new Bound(
|
||||
point.x,
|
||||
point.y,
|
||||
DEFAULT_NOTE_WIDTH,
|
||||
DEFAULT_NOTE_HEIGHT
|
||||
).serialize(),
|
||||
},
|
||||
],
|
||||
placement
|
||||
)[0];
|
||||
} else {
|
||||
noteId = store.addBlock(
|
||||
'affine:note',
|
||||
{
|
||||
xywh: new Bound(
|
||||
point.x,
|
||||
point.y,
|
||||
DEFAULT_NOTE_WIDTH,
|
||||
DEFAULT_NOTE_HEIGHT
|
||||
).serialize(),
|
||||
},
|
||||
this.widget.store.root!
|
||||
);
|
||||
}
|
||||
|
||||
this._dropToModel(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user