|
@@ -9,8 +9,6 @@ import {
|
|
|
useState,
|
|
useState,
|
|
|
} from 'react'
|
|
} from 'react'
|
|
|
import { sendMB } from '@/infrastructure/event-tracking'
|
|
import { sendMB } from '@/infrastructure/event-tracking'
|
|
|
-import useScopeValue from '@/shared/hooks/use-scope-value'
|
|
|
|
|
-import { useIdeContext } from '@/shared/context/ide-context'
|
|
|
|
|
import { OpenDocuments } from '@/features/ide-react/editor/open-documents'
|
|
import { OpenDocuments } from '@/features/ide-react/editor/open-documents'
|
|
|
import EditorWatchdogManager from '@/features/ide-react/connection/editor-watchdog-manager'
|
|
import EditorWatchdogManager from '@/features/ide-react/connection/editor-watchdog-manager'
|
|
|
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
|
|
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
|
|
@@ -37,6 +35,7 @@ import { Update } from '@/features/history/services/types/update'
|
|
|
import { useDebugDiffTracker } from '../hooks/use-debug-diff-tracker'
|
|
import { useDebugDiffTracker } from '../hooks/use-debug-diff-tracker'
|
|
|
import { convertFileRefToBinaryFile } from '@/features/ide-react/util/file-view'
|
|
import { convertFileRefToBinaryFile } from '@/features/ide-react/util/file-view'
|
|
|
import { useEditorOpenDocContext } from '@/features/ide-react/context/editor-open-doc-context'
|
|
import { useEditorOpenDocContext } from '@/features/ide-react/context/editor-open-doc-context'
|
|
|
|
|
+import { useEditorPropertiesContext } from '@/features/ide-react/context/editor-properties-context'
|
|
|
|
|
|
|
|
export interface GotoOffsetOptions {
|
|
export interface GotoOffsetOptions {
|
|
|
gotoOffset: number
|
|
gotoOffset: number
|
|
@@ -52,7 +51,6 @@ interface OpenDocOptions
|
|
|
|
|
|
|
|
export type EditorManager = {
|
|
export type EditorManager = {
|
|
|
getEditorType: () => EditorType | null
|
|
getEditorType: () => EditorType | null
|
|
|
- showSymbolPalette: boolean
|
|
|
|
|
getCurrentDocValue: () => string | null
|
|
getCurrentDocValue: () => string | null
|
|
|
getCurrentDocumentId: () => DocId | null
|
|
getCurrentDocumentId: () => DocId | null
|
|
|
setIgnoringExternalUpdates: (value: boolean) => void
|
|
setIgnoringExternalUpdates: (value: boolean) => void
|
|
@@ -62,12 +60,7 @@ export type EditorManager = {
|
|
|
openFileWithId: (fileId: string) => void
|
|
openFileWithId: (fileId: string) => void
|
|
|
openInitialDoc: (docId: string) => void
|
|
openInitialDoc: (docId: string) => void
|
|
|
isLoading: boolean
|
|
isLoading: boolean
|
|
|
- trackChanges: boolean
|
|
|
|
|
jumpToLine: (options: GotoLineOptions) => void
|
|
jumpToLine: (options: GotoLineOptions) => void
|
|
|
- wantTrackChanges: boolean
|
|
|
|
|
- setWantTrackChanges: React.Dispatch<
|
|
|
|
|
- React.SetStateAction<EditorManager['wantTrackChanges']>
|
|
|
|
|
- >
|
|
|
|
|
debugTimers: React.MutableRefObject<Record<string, number>>
|
|
debugTimers: React.MutableRefObject<Record<string, number>>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -87,7 +80,6 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
|
|
children,
|
|
children,
|
|
|
}) => {
|
|
}) => {
|
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
|
- const { scopeStore } = useIdeContext()
|
|
|
|
|
const { reportError, eventEmitter, projectId, setOutOfSync } =
|
|
const { reportError, eventEmitter, projectId, setOutOfSync } =
|
|
|
useIdeReactContext()
|
|
useIdeReactContext()
|
|
|
const { socket, closeConnection, connectionState } = useConnectionContext()
|
|
const { socket, closeConnection, connectionState } = useConnectionContext()
|
|
@@ -95,11 +87,15 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
|
|
const { showGenericMessageModal, genericModalVisible, showOutOfSyncModal } =
|
|
const { showGenericMessageModal, genericModalVisible, showOutOfSyncModal } =
|
|
|
useModalsContext()
|
|
useModalsContext()
|
|
|
const { id: userId } = useUserContext()
|
|
const { id: userId } = useUserContext()
|
|
|
-
|
|
|
|
|
- const [showSymbolPalette, setShowSymbolPalette] = useScopeValue<boolean>(
|
|
|
|
|
- 'editor.showSymbolPalette'
|
|
|
|
|
- )
|
|
|
|
|
- const [showVisual] = useScopeValue<boolean>('editor.showVisual')
|
|
|
|
|
|
|
+ const {
|
|
|
|
|
+ showVisual,
|
|
|
|
|
+ opening,
|
|
|
|
|
+ setOpening,
|
|
|
|
|
+ errorState,
|
|
|
|
|
+ setErrorState,
|
|
|
|
|
+ setTrackChanges,
|
|
|
|
|
+ wantTrackChanges,
|
|
|
|
|
+ } = useEditorPropertiesContext()
|
|
|
const {
|
|
const {
|
|
|
currentDocumentId,
|
|
currentDocumentId,
|
|
|
setCurrentDocumentId,
|
|
setCurrentDocumentId,
|
|
@@ -107,15 +103,6 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
|
|
currentDocument,
|
|
currentDocument,
|
|
|
setCurrentDocument,
|
|
setCurrentDocument,
|
|
|
} = useEditorOpenDocContext()
|
|
} = useEditorOpenDocContext()
|
|
|
- const [opening, setOpening] = useScopeValue<boolean>('editor.opening')
|
|
|
|
|
- const [errorState, setIsInErrorState] =
|
|
|
|
|
- useScopeValue<boolean>('editor.error_state')
|
|
|
|
|
- const [trackChanges, setTrackChanges] = useScopeValue<boolean>(
|
|
|
|
|
- 'editor.trackChanges'
|
|
|
|
|
- )
|
|
|
|
|
- const [wantTrackChanges, setWantTrackChanges] = useScopeValue<boolean>(
|
|
|
|
|
- 'editor.wantTrackChanges'
|
|
|
|
|
- )
|
|
|
|
|
|
|
|
|
|
const wantTrackChangesRef = useRef(wantTrackChanges)
|
|
const wantTrackChangesRef = useRef(wantTrackChanges)
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
@@ -191,22 +178,6 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
|
|
|
|
|
|
|
const editorOpenDocEpochRef = useRef(0)
|
|
const editorOpenDocEpochRef = useRef(0)
|
|
|
|
|
|
|
|
- // TODO: This looks dodgy because it wraps a state setter and is itself
|
|
|
|
|
- // stored in React state in the scope store. The problem is that it needs to
|
|
|
|
|
- // be exposed via the scope store because some components access it that way;
|
|
|
|
|
- // it would be better to simply access it from a context, but the current
|
|
|
|
|
- // implementation in EditorManager interacts with Angular scope to update
|
|
|
|
|
- // the layout. Once Angular is gone, this can become a context method.
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- scopeStore.set('editor.toggleSymbolPalette', () => {
|
|
|
|
|
- setShowSymbolPalette(show => {
|
|
|
|
|
- const newValue = !show
|
|
|
|
|
- sendMB(newValue ? 'symbol-palette-show' : 'symbol-palette-hide')
|
|
|
|
|
- return newValue
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
- }, [scopeStore, setShowSymbolPalette])
|
|
|
|
|
-
|
|
|
|
|
const getEditorType = useCallback((): EditorType | null => {
|
|
const getEditorType = useCallback((): EditorType | null => {
|
|
|
if (!currentDocument) {
|
|
if (!currentDocument) {
|
|
|
return null
|
|
return null
|
|
@@ -587,7 +558,7 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
|
|
reportError(error, meta)
|
|
reportError(error, meta)
|
|
|
|
|
|
|
|
// Tell the user about the error state.
|
|
// Tell the user about the error state.
|
|
|
- setIsInErrorState(true)
|
|
|
|
|
|
|
+ setErrorState(true)
|
|
|
// Ensure that the editor is locked
|
|
// Ensure that the editor is locked
|
|
|
setOutOfSync(true)
|
|
setOutOfSync(true)
|
|
|
// Display the "out of sync" modal
|
|
// Display the "out of sync" modal
|
|
@@ -614,7 +585,7 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
|
|
eventEmitter,
|
|
eventEmitter,
|
|
|
openDoc,
|
|
openDoc,
|
|
|
reportError,
|
|
reportError,
|
|
|
- setIsInErrorState,
|
|
|
|
|
|
|
+ setErrorState,
|
|
|
showGenericMessageModal,
|
|
showGenericMessageModal,
|
|
|
showOutOfSyncModal,
|
|
showOutOfSyncModal,
|
|
|
setOutOfSync,
|
|
setOutOfSync,
|
|
@@ -661,25 +632,20 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
|
|
const value: EditorManager = useMemo(
|
|
const value: EditorManager = useMemo(
|
|
|
() => ({
|
|
() => ({
|
|
|
getEditorType,
|
|
getEditorType,
|
|
|
- showSymbolPalette,
|
|
|
|
|
getCurrentDocValue,
|
|
getCurrentDocValue,
|
|
|
getCurrentDocumentId,
|
|
getCurrentDocumentId,
|
|
|
setIgnoringExternalUpdates,
|
|
setIgnoringExternalUpdates,
|
|
|
openDocWithId,
|
|
openDocWithId,
|
|
|
openDoc,
|
|
openDoc,
|
|
|
openDocs,
|
|
openDocs,
|
|
|
- trackChanges,
|
|
|
|
|
isLoading,
|
|
isLoading,
|
|
|
openFileWithId,
|
|
openFileWithId,
|
|
|
openInitialDoc,
|
|
openInitialDoc,
|
|
|
jumpToLine,
|
|
jumpToLine,
|
|
|
- wantTrackChanges,
|
|
|
|
|
- setWantTrackChanges,
|
|
|
|
|
debugTimers,
|
|
debugTimers,
|
|
|
}),
|
|
}),
|
|
|
[
|
|
[
|
|
|
getEditorType,
|
|
getEditorType,
|
|
|
- showSymbolPalette,
|
|
|
|
|
getCurrentDocValue,
|
|
getCurrentDocValue,
|
|
|
getCurrentDocumentId,
|
|
getCurrentDocumentId,
|
|
|
setIgnoringExternalUpdates,
|
|
setIgnoringExternalUpdates,
|
|
@@ -688,11 +654,8 @@ export const EditorManagerProvider: FC<React.PropsWithChildren> = ({
|
|
|
openDocs,
|
|
openDocs,
|
|
|
openFileWithId,
|
|
openFileWithId,
|
|
|
openInitialDoc,
|
|
openInitialDoc,
|
|
|
- trackChanges,
|
|
|
|
|
isLoading,
|
|
isLoading,
|
|
|
jumpToLine,
|
|
jumpToLine,
|
|
|
- wantTrackChanges,
|
|
|
|
|
- setWantTrackChanges,
|
|
|
|
|
debugTimers,
|
|
debugTimers,
|
|
|
]
|
|
]
|
|
|
)
|
|
)
|