Skip to content

Commit

Permalink
ISSUE #5198 - fix names
Browse files Browse the repository at this point in the history
  • Loading branch information
Amantini1997 committed Oct 15, 2024
1 parent ff7f48d commit b82e96b
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ export const TypingHandler = ({
selected, mode, stage, layer, boxRef, fontSize, size, color, onRefreshDrawingLayer, onAddNewText
}: IProps) => {
const [visible, setVisible] = useState<boolean>(false);
const [styles, setStyles] = useState<CSSProperties>({});
const [offset, setOffset] = useState<CSSProperties>({});
const [positionLocked, setPositionLocked] = useState<boolean>(false);
const [maxSizes, setMaxSizes] = useState({ maxWidth: 0, maxHeight: 0 });
const isCallout = !!boxRef;

useEffect(() => {
if (stage) {
Expand All @@ -63,15 +64,15 @@ export const TypingHandler = ({
left = position.x - layer.x();
top = position.y - layer.y();
}
setStyles({ top, left });
setOffset({ top, left });
const { width, height } = stage.attrs;
setMaxSizes({
maxWidth: width - left,
maxHeight: height - top,
});
};

const recomputeTextBoxSizeAndRefresh = ({ width, height }) => {
const redrawCalloutBox = ({ width, height }) => {
if (!isEmpty(boxRef) && onRefreshDrawingLayer) {
boxRef.width(width + Math.max(6, size * 2));
boxRef.height(height + Math.max(6, size * 2));
Expand All @@ -86,12 +87,12 @@ export const TypingHandler = ({
};

useEffect(() => {
if (!isEmpty(boxRef) && !isEmpty(styles) && onRefreshDrawingLayer) {
boxRef.x(Number(styles.left) - Math.max(3, size));
boxRef.y(Number(styles.top) - Math.max(3, size));
if (!isEmpty(boxRef) && !isEmpty(offset) && onRefreshDrawingLayer) {
boxRef.x(Number(offset.left) - Math.max(3, size));
boxRef.y(Number(offset.top) - Math.max(3, size));
onRefreshDrawingLayer();
}
}, [styles]);
}, [offset]);

const handleClick = useCallback(() => {
setTextPosition();
Expand All @@ -100,7 +101,7 @@ export const TypingHandler = ({
}, []);

const onTextChange = (newText: string, width: number) => {
onAddNewText({ x: styles.left, y: styles.top }, newText, width);
onAddNewText({ x: offset.left, y: offset.top }, newText, width);
setVisible(false);
setPositionLocked(false);
};
Expand All @@ -111,11 +112,11 @@ export const TypingHandler = ({

return (
<EditableText
onChange={recomputeTextBoxSizeAndRefresh}
onChange={redrawCalloutBox}
onAddText={onTextChange}
onClick={handleClick}
styles={{
...styles,
...offset,
color,
fontSize: `${fontSize}px`,
visibility: visible ? 'visible' : 'hidden',
Expand Down

0 comments on commit b82e96b

Please sign in to comment.