editor.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { EditorLoadingPane } from '@/features/ide-react/components/editor/editor-loading-pane'
  2. import { useEditorOpenDocContext } from '@/features/ide-react/context/editor-open-doc-context'
  3. import { useFileTreeOpenContext } from '@/features/ide-react/context/file-tree-open-context'
  4. import classNames from 'classnames'
  5. import SourceEditor from '@/features/source-editor/components/source-editor'
  6. import { Panel, PanelGroup } from 'react-resizable-panels'
  7. import { VerticalResizeHandle } from '@/features/ide-react/components/resize/vertical-resize-handle'
  8. import { Suspense } from 'react'
  9. import { FullSizeLoadingSpinner } from '@/shared/components/loading-spinner'
  10. import SymbolPalettePane from '@/features/ide-react/components/editor/symbol-palette-pane'
  11. import { useEditorPropertiesContext } from '@/features/ide-react/context/editor-properties-context'
  12. import { PythonEditorSplit } from '@/features/ide-react/components/layout/python-editor-split'
  13. import { isSplitTestEnabled } from '@/utils/splitTestUtils'
  14. export const Editor = () => {
  15. const { opening, errorState, showSymbolPalette } =
  16. useEditorPropertiesContext()
  17. const { selectedEntityCount, openEntity } = useFileTreeOpenContext()
  18. const { currentDocumentId, currentDocument } = useEditorOpenDocContext()
  19. const isPythonDocument =
  20. openEntity?.type === 'doc' &&
  21. openEntity.entity.name.toLowerCase().endsWith('.py')
  22. const pythonExecutionEnabled = isSplitTestEnabled('overleaf-code')
  23. if (!currentDocumentId) {
  24. return null
  25. }
  26. const isLoading = Boolean(
  27. (!currentDocument || opening) && !errorState && currentDocumentId
  28. )
  29. return (
  30. <div
  31. className={classNames('ide-redesign-editor-content', {
  32. hidden: openEntity?.type !== 'doc' || selectedEntityCount !== 1,
  33. })}
  34. >
  35. <PanelGroup
  36. autoSaveId="ide-redesign-editor-symbol-palette"
  37. direction="vertical"
  38. >
  39. <Panel
  40. id="ide-redesign-panel-source-editor"
  41. order={1}
  42. className="ide-redesign-editor-panel"
  43. >
  44. {isPythonDocument && pythonExecutionEnabled ? (
  45. <PythonEditorSplit />
  46. ) : (
  47. <SourceEditor />
  48. )}
  49. {isLoading && <EditorLoadingPane />}
  50. </Panel>
  51. {showSymbolPalette && (
  52. <>
  53. <VerticalResizeHandle id="ide-redesign-editor-symbol-palette" />
  54. <Panel
  55. id="ide-redesign-panel-symbol-palette"
  56. order={2}
  57. defaultSize={25}
  58. minSize={10}
  59. maxSize={50}
  60. >
  61. <Suspense fallback={<FullSizeLoadingSpinner delay={500} />}>
  62. <SymbolPalettePane />
  63. </Suspense>
  64. </Panel>
  65. </>
  66. )}
  67. </PanelGroup>
  68. </div>
  69. )
  70. }