Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Scroll on highlight cairo segment when moving through the exec… #146

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,30 @@ const Editor = ({ readOnly = false }: Props) => {
inlineClassName: string
}
interface Decoration {
range: {}
range: {
startLineNumber: number
startColumn: number
endLineNumber: number
endColumn: number
}
options: DecorationOptions
}

useEffect(() => {
setTimeout(() => {
const multiplieDecorations: Decoration[] = []
let isHighlightOnScreen = false
casmToSierraProgramMap[activeCasmInstructionIndex]?.map((item, i) => {
const index = casmToSierraStatementsMap[activeCasmInstructionIndex][i]

if (sierraStatementsToCairoInfo) {
sierraStatementsToCairoInfo[index]?.cairo_locations.map(
(cairoLocElem) => {
if (
isRangeVisible(cairoLocElem.start.line, cairoLocElem.end.line)
) {
isHighlightOnScreen = true
}
const startLine: number = cairoLocElem.start.line + 1
const endLine: number = cairoLocElem.end.line + 1
const startCol: number = cairoLocElem.start.col + 1
Expand All @@ -132,6 +143,17 @@ const Editor = ({ readOnly = false }: Props) => {
}
},
)

if (!isHighlightOnScreen && multiplieDecorations[0] && monaco) {
editorRef.current?.revealRangeInCenter(
new monaco.Range(
multiplieDecorations[0].range.startLineNumber,
multiplieDecorations[0].range.startColumn,
multiplieDecorations[0].range.endLineNumber,
multiplieDecorations[0].range.endColumn,
),
)
}
}
}) || []
const editor = editorRef.current as any
Expand Down Expand Up @@ -214,6 +236,19 @@ const Editor = ({ readOnly = false }: Props) => {
executionPanicMessage,
])

const isRangeVisible = (startLine: number, endLine: number) => {
const editor = editorRef.current
if (editor) {
const visibleRanges = editor.getVisibleRanges()
return visibleRanges.some(
(visibleRange) =>
visibleRange.startLineNumber <= endLine &&
visibleRange.endLineNumber >= startLine,
)
}
return false
}

const handleCairoCodeChange = (value: string | undefined) => {
if (value) {
setCairoCode(value)
Expand Down
Loading