DiffEditor.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { DiffEditor as BaseDiffEditor } from '@monaco-editor/react'
  2. import type { editor as monacoEditor } from 'monaco-editor'
  3. interface DiffViewerProps {
  4. /** Original/left hand side content (optional) */
  5. original?: string
  6. /** Modified/right hand side content */
  7. modified: string | undefined
  8. /** Language identifier understood by Monaco */
  9. language?: string
  10. /** Height for the editor container */
  11. height?: string | number
  12. /** Diff Editor Options */
  13. options?: monacoEditor.IStandaloneDiffEditorConstructionOptions
  14. onMount?: (editor: monacoEditor.IStandaloneDiffEditor) => void
  15. }
  16. // Centralised set of options so all diff editors look the same
  17. const DEFAULT_OPTIONS: monacoEditor.IStandaloneDiffEditorConstructionOptions = {
  18. fontSize: 13,
  19. minimap: { enabled: false },
  20. wordWrap: 'on',
  21. lineNumbers: 'on',
  22. folding: false,
  23. lineNumbersMinChars: 3,
  24. scrollBeyondLastLine: false,
  25. renderSideBySide: false,
  26. padding: { top: 4 },
  27. }
  28. export const DiffEditor = ({
  29. original = '',
  30. modified = '',
  31. language = 'pgsql',
  32. height = '100%',
  33. options,
  34. onMount,
  35. }: DiffViewerProps) => (
  36. <BaseDiffEditor
  37. // [Joshen] These ones are meant to solve a UI issue that seems to only be happening locally
  38. // Happens when you use the inline assistant in the SQL Editor and accept the suggestion
  39. // Error: TextModel got disposed before DiffEditorWidget model got reset
  40. keepCurrentOriginalModel
  41. keepCurrentModifiedModel
  42. theme="briven"
  43. language={language}
  44. height={height}
  45. original={original}
  46. modified={modified}
  47. options={{ ...DEFAULT_OPTIONS, ...options }}
  48. onMount={onMount}
  49. />
  50. )