|
|
@@ -21,7 +21,11 @@ import {
|
|
|
} from '../extensions/annotations'
|
|
|
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
|
|
import { setCursorHighlights } from '../extensions/cursor-highlights'
|
|
|
-import { setMetadata, setSyntaxValidation } from '../extensions/language'
|
|
|
+import {
|
|
|
+ setLanguage,
|
|
|
+ setMetadata,
|
|
|
+ setSyntaxValidation,
|
|
|
+} from '../extensions/language'
|
|
|
import { useIdeContext } from '../../../shared/context/ide-context'
|
|
|
import { restoreScrollPosition } from '../extensions/scroll-position'
|
|
|
import { setEditable } from '../extensions/editable'
|
|
|
@@ -48,6 +52,8 @@ import { useErrorHandler } from 'react-error-boundary'
|
|
|
import { setVisual } from '../extensions/visual/visual'
|
|
|
import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
|
|
|
import { useUserSettingsContext } from '@/shared/context/user-settings-context'
|
|
|
+import { setDocName } from '@/features/source-editor/extensions/doc-name'
|
|
|
+import isValidTexFile from '@/main/is-valid-tex-file'
|
|
|
|
|
|
function useCodeMirrorScope(view: EditorView) {
|
|
|
const ide = useIdeContext()
|
|
|
@@ -139,7 +145,6 @@ function useCodeMirrorScope(view: EditorView) {
|
|
|
|
|
|
const currentDocRef = useRef({
|
|
|
currentDoc,
|
|
|
- docName,
|
|
|
trackChanges,
|
|
|
loadingThreads,
|
|
|
})
|
|
|
@@ -150,11 +155,7 @@ function useCodeMirrorScope(view: EditorView) {
|
|
|
}
|
|
|
}, [view, currentDoc])
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- if (docName) {
|
|
|
- currentDocRef.current.docName = docName
|
|
|
- }
|
|
|
- }, [view, docName])
|
|
|
+ const docNameRef = useRef(docName)
|
|
|
|
|
|
useEffect(() => {
|
|
|
currentDocRef.current.loadingThreads = loadingThreads
|
|
|
@@ -258,6 +259,7 @@ function useCodeMirrorScope(view: EditorView) {
|
|
|
...currentDocRef.current,
|
|
|
currentDoc,
|
|
|
},
|
|
|
+ docName: docNameRef.current,
|
|
|
theme: themeRef.current,
|
|
|
metadata: metadataRef.current,
|
|
|
settings: settingsRef.current,
|
|
|
@@ -298,14 +300,31 @@ function useCodeMirrorScope(view: EditorView) {
|
|
|
}, [view, currentDoc, handleError])
|
|
|
|
|
|
useEffect(() => {
|
|
|
- visualRef.current.visual = visual
|
|
|
+ if (docName) {
|
|
|
+ docNameRef.current = docName
|
|
|
+
|
|
|
+ view.dispatch(
|
|
|
+ setDocName(docNameRef.current),
|
|
|
+ setLanguage(
|
|
|
+ docNameRef.current,
|
|
|
+ metadataRef.current,
|
|
|
+ settingsRef.current.syntaxValidation
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }, [view, docName])
|
|
|
+
|
|
|
+ const showVisual = visual && isValidTexFile(docName)
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ visualRef.current.visual = showVisual
|
|
|
view.dispatch(setVisual(visualRef.current))
|
|
|
view.dispatch({
|
|
|
effects: EditorView.scrollIntoView(view.state.selection.main.head),
|
|
|
})
|
|
|
// clear performance measures and marks when switching between Source and Rich Text
|
|
|
window.dispatchEvent(new Event('editor:visual-switch'))
|
|
|
- }, [view, visual])
|
|
|
+ }, [view, showVisual])
|
|
|
|
|
|
useEffect(() => {
|
|
|
visualRef.current.previewByPath = previewByPath
|