Remove uses of editor scope values (#23312)

GitOrigin-RevId: 97e2188bc1363618b60f722fa317a5b240d5013b
This commit is contained in:
Alf Eaton
2025-02-07 09:05:12 +00:00
committed by Copybot
parent 9854d37916
commit 294079d55e
14 changed files with 130 additions and 134 deletions
@@ -54,7 +54,7 @@ interface OpenDocOptions
export type EditorManager = {
getEditorType: () => EditorType | null
showSymbolPalette: boolean
currentDocument: DocumentContainer
currentDocument: DocumentContainer | null
currentDocumentId: DocId | null
getCurrentDocValue: () => string | null
getCurrentDocumentId: () => DocId | null
@@ -65,6 +65,10 @@ export type EditorManager = {
openDocs: OpenDocuments
openFileWithId: (fileId: string) => void
openInitialDoc: (docId: string) => void
openDocName: string | null
setOpenDocName: (openDocName: string) => void
isLoading: boolean
trackChanges: boolean
jumpToLine: (options: GotoLineOptions) => void
wantTrackChanges: boolean
setWantTrackChanges: React.Dispatch<
@@ -102,8 +106,7 @@ export const EditorManagerContext = createContext<EditorManager | undefined>(
export const EditorManagerProvider: FC = ({ children }) => {
const { t } = useTranslation()
const { scopeStore } = useIdeContext()
const { projectId } = useIdeReactContext()
const { reportError, eventEmitter } = useIdeReactContext()
const { reportError, eventEmitter, projectId } = useIdeReactContext()
const { setOutOfSync } = useEditorContext()
const { socket, closeConnection, connectionState } = useConnectionContext()
const { view, setView } = useLayoutContext()
@@ -115,16 +118,19 @@ export const EditorManagerProvider: FC = ({ children }) => {
)
const [showVisual] = useScopeValue<boolean>('editor.showVisual')
const [currentDocument, setCurrentDocument] =
useScopeValue<DocumentContainer>('editor.sharejs_doc')
useScopeValue<DocumentContainer | null>('editor.sharejs_doc')
const [currentDocumentId, setCurrentDocumentId] = useScopeValue<DocId | null>(
'editor.open_doc_id'
)
const [, setOpenDocName] = useScopeValue<string | null>(
const [openDocName, setOpenDocName] = useScopeValue<string | null>(
'editor.open_doc_name'
)
const [, setOpening] = useScopeValue<boolean>('editor.opening')
const [, setIsInErrorState] = useScopeValue<boolean>('editor.error_state')
const [, setTrackChanges] = useScopeValue<boolean>('editor.trackChanges')
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'
)
@@ -385,7 +391,7 @@ export const EditorManagerProvider: FC = ({ children }) => {
// - when the current one has pending ops that need flushing, to avoid
// race conditions from cleanup
const currentDocumentId = currentDocument?.doc_id
const hasBufferedOps = currentDocument?.hasBufferedOps()
const hasBufferedOps = currentDocument && currentDocument.hasBufferedOps()
const changingDoc = currentDocument && currentDocumentId !== doc._id
if (changingDoc || hasBufferedOps) {
debugConsole.log('[openNewDocument] Leaving existing open doc...')
@@ -679,13 +685,20 @@ export const EditorManagerProvider: FC = ({ children }) => {
// Watch for changes in wantTrackChanges
const previousWantTrackChangesRef = useRef(wantTrackChanges)
useEffect(() => {
if (wantTrackChanges !== previousWantTrackChangesRef.current) {
if (
currentDocument &&
wantTrackChanges !== previousWantTrackChangesRef.current
) {
previousWantTrackChangesRef.current = wantTrackChanges
syncTrackChangesState(currentDocument)
}
}, [currentDocument, syncTrackChangesState, wantTrackChanges])
const value = useMemo(
const isLoading = Boolean(
(!currentDocument || opening) && !errorState && currentDocumentId
)
const value: EditorManager = useMemo(
() => ({
getEditorType,
showSymbolPalette,
@@ -698,6 +711,10 @@ export const EditorManagerProvider: FC = ({ children }) => {
openDocWithId,
openDoc,
openDocs,
openDocName,
setOpenDocName,
trackChanges,
isLoading,
openFileWithId,
openInitialDoc,
jumpToLine,
@@ -719,6 +736,10 @@ export const EditorManagerProvider: FC = ({ children }) => {
openDocs,
openFileWithId,
openInitialDoc,
openDocName,
setOpenDocName,
trackChanges,
isLoading,
jumpToLine,
wantTrackChanges,
setWantTrackChanges,
@@ -20,6 +20,7 @@ import useSocketListener from '@/features/ide-react/hooks/use-socket-listener'
import { debugConsole } from '@/utils/debugging'
import { IdeEvents } from '@/features/ide-react/create-ide-event-emitter'
import { getHueForUserId } from '@/shared/utils/colors'
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
export type OnlineUser = {
id: string
@@ -76,7 +77,7 @@ const OnlineUsersContext = createContext<OnlineUsersContextValue | undefined>(
export const OnlineUsersProvider: FC = ({ children }) => {
const { eventEmitter } = useIdeReactContext()
const { socket } = useConnectionContext()
const [currentDocumentId] = useScopeValue<string | null>('editor.open_doc_id')
const { currentDocumentId } = useEditorManagerContext()
const { fileTreeData } = useFileTreeData()
const [onlineUsers, setOnlineUsers] =
@@ -11,10 +11,10 @@ import {
import useScopeEventEmitter from '@/shared/hooks/use-scope-event-emitter'
import useEventListener from '@/shared/hooks/use-event-listener'
import * as eventTracking from '@/infrastructure/event-tracking'
import useScopeValue from '@/shared/hooks/use-scope-value'
import { isValidTeXFile } from '@/main/is-valid-tex-file'
import localStorage from '@/infrastructure/local-storage'
import { useProjectContext } from '@/shared/context/project-context'
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
export type PartialFlatOutline = {
level: number
@@ -118,10 +118,10 @@ export const OutlineProvider: FC = ({ children }) => {
[flatOutline, currentlyHighlightedLine]
)
const [docName] = useScopeValue<string | null>('editor.open_doc_name')
const { openDocName } = useEditorManagerContext()
const isTexFile = useMemo(
() => (docName ? isValidTeXFile(docName) : false),
[docName]
() => (openDocName ? isValidTeXFile(openDocName) : false),
[openDocName]
)
const { _id: projectId } = useProjectContext()
@@ -495,11 +495,13 @@ function useReviewPanelState(): ReviewPanel.ReviewPanelState {
const regenerateTrackChangesId = useCallback(
(doc: typeof currentDocument) => {
const currentChangeTracker = getChangeTracker(doc.doc_id as DocId)
const oldId = currentChangeTracker.getIdSeed()
const newId = RangesTracker.generateIdSeed()
currentChangeTracker.setIdSeed(newId)
doc.setTrackChangesIdSeeds({ pending: newId, inflight: oldId })
if (doc) {
const currentChangeTracker = getChangeTracker(doc.doc_id as DocId)
const oldId = currentChangeTracker.getIdSeed()
const newId = RangesTracker.generateIdSeed()
currentChangeTracker.setIdSeed(newId)
doc.setTrackChangesIdSeeds({ pending: newId, inflight: oldId })
}
},
[getChangeTracker]
)