import { Box, chakra } from '@chakra-ui/react'; import React from 'react'; import type { SearchResult } from './types'; import type { ArrayElement } from 'types/utils'; import useThemeColors from './utils/useThemeColors'; interface Props extends ArrayElement { filePath: string; onClick: (event: React.MouseEvent) => void; } const calculateStartPosition = (lineContent: string, startColumn: number) => { let start = 0; for (let index = 0; index < startColumn; index++) { const element = lineContent[index]; if (element === ' ') { start = index + 1; continue; } } return start ? start - 1 : 0; }; const CodeEditorSearchResultItem = ({ lineContent, filePath, onClick, startLineNumber, startColumn, endColumn }: Props) => { const start = calculateStartPosition(lineContent, startColumn); const themeColors = useThemeColors(); return ( { lineContent.slice(start, startColumn - 1) } { lineContent.slice(startColumn - 1, endColumn - 1) } { lineContent.slice(endColumn - 1) } ); }; export default React.memo(CodeEditorSearchResultItem);