fix: revert separate event handler mousedown
This commit is contained in:
@@ -38,18 +38,6 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
const lastMousePosition = useRef<Coordinates>({ x: 0, y: 0 });
|
const lastMousePosition = useRef<Coordinates>({ x: 0, y: 0 });
|
||||||
//const lastWheelPosition = useRef<ScrollDeltas>({ deltaX: 0, deltaY: 0 });
|
//const lastWheelPosition = useRef<ScrollDeltas>({ deltaX: 0, deltaY: 0 });
|
||||||
|
|
||||||
const handleMouseEventForGetText = useCallback((event: MouseEvent) => {
|
|
||||||
if (socket && getText) {
|
|
||||||
switch (event.type) {
|
|
||||||
case 'mousedown':
|
|
||||||
console.log('Handling text selection logic');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [socket, getText]);
|
|
||||||
|
|
||||||
const onMouseEvent = useCallback((event: MouseEvent) => {
|
const onMouseEvent = useCallback((event: MouseEvent) => {
|
||||||
if (socket) {
|
if (socket) {
|
||||||
const coordinates = {
|
const coordinates = {
|
||||||
@@ -59,8 +47,11 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case 'mousedown':
|
case 'mousedown':
|
||||||
const clickCoordinates = getMappedCoordinates(event, canvasRef.current, width, height);
|
const clickCoordinates = getMappedCoordinates(event, canvasRef.current, width, height);
|
||||||
|
if (getText === true) {
|
||||||
|
console.log('get text')
|
||||||
|
} else {
|
||||||
socket.emit('input:mousedown', clickCoordinates);
|
socket.emit('input:mousedown', clickCoordinates);
|
||||||
notifyLastAction('click');
|
}
|
||||||
break;
|
break;
|
||||||
case 'mousemove':
|
case 'mousemove':
|
||||||
const coordinates = getMappedCoordinates(event, canvasRef.current, width, height);
|
const coordinates = getMappedCoordinates(event, canvasRef.current, width, height);
|
||||||
@@ -91,7 +82,7 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [socket]);
|
}, [socket, getText]);
|
||||||
|
|
||||||
const onKeyboardEvent = useCallback((event: KeyboardEvent) => {
|
const onKeyboardEvent = useCallback((event: KeyboardEvent) => {
|
||||||
if (socket) {
|
if (socket) {
|
||||||
@@ -114,13 +105,7 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (canvasRef.current) {
|
if (canvasRef.current) {
|
||||||
onCreateRef(canvasRef);
|
onCreateRef(canvasRef);
|
||||||
|
canvasRef.current.addEventListener('mousedown', onMouseEvent);
|
||||||
const combinedMouseEventHandler = (event: MouseEvent) => {
|
|
||||||
onMouseEvent(event);
|
|
||||||
handleMouseEventForGetText(event);
|
|
||||||
};
|
|
||||||
|
|
||||||
canvasRef.current.addEventListener('mousedown', combinedMouseEventHandler);
|
|
||||||
canvasRef.current.addEventListener('mousemove', onMouseEvent);
|
canvasRef.current.addEventListener('mousemove', onMouseEvent);
|
||||||
canvasRef.current.addEventListener('wheel', onMouseEvent, { passive: true });
|
canvasRef.current.addEventListener('wheel', onMouseEvent, { passive: true });
|
||||||
canvasRef.current.addEventListener('keydown', onKeyboardEvent);
|
canvasRef.current.addEventListener('keydown', onKeyboardEvent);
|
||||||
@@ -128,7 +113,7 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (canvasRef.current) {
|
if (canvasRef.current) {
|
||||||
canvasRef.current.removeEventListener('mousedown', combinedMouseEventHandler);
|
canvasRef.current.removeEventListener('mousedown', onMouseEvent);
|
||||||
canvasRef.current.removeEventListener('mousemove', onMouseEvent);
|
canvasRef.current.removeEventListener('mousemove', onMouseEvent);
|
||||||
canvasRef.current.removeEventListener('wheel', onMouseEvent);
|
canvasRef.current.removeEventListener('wheel', onMouseEvent);
|
||||||
canvasRef.current.removeEventListener('keydown', onKeyboardEvent);
|
canvasRef.current.removeEventListener('keydown', onKeyboardEvent);
|
||||||
|
|||||||
Reference in New Issue
Block a user