|
@@ -8,7 +8,14 @@ import {
|
|
|
import { EditorView, lineNumbers } from '@codemirror/view'
|
|
import { EditorView, lineNumbers } from '@codemirror/view'
|
|
|
import { indentationMarkers } from '@replit/codemirror-indentation-markers'
|
|
import { indentationMarkers } from '@replit/codemirror-indentation-markers'
|
|
|
import { highlights, setHighlightsEffect } from '../../extensions/highlights'
|
|
import { highlights, setHighlightsEffect } from '../../extensions/highlights'
|
|
|
-import { theme } from '../../extensions/theme'
|
|
|
|
|
|
|
+import useScopeValue from '../../../../shared/hooks/use-scope-value'
|
|
|
|
|
+import {
|
|
|
|
|
+ theme,
|
|
|
|
|
+ Options,
|
|
|
|
|
+ setOptionsTheme,
|
|
|
|
|
+ FontFamily,
|
|
|
|
|
+ LineHeight,
|
|
|
|
|
+} from '../../extensions/theme'
|
|
|
import { indentUnit } from '@codemirror/language'
|
|
import { indentUnit } from '@codemirror/language'
|
|
|
import { Highlight } from '../../services/types/doc'
|
|
import { Highlight } from '../../services/types/doc'
|
|
|
import useIsMounted from '../../../../shared/hooks/use-is-mounted'
|
|
import useIsMounted from '../../../../shared/hooks/use-is-mounted'
|
|
@@ -21,7 +28,7 @@ import Icon from '../../../../shared/components/icon'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
import { inlineBackground } from '../../../source-editor/extensions/inline-background'
|
|
import { inlineBackground } from '../../../source-editor/extensions/inline-background'
|
|
|
|
|
|
|
|
-function extensions(): Extension[] {
|
|
|
|
|
|
|
+function extensions(themeOptions: Options): Extension[] {
|
|
|
return [
|
|
return [
|
|
|
EditorView.editable.of(false),
|
|
EditorView.editable.of(false),
|
|
|
EditorView.contentAttributes.of({ tabindex: '0' }),
|
|
EditorView.contentAttributes.of({ tabindex: '0' }),
|
|
@@ -31,7 +38,7 @@ function extensions(): Extension[] {
|
|
|
indentationMarkers({ hideFirstIndent: true, highlightActiveBlock: false }),
|
|
indentationMarkers({ hideFirstIndent: true, highlightActiveBlock: false }),
|
|
|
highlights(),
|
|
highlights(),
|
|
|
highlightLocations(),
|
|
highlightLocations(),
|
|
|
- theme(),
|
|
|
|
|
|
|
+ theme(themeOptions),
|
|
|
inlineBackground(false),
|
|
inlineBackground(false),
|
|
|
]
|
|
]
|
|
|
}
|
|
}
|
|
@@ -43,13 +50,20 @@ function DocumentDiffViewer({
|
|
|
doc: string
|
|
doc: string
|
|
|
highlights: Highlight[]
|
|
highlights: Highlight[]
|
|
|
}) {
|
|
}) {
|
|
|
|
|
+ const [fontFamily] = useScopeValue<FontFamily>('settings.fontFamily')
|
|
|
|
|
+ const [fontSize] = useScopeValue<number>('settings.fontSize')
|
|
|
|
|
+ const [lineHeight] = useScopeValue<LineHeight>('settings.lineHeight')
|
|
|
const isMounted = useIsMounted()
|
|
const isMounted = useIsMounted()
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
const [state, setState] = useState(() => {
|
|
const [state, setState] = useState(() => {
|
|
|
return EditorState.create({
|
|
return EditorState.create({
|
|
|
doc,
|
|
doc,
|
|
|
- extensions: extensions(),
|
|
|
|
|
|
|
+ extensions: extensions({
|
|
|
|
|
+ fontSize,
|
|
|
|
|
+ fontFamily,
|
|
|
|
|
+ lineHeight,
|
|
|
|
|
+ }),
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -107,6 +121,18 @@ function DocumentDiffViewer({
|
|
|
})
|
|
})
|
|
|
}, [doc, highlights, view])
|
|
}, [doc, highlights, view])
|
|
|
|
|
|
|
|
|
|
+ // Update the document diff viewer theme whenever the font size, font family
|
|
|
|
|
+ // or line height user setting changes
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ view.dispatch(
|
|
|
|
|
+ setOptionsTheme({
|
|
|
|
|
+ fontSize,
|
|
|
|
|
+ fontFamily,
|
|
|
|
|
+ lineHeight,
|
|
|
|
|
+ })
|
|
|
|
|
+ )
|
|
|
|
|
+ }, [view, fontSize, fontFamily, lineHeight])
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className="document-diff-container">
|
|
<div className="document-diff-container">
|
|
|
<div ref={containerRef} className="cm-viewer-container" />
|
|
<div ref={containerRef} className="cm-viewer-container" />
|