From e05b118cd93889e3ee7151e0a297b3756d485aad Mon Sep 17 00:00:00 2001 From: anastasiia Date: Tue, 16 Jan 2024 12:58:17 -0500 Subject: [PATCH] some fixes --- .../CurrentTabContent/FileTab/index.tsx | 8 +- .../Code/CodeFullSelectable/CodeLine.tsx | 130 ------------------ client/src/components/Code/CodeLine.tsx | 8 +- 3 files changed, 11 insertions(+), 135 deletions(-) delete mode 100644 client/src/components/Code/CodeFullSelectable/CodeLine.tsx diff --git a/client/src/Project/CurrentTabContent/FileTab/index.tsx b/client/src/Project/CurrentTabContent/FileTab/index.tsx index 03b3e10ff9..def7bbe075 100644 --- a/client/src/Project/CurrentTabContent/FileTab/index.tsx +++ b/client/src/Project/CurrentTabContent/FileTab/index.tsx @@ -69,6 +69,7 @@ type Props = { studioId?: string; initialRanges?: [number, number][]; isFileInContext?: boolean; + isTemp?: boolean; handleMoveToAnotherSide: () => void; }; @@ -85,6 +86,7 @@ const FileTab = ({ studioId, initialRanges, isFileInContext, + isTemp, }: Props) => { const { t } = useTranslation(); const [file, setFile] = useState(null); @@ -246,8 +248,10 @@ const FileTab = ({ }, [repoRef, path]); const handleClick = useCallback(() => { - updateTabProperty(tabKey, 'isTemp', false, side); - }, [updateTabProperty, tabKey, side]); + if (isTemp) { + updateTabProperty(tabKey, 'isTemp', false, side); + } + }, [updateTabProperty, tabKey, side, isTemp]); const linesNumber = useMemo(() => { return file?.contents?.split(/\n(?!$)/g).length || 0; diff --git a/client/src/components/Code/CodeFullSelectable/CodeLine.tsx b/client/src/components/Code/CodeFullSelectable/CodeLine.tsx deleted file mode 100644 index 105fc671b2..0000000000 --- a/client/src/components/Code/CodeFullSelectable/CodeLine.tsx +++ /dev/null @@ -1,130 +0,0 @@ -import React, { - ReactNode, - useEffect, - useMemo, - useRef, - memo, - useState, -} from 'react'; -import { markNode, unmark } from '../../../utils/textSearch'; -import { CODE_LINE_HEIGHT } from '../../../consts/code'; - -type Props = { - lineNumber: number; - children: ReactNode; - stylesGenerated?: any; - searchTerm?: string; - isSelectionDisabled: boolean; - setCurrentlySelectingRange: (range: [number, number] | null) => void; - handleAddRange: () => void; - fileLinesNum: number; - shouldHighlight?: boolean; -}; - -const CodeLine = ({ - lineNumber, - children, - stylesGenerated, - searchTerm, - isSelectionDisabled, - setCurrentlySelectingRange, - handleAddRange, - fileLinesNum, - shouldHighlight, -}: Props) => { - const [isDragging, setIsDragging] = useState(false); - const codeRef = useRef(null); - const ref = useRef(null); - - useEffect(() => { - if (codeRef.current && searchTerm) { - markNode( - codeRef.current, - new RegExp( - searchTerm.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), - 'gi', - ), - ); - } - return () => { - if (codeRef.current) { - unmark(codeRef.current); - } - }; - }, [searchTerm]); - - const style = useMemo( - () => ({ - borderLeft: `3px solid ${ - shouldHighlight ? 'rgb(var(--yellow))' : 'transparent' - }`, - ...stylesGenerated, - }), - [stylesGenerated, shouldHighlight], - ); - useEffect(() => { - const handleMouseMove = (e: MouseEvent) => { - if (isDragging && ref.current) { - const deltaY = e.clientY - ref.current.getBoundingClientRect().top; - setCurrentlySelectingRange([ - Math.max( - Math.min( - lineNumber, - lineNumber + Math.ceil(deltaY / CODE_LINE_HEIGHT) - 1, - ), - 0, - ), - Math.min( - Math.max( - lineNumber, - lineNumber + Math.ceil(deltaY / CODE_LINE_HEIGHT) - 1, - ), - fileLinesNum - 1, - ), - ]); - } - }; - const handleMouseUp = (e: MouseEvent) => { - e.preventDefault(); - e.stopPropagation(); - setIsDragging(false); - handleAddRange(); - }; - if (isDragging) { - document.addEventListener('mousemove', handleMouseMove); - document.addEventListener('mouseup', handleMouseUp); - } else { - document.removeEventListener('mousemove', handleMouseMove); - document.removeEventListener('mouseup', handleMouseUp); - } - return () => { - document.removeEventListener('mousemove', handleMouseMove); - document.removeEventListener('mouseup', handleMouseUp); - }; - }, [isDragging, lineNumber, fileLinesNum]); - return ( -
{ - e.preventDefault(); - if (!isSelectionDisabled) { - setIsDragging(true); - } - }} - ref={ref} - > -
-
- {children} -
-
- ); -}; -export default memo(CodeLine); diff --git a/client/src/components/Code/CodeLine.tsx b/client/src/components/Code/CodeLine.tsx index 6d105887fa..58815d85c0 100644 --- a/client/src/components/Code/CodeLine.tsx +++ b/client/src/components/Code/CodeLine.tsx @@ -126,9 +126,11 @@ const CodeLine = ({ const handleMouseDown = useCallback( (e: React.MouseEvent) => { - e.preventDefault(); - if (!isSelectionDisabled && isEditingRanges) { - setIsDragging(true); + if (isEditingRanges) { + e.preventDefault(); + if (!isSelectionDisabled) { + setIsDragging(true); + } } }, [isSelectionDisabled, isEditingRanges],