Skip to content

Commit

Permalink
perf(editor): optimize the search for the closest element
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Jan 8, 2025
1 parent 39f4b17 commit 288e37d
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 187 deletions.
9 changes: 5 additions & 4 deletions blocksuite/affine/block-attachment/src/attachment-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ export class AttachmentBlockService extends BlockService {

export const AttachmentDropOption = FileDropConfigExtension({
flavour: AttachmentBlockSchema.model.flavour,
onDrop: ({ files, targetModel, place, point, std }) => {
onDrop: ({ files, targetModel, placement, point, std }) => {
if (!targetModel) return false;

// generic attachment block for all files except images
const attachmentFiles = files.filter(
file => !file.type.startsWith('image/')
);

if (!attachmentFiles.length) return false;

if (targetModel && !matchFlavours(targetModel, ['affine:surface'])) {
if (!matchFlavours(targetModel, ['affine:surface'])) {
addSiblingAttachmentBlocks(
std.host,
attachmentFiles,
// TODO: use max file size from service
maxFileSize,
targetModel,
place
placement
).catch(console.error);

return true;
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/block-database/src/database-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent<
const model = this.doc.getBlock(id)?.model;
const target = result.modelState.model;
let parent = this.doc.getParent(target.id);
const shouldInsertIn = result.type === 'in';
const shouldInsertIn = result.placement === 'in';
if (shouldInsertIn) {
parent = target;
}
Expand All @@ -274,7 +274,7 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent<
[model],
parent,
target,
result.type === 'before'
result.placement === 'before'
);
}
}
Expand Down
8 changes: 5 additions & 3 deletions blocksuite/affine/block-image/src/image-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ export class ImageBlockService extends BlockService {

export const ImageDropOption = FileDropConfigExtension({
flavour: ImageBlockSchema.model.flavour,
onDrop: ({ files, targetModel, place, point, std }) => {
onDrop: ({ files, targetModel, placement, point, std }) => {
if (!targetModel) return false;

const imageFiles = files.filter(file => file.type.startsWith('image/'));
if (!imageFiles.length) return false;

if (targetModel && !matchFlavours(targetModel, ['affine:surface'])) {
if (!matchFlavours(targetModel, ['affine:surface'])) {
addSiblingImageBlock(
std.host,
imageFiles,
// TODO: use max file size from service
maxFileSize,
targetModel,
place
placement
);
return true;
}
Expand Down
Loading

0 comments on commit 288e37d

Please sign in to comment.