Notebooks: fix highlighted code (#59264)

fix highlighted lines in notebooks
This commit is contained in:
Camden Cheek 2024-01-02 09:01:37 -07:00 committed by GitHub
parent d22dc98dd1
commit 5db495dd30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -81,7 +81,9 @@ export const NotebookFileBlock: React.FunctionComponent<React.PropsWithChildren<
const hideInputs = useCallback(() => setShowInputs(false), [setShowInputs])
const isFileSelected = input.repositoryName.length > 0 && input.filePath.length > 0
const blobLines = useObservable(useMemo(() => output?.pipe(startWith(LOADING)) ?? of(undefined), [output]))
const highlightedLines = useObservable(
useMemo(() => output?.pipe(startWith(LOADING)) ?? of(undefined), [output])
)
const commonMenuActions = useCommonBlockMenuActions({ id, isReadOnly, ...props })
const fileURL = useMemo(
() =>
@ -186,19 +188,20 @@ export const NotebookFileBlock: React.FunctionComponent<React.PropsWithChildren<
{...props}
/>
)}
{blobLines && blobLines === LOADING && (
{highlightedLines && highlightedLines === LOADING && (
<div className="d-flex justify-content-center py-3">
<LoadingSpinner inline={false} />
</div>
)}
{blobLines && blobLines !== LOADING && !isErrorLike(blobLines) && (
{highlightedLines && highlightedLines !== LOADING && !isErrorLike(highlightedLines) && (
<div>
<CodeExcerpt
className={styles.code}
repoName={input.repositoryName}
commitID={input.revision}
filePath={input.filePath}
plaintextLines={blobLines}
plaintextLines={[]}
highlightedLines={highlightedLines}
highlightRanges={[]}
startLine={input.lineRange?.startLine ?? 0}
endLine={input.lineRange?.endLine ?? 1}
@ -206,9 +209,9 @@ export const NotebookFileBlock: React.FunctionComponent<React.PropsWithChildren<
/>
</div>
)}
{blobLines && blobLines !== LOADING && isErrorLike(blobLines) && (
{highlightedLines && highlightedLines !== LOADING && isErrorLike(highlightedLines) && (
<Alert className="m-3" variant="danger">
{blobLines.message}
{highlightedLines.message}
</Alert>
)}
</NotebookBlock>

View File

@ -196,7 +196,8 @@ export const NotebookSymbolBlock: React.FunctionComponent<React.PropsWithChildre
repoName={input.repositoryName}
commitID={input.revision}
filePath={input.filePath}
plaintextLines={symbolOutput.highlightedLines}
plaintextLines={[]}
highlightedLines={symbolOutput.highlightedLines}
highlightRanges={[symbolOutput.highlightSymbolRange]}
{...symbolOutput.highlightLineRange}
onCopy={logEventOnCopy}