Skip to content

Commit

Permalink
fix: restore isHitText #WIK-15721
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa committed Jun 27, 2024
1 parent 9bf80f4 commit 176c903
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
24 changes: 22 additions & 2 deletions packages/draw/src/utils/hit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ export const isRectangleHitElementText = (element: PlaitCommonGeometry, rectangl
}
};

export const isHitElementText = (element: PlaitCommonGeometry, point: Point) => {
const engine = getEngine<PlaitCommonGeometry>(element.shape);
if (isMultipleTextGeometry(element)) {
const texts = element.texts;
return texts.some(item => {
const textClient = engine.getTextRectangle!(element, { key: item.key });
return RectangleClient.isPointInRectangle(textClient, point);
});
} else {
const textClient = engine.getTextRectangle ? engine.getTextRectangle(element) : getTextRectangle(element);
return RectangleClient.isPointInRectangle(textClient, point);
}
};

export const isRectangleHitDrawElement = (board: PlaitBoard, element: PlaitElement, selection: Selection) => {
const rangeRectangle = RectangleClient.getRectangleByPoints([selection.anchor, selection.focus]);
if (PlaitDrawElement.isGeometry(element)) {
Expand Down Expand Up @@ -140,8 +154,8 @@ export const isHitDrawElement = (board: PlaitBoard, element: PlaitElement, point
const textClient = getTextRectangle(element);
return RectangleClient.isPointInRectangle(textClient, point);
}

return engine.isInsidePoint(rectangle!, point);
const isHitText = isHitElementText(element, point);
return isHitText || engine.isInsidePoint(rectangle!, point);
}
if (PlaitDrawElement.isImage(element)) {
const client = RectangleClient.getRectangleByPoints(element.points);
Expand Down Expand Up @@ -173,6 +187,12 @@ export const isHitElementInside = (board: PlaitBoard, element: PlaitElement, poi
if (isHitInside) {
return isHitInside;
}
if (engine.getTextRectangle) {
const isHitText = isHitElementText(element, point);
if (isHitText) {
return isHitText;
}
}
}
if (PlaitDrawElement.isImage(element)) {
const client = RectangleClient.getRectangleByPoints(element.points);
Expand Down
13 changes: 12 additions & 1 deletion src/app/components/setting-panel/setting-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ import { Node, Transforms as SlateTransforms } from 'slate';
import { AppColorPickerComponent } from '../color-picker/color-picker.component';
import { FormsModule } from '@angular/forms';
import { NgClass, NgIf } from '@angular/common';
import { AlignTransform, Alignment, CustomText, ParagraphElement, PropertyTransforms, getEditingTextEditor, getFirstTextEditor } from '@plait/common';
import {
AlignTransform,
Alignment,
CustomText,
ParagraphElement,
PropertyTransforms,
getEditingTextEditor,
getFirstTextEditor
} from '@plait/common';
import {
LineShape,
LineMarkerType,
Expand Down Expand Up @@ -223,6 +231,9 @@ export class AppSettingPanelComponent extends PlaitIslandBaseComponent implement
}

changeFill(property: string) {
if (!property) {
property = 'transparent';
}
PropertyTransforms.setFillColor(this.board, property, {
getMemorizeKey,
callback: (element: PlaitElement, path: Path) => {
Expand Down

0 comments on commit 176c903

Please sign in to comment.