Skip to content

Commit

Permalink
fix: preview is now dev-preview.17 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
snorrees committed Sep 15, 2022
1 parent ed69217 commit 58a75d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/PreviewCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const PreviewInner = styled(Box)`

export interface PreviewCodeProps {
type?: CodeInputType
value?: CodeInputValue
value?: {selection?: CodeInputValue}
}

export default function PreviewCode(props: PreviewCodeProps) {
Expand All @@ -52,14 +52,15 @@ export default function PreviewCode(props: PreviewCodeProps) {
const {value, type} = props
const fixedLanguage = type?.options?.language

const mode = value?.language || fixedLanguage || 'text'
const AceEditor = useAceEditor()
const selection = value?.selection
const mode = selection?.language || fixedLanguage || 'text'

const AceEditor = useAceEditor()
return (
<PreviewContainer>
<PreviewInner padding={4}>
{AceEditor && (
<Suspense fallback={<div>Loading code editor...</div>}>
<Suspense fallback={<div>Loading code preview...</div>}>
<AceEditor
ref={aceEditorRef}
focus={false}
Expand All @@ -73,10 +74,10 @@ export default function PreviewCode(props: PreviewCodeProps) {
showPrintMargin={false}
highlightActiveLine={false}
cursorStart={-1}
value={(value && value.code) || ''}
value={selection?.code || ''}
markers={
value && value.highlightedLines
? createHighlightMarkers(value.highlightedLines)
selection?.highlightedLines
? createHighlightMarkers(selection.highlightedLines)
: undefined
}
tabSize={2}
Expand Down
2 changes: 1 addition & 1 deletion src/ace-editor/AceEditorLazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const AceEditorLazy = React.lazy(() => import('./editorSupport'))
export function useAceEditor() {
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
requestAnimationFrame(() => setMounted(true))
}, [])

return mounted ? AceEditorLazy : null
Expand Down
1 change: 1 addition & 0 deletions src/schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default defineType({
return {
title: value.filename || (value.language || 'unknown').toUpperCase(),
media: getMedia(value?.language),
selection: value,
}
},
},
Expand Down

0 comments on commit 58a75d9

Please sign in to comment.