Skip to content

Commit

Permalink
fix: creating snap no work well when some graphics are selected
Browse files Browse the repository at this point in the history
  • Loading branch information
F-star committed Jan 13, 2025
1 parent b0ace07 commit 3b94d6b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
17 changes: 12 additions & 5 deletions packages/core/src/ref_line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ export class RefLine {
/**
* cache reference line of graphics in viewport
*/
cacheGraphicsRefLines() {
cacheGraphicsRefLines(
options: {
excludeItems: SuikaGraphics[];
} = {
excludeItems: [],
},
) {
this.clear();

const excludeItems = options.excludeItems;

const vRefLineMap = this.vRefLineMap;
const hRefLineMap = this.hRefLineMap;

const selectIdSet = this.editor.selectedElements.getIdSet();
const viewportBbox = this.editor.viewportManager.getBbox();

const refGraphicsSet = new Set<SuikaGraphics>();
Expand All @@ -71,17 +78,17 @@ export class RefLine {
refGraphicsSet.add(graphics);
});

const selectedItems = this.editor.selectedElements.getItems();
for (const selectedItem of selectedItems) {
for (const selectedItem of excludeItems) {
selectedItem.forEachVisibleChildNode((graphics) => {
if (refGraphicsSet.has(graphics)) {
refGraphicsSet.delete(graphics);
}
});
}

const excludeIdSet = new Set(excludeItems.map((item) => item.attrs.id));
for (const graphics of refGraphicsSet) {
if (selectIdSet.has(graphics.attrs.id)) {
if (excludeIdSet.has(graphics.attrs.id)) {
continue;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/tools/tool_draw_graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export abstract class DrawGraphicsTool implements ITool {
return;
}
if (this.isDragging) {
this.editor.refLine.cacheGraphicsRefLines();
this.editor.refLine.cacheGraphicsRefLines({
excludeItems: this.editor.selectedElements.getItems(),
});
}
};
const updateRectWhenViewportTranslate = () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/tools/tool_select/tool_select_move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export class SelectMoveTool implements IBaseTool {
this.prevBBoxPos = { x: boundingRect.x, y: boundingRect.y };
}

this.editor.refLine.cacheGraphicsRefLines();
this.editor.refLine.cacheGraphicsRefLines({
excludeItems: this.selectedItems,
});
}
onDrag(e: PointerEvent) {
this.dragPoint = this.editor.getCursorXY(e);
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/tools/tool_select/tool_select_resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ export class SelectResizeTool implements IBaseTool {
this.editor.selectedElements.getItems()[0].getRotate() % HALF_PI === 0);

if (!this.lastDragPoint) {
this.editor.refLine.cacheGraphicsRefLines();
this.editor.refLine.cacheGraphicsRefLines({
excludeItems: this.editor.selectedElements.getItems(),
});
}
this.lastDragPoint = this.editor.getSceneCursorXY(e);

Expand Down

0 comments on commit 3b94d6b

Please sign in to comment.