From 7416c0c4a686f3e09c36c163324e6ce265805460 Mon Sep 17 00:00:00 2001 From: jaipaljadeja Date: Sat, 23 Mar 2024 04:55:27 +0530 Subject: [PATCH] Fix: Self Scroll to Highlighted Line --- components/Editor/InstructionsTable.tsx | 38 ++++++++++++------------- components/Editor/index.tsx | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/components/Editor/InstructionsTable.tsx b/components/Editor/InstructionsTable.tsx index d73627e..39a241a 100644 --- a/components/Editor/InstructionsTable.tsx +++ b/components/Editor/InstructionsTable.tsx @@ -1,5 +1,6 @@ -import { useEffect, useRef } from 'react' +import React, { useEffect, useRef } from 'react' +import cn from 'classnames' import ReactTooltip from 'react-tooltip' import { IInstruction } from 'types' @@ -21,20 +22,19 @@ export const InstructionsTable = ({ codeType: CodeType }) => { useEffect(() => { - if ( - tableRef.current && - focusRowRef.current && - focusRowRef.current.offsetTop - ) { - tableRef.current.scrollTo({ - top: focusRowRef.current.offsetTop - 58, - behavior: 'smooth', - }) + if (tableRef.current) { + const activeRowRef = rowRefs.current[activeIndexes[0]] + if (activeRowRef) { + tableRef.current?.scrollTo({ + top: activeRowRef.offsetTop - 58, + behavior: 'smooth', + }) + } } }, [activeIndexes]) const tableRef = useRef(null) - const focusRowRef = useRef(null) + const rowRefs = useRef>([]) const splitInLines = (instructionName: string) => instructionName.split('\n').map((line, i) => ( @@ -84,9 +84,8 @@ export const InstructionsTable = ({ const tooltipId = getRandomToolTipId() return ( - <> + {formatSierraVariableValue(variableValues)} - + ) } @@ -121,7 +120,7 @@ export const InstructionsTable = ({ return (
@@ -129,13 +128,14 @@ export const InstructionsTable = ({ const isActive = activeIndexes.includes(index) return ( (rowRefs.current[index] = el)} key={index} - className={`border-b border-gray-200 dark:border-black-500 ${ + className={cn( + 'border-b border-gray-200 dark:border-black-500', isActive ? 'text-gray-900 dark:text-gray-200' - : 'text-gray-400 dark:text-gray-600' - } `} + : 'text-gray-400 dark:text-gray-600', + )} >
{index + 1} diff --git a/components/Editor/index.tsx b/components/Editor/index.tsx index dbac5ee..ab621ef 100644 --- a/components/Editor/index.tsx +++ b/components/Editor/index.tsx @@ -348,7 +348,7 @@ const Editor = ({ readOnly = false }: Props) => {
{codeType === CodeType.CASM ? (