Skip to content

Commit

Permalink
fix highlights after click (BloopAI#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiya1155 committed Aug 15, 2023
1 parent e6aa989 commit 6b017ff
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 22 deletions.
10 changes: 6 additions & 4 deletions client/src/components/Chat/ConversationMessage/FileChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Props = {
fileName: string;
filePath: string;
skipIcon?: boolean;
isSummary?: boolean;
lines?: [number, number];
fileChips?: MutableRefObject<HTMLButtonElement[]>;
setFileHighlights?: Dispatch<SetStateAction<FileHighlightsType>>;
Expand All @@ -31,6 +32,7 @@ const FileChip = ({
fileChips,
setFileHighlights,
setHoveredLines,
isSummary,
}: Props) => {
const ref = useRef<HTMLButtonElement>(null);
const [isHovered, setHovered] = useState(false);
Expand All @@ -43,12 +45,12 @@ const FileChip = ({

useEffect(() => {
let chip = ref.current;
if (chip && fileChips) {
if (chip && fileChips && !isSummary) {
fileChips.current.push(chip);
}

return () => {
if (chip && fileChips) {
if (chip && fileChips && !isSummary) {
const index = fileChips.current.indexOf(chip);
if (index !== -1) {
fileChips.current.splice(index, 1);
Expand All @@ -61,7 +63,7 @@ const FileChip = ({
ref.current && fileChips ? fileChips.current.indexOf(ref.current) : -1;

useEffect(() => {
if (lines && index > -1 && setFileHighlights) {
if (lines && index > -1 && setFileHighlights && !isSummary) {
setFileHighlights((prev) => {
const newHighlights = JSON.parse(JSON.stringify(prev));
if (!newHighlights[filePath]) {
Expand All @@ -83,7 +85,7 @@ const FileChip = ({
}, [lines, filePath, index]);

useEffect(() => {
if (setHoveredLines && lines && index > -1) {
if (setHoveredLines && lines && index > -1 && !isSummary) {
setHoveredLines((prev) => {
if (
isHovered &&
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/CodeBlock/Code/CodeLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const CodeLine = ({

return (
<div
className={`flex transition-all duration-150 ease-in-bounce group hover:bg-transparent ${
className={`flex transition-all duration-150 ease-in-bounce group ${
lineHidden ? 'opacity-0' : ''
} ${
blameLine?.start && lineNumber !== 0 ? ' border-t border-bg-border' : ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const CodeContainerFull = ({
firstRender.current = false;
}
}, []);

console.log('hoveredLines', hoveredLines, 'highlights', highlights);
return (
<div ref={ref} className="relative pb-60">
{tokens.map((line, index) => {
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/MarkdownWithCode/LinkRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const LinkRenderer = ({
}, [children]);

const linesToUse: [number, number] | undefined = useMemo(() => {
return hideCode && start ? [start, end ?? start] : undefined;
return hideCode && start > -1 ? [start, end ?? start] : undefined;
}, [hideCode, start, end]);

const handleClickFile = useCallback(() => {
Expand Down Expand Up @@ -99,6 +99,7 @@ const LinkRenderer = ({
lines={linesToUse}
setFileHighlights={setFileHighlights}
setHoveredLines={setHoveredLines}
isSummary={isSummary}
/>
)}
</>
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/MarkdownWithCode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ const MarkdownWithCode = ({

useEffect(() => {
return () => {
setFileHighlights({});
setHoveredLines(null);
if (!isSummary) {
setFileHighlights({});
setHoveredLines(null);
}
};
}, []);

Expand Down
17 changes: 11 additions & 6 deletions client/src/components/RegexButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { useTranslation } from 'react-i18next';
import { RegexIcon } from '../../icons';
import Tooltip from '../Tooltip';

type Props = {
active: boolean;
clasName?: string;
onClick?: () => void;
};
const RegexButton = ({ active, clasName, onClick }: Props) => {
const { t } = useTranslation();
return (
<button
onClick={onClick}
className={`
<Tooltip text={t('Search using RegExp')} placement={'bottom-end'}>
<button
onClick={onClick}
className={`
hover:text-label-title active:text-label-title
rounded-4 focus:outline-none outline-none outline-0 flex items-center p-1
flex-grow-0 flex-shrink-0 h-6 w-6 justify-center transition-all duration-150 ease-in-bounce select-none ${clasName}
Expand All @@ -18,9 +22,10 @@ const RegexButton = ({ active, clasName, onClick }: Props) => {
? 'bg-bg-main text-label-title hover:bg-bg-main'
: 'bg-transparent hover:bg-bg-base text-label-muted'
}`}
>
<RegexIcon raw sizeClassName="h-3 w-3" />
</button>
>
<RegexIcon raw sizeClassName="h-3 w-3" />
</button>
</Tooltip>
);
};
export default RegexButton;
3 changes: 2 additions & 1 deletion client/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,6 @@
"Open file": "Open file",
"Edit": "Edit",
"Editing a previously submitted question will discard all answers and questions following it.": "Editing a previously submitted question will discard all answers and questions following it.",
"Copy link": "Copy link"
"Copy link": "Copy link",
"Search using RegExp": "Search using RegExp"
}
5 changes: 3 additions & 2 deletions client/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,6 @@
"Open file": "Abrir documento",
"Edit": "Editar",
"Editing a previously submitted question will discard all answers and questions following it.": "La edición de una pregunta enviada anteriormente descartará todas las respuestas y preguntas que lo sigan.",
"Copy link": "Copiar link"
}
"Copy link": "Copiar link",
"Search using RegExp": "Buscar usando RegExp"
}
5 changes: 3 additions & 2 deletions client/src/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,6 @@
"Open file": "ファイルを開く",
"Edit": "編集",
"Editing a previously submitted question will discard all answers and questions following it.": "以前に提出された質問を編集すると、それに続くすべての回答と質問が破棄されます。",
"Copy link": "リンクをコピーする"
}
"Copy link": "リンクをコピーする",
"Search using RegExp": "RegExpを使用して検索します"
}
5 changes: 3 additions & 2 deletions client/src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,6 @@
"Open file": "打开文件",
"Edit": "编辑",
"Editing a previously submitted question will discard all answers and questions following it.": "编辑之前提交的问题将丢弃其后的所有答案和问题。",
"Copy link": "复制链接"
}
"Copy link": "复制链接",
"Search using RegExp": "使用RegExp搜索"
}

0 comments on commit 6b017ff

Please sign in to comment.