diff --git a/services/web/frontend/js/features/history/context/hooks/use-restore-deleted-file.ts b/services/web/frontend/js/features/history/context/hooks/use-restore-deleted-file.ts index c4bfb672c5..5dcb5f2fef 100644 --- a/services/web/frontend/js/features/history/context/hooks/use-restore-deleted-file.ts +++ b/services/web/frontend/js/features/history/context/hooks/use-restore-deleted-file.ts @@ -42,7 +42,7 @@ export function useRestoreDeletedFile() { // Once Angular is gone, these can be replaced with calls to context // methods if (restoredFileMetadata.type === 'doc') { - ide.editorManager.openDocId(id) + ide.editorManager.openDocWithId(id) } else { ide.binaryFilesManager.openFileWithId(id) } diff --git a/services/web/frontend/js/features/history/context/hooks/use-restore-selected-file.ts b/services/web/frontend/js/features/history/context/hooks/use-restore-selected-file.ts index 0355f0a107..f33847d0f0 100644 --- a/services/web/frontend/js/features/history/context/hooks/use-restore-selected-file.ts +++ b/services/web/frontend/js/features/history/context/hooks/use-restore-selected-file.ts @@ -43,7 +43,7 @@ export function useRestoreSelectedFile() { // Once Angular is gone, these can be replaced with calls to context // methods if (restoredFileMetadata.type === 'doc') { - ide.editorManager.openDocId(id) + ide.editorManager.openDocWithId(id) } else { ide.binaryFilesManager.openFileWithId(id) } diff --git a/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx b/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx index c2d73a0988..99b6c2436f 100644 --- a/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx @@ -51,10 +51,10 @@ export type EditorManager = { currentDocument: DocumentContainer currentDocumentId: DocId | null getCurrentDocValue: () => string | null - getCurrentDocId: () => DocId | null + getCurrentDocumentId: () => DocId | null startIgnoringExternalUpdates: () => void stopIgnoringExternalUpdates: () => void - openDocId: (docId: string, options?: OpenDocOptions) => void + openDocWithId: (docId: string, options?: OpenDocOptions) => void openDoc: (document: Doc, options?: OpenDocOptions) => void openDocs: OpenDocuments openInitialDoc: (docId: string) => void @@ -109,7 +109,7 @@ export const EditorManagerProvider: FC = ({ children }) => { const [showVisual] = useScopeValue('editor.showVisual') const [currentDocument, setCurrentDocument] = useScopeValue('editor.sharejs_doc') - const [openDocId, setOpenDocId] = useScopeValue( + const [currentDocumentId, setCurrentDocumentId] = useScopeValue( 'editor.open_doc_id' ) const [, setOpenDocName] = useScopeValue( @@ -191,14 +191,14 @@ export const EditorManagerProvider: FC = ({ children }) => { ) ) - const openDocIdStorageKey = `doc.open_id.${projectId}` + const currentDocumentIdStorageKey = `doc.open_id.${projectId}` // Persist the open document ID to local storage useEffect(() => { - if (openDocId) { - customLocalStorage.setItem(openDocIdStorageKey, openDocId) + if (currentDocumentId) { + customLocalStorage.setItem(currentDocumentIdStorageKey, currentDocumentId) } - }, [openDocId, openDocIdStorageKey]) + }, [currentDocumentId, currentDocumentIdStorageKey]) const editorOpenDocEpochRef = useRef(0) @@ -230,7 +230,10 @@ export const EditorManagerProvider: FC = ({ children }) => { return currentDocument?.getSnapshot() ?? null }, [currentDocument]) - const getCurrentDocId = useCallback(() => openDocId, [openDocId]) + const getCurrentDocumentId = useCallback( + () => currentDocumentId, + [currentDocumentId] + ) const startIgnoringExternalUpdates = useCallback( () => setIgnoringExternalUpdates(true), @@ -379,9 +382,9 @@ export const EditorManagerProvider: FC = ({ children }) => { // between leaving and joining the same document // - when the current one has pending ops that need flushing, to avoid // race conditions from cleanup - const currentDocId = currentDocument?.doc_id + const currentDocumentId = currentDocument?.doc_id const hasBufferedOps = currentDocument?.hasBufferedOps() - const changingDoc = currentDocument && currentDocId !== doc._id + const changingDoc = currentDocument && currentDocumentId !== doc._id if (changingDoc || hasBufferedOps) { debugConsole.log('[openNewDocument] Leaving existing open doc...') @@ -401,7 +404,7 @@ export const EditorManagerProvider: FC = ({ children }) => { await currentDocument.leaveAndCleanUpPromise() } catch (error) { debugConsole.log( - `[openNewDocument] error leaving doc ${currentDocId}`, + `[openNewDocument] error leaving doc ${currentDocumentId}`, error ) throw error @@ -419,10 +422,10 @@ export const EditorManagerProvider: FC = ({ children }) => { [attachErrorHandlerToDocument, doOpenNewDocument, currentDocument] ) - const openDocIdRef = useRef(openDocId) + const currentDocumentIdRef = useRef(currentDocumentId) useEffect(() => { - openDocIdRef.current = openDocId - }, [openDocId]) + currentDocumentIdRef.current = currentDocumentId + }, [currentDocumentId]) const openDoc = useCallback( async (doc: Doc, options: OpenDocOptions = {}) => { @@ -468,14 +471,14 @@ export const EditorManagerProvider: FC = ({ children }) => { // If we already have the document open, or are opening the document, we can return at this point. // Note: only use forceReopen:true to override this when the document is // out of sync and needs to be reloaded from the server. - if (doc._id === openDocIdRef.current && !options.forceReopen) { + if (doc._id === currentDocumentIdRef.current && !options.forceReopen) { done(false) return } // We're now either opening a new document or reloading a broken one. - openDocIdRef.current = doc._id as DocId - setOpenDocId(doc._id as DocId) + currentDocumentIdRef.current = doc._id as DocId + setCurrentDocumentId(doc._id as DocId) setOpenDocName(doc.name) setOpening(true) @@ -507,7 +510,7 @@ export const EditorManagerProvider: FC = ({ children }) => { jumpToLine, openNewDocument, setCurrentDocument, - setOpenDocId, + setCurrentDocumentId, setOpenDocName, setOpening, setView, @@ -532,12 +535,12 @@ export const EditorManagerProvider: FC = ({ children }) => { const openInitialDoc = useCallback( (fallbackDocId: string) => { const docId = - customLocalStorage.getItem(openDocIdStorageKey) || fallbackDocId + customLocalStorage.getItem(currentDocumentIdStorageKey) || fallbackDocId if (docId) { openDocWithId(docId) } }, - [openDocIdStorageKey, openDocWithId] + [currentDocumentIdStorageKey, openDocWithId] ) useEffect(() => { @@ -662,12 +665,12 @@ export const EditorManagerProvider: FC = ({ children }) => { getEditorType, showSymbolPalette, currentDocument, - currentDocumentId: openDocId, + currentDocumentId, getCurrentDocValue, - getCurrentDocId, + getCurrentDocumentId, startIgnoringExternalUpdates, stopIgnoringExternalUpdates, - openDocId: openDocWithId, + openDocWithId, openDoc, openDocs, openInitialDoc, @@ -680,9 +683,9 @@ export const EditorManagerProvider: FC = ({ children }) => { getEditorType, showSymbolPalette, currentDocument, - openDocId, + currentDocumentId, getCurrentDocValue, - getCurrentDocId, + getCurrentDocumentId, startIgnoringExternalUpdates, stopIgnoringExternalUpdates, openDocWithId, diff --git a/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx b/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx index d1b30deb59..82f5dfc049 100644 --- a/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx @@ -39,11 +39,8 @@ const FileTreeOpenContext = createContext< export const FileTreeOpenProvider: FC = ({ children }) => { const { rootDocId, owner } = useProjectContext() const { eventEmitter, projectJoined } = useIdeReactContext() - const { - openDocId: openDocWithId, - currentDocumentId: openDocId, - openInitialDoc, - } = useEditorManagerContext() + const { openDocWithId, currentDocumentId, openInitialDoc } = + useEditorManagerContext() const { selectEntity } = useSelectFileTreeEntity() const [, setOpenFile] = useScopeValue('openFile') const [openEntity, setOpenEntity] = useState< @@ -107,14 +104,14 @@ export const FileTreeOpenProvider: FC = ({ children }) => { (entity: FileTreeFindResult) => { eventEmitter.emit('entity:deleted', entity) // Select the root document if the current document was deleted - if (entity.entity._id === openDocId) { + if (entity.entity._id === currentDocumentId) { openDocWithId(rootDocId!) } }, - [eventEmitter, openDocId, openDocWithId, rootDocId] + [eventEmitter, currentDocumentId, openDocWithId, rootDocId] ) - // Synchronize the file tree when openDoc or openDocId is called on the editor + // Synchronize the file tree when openDoc or openDocWithId is called on the editor // manager context from elsewhere. If the file tree does change, it will // trigger the onSelect handler in this component, which will update the local // state. diff --git a/services/web/frontend/js/features/ide-react/context/online-users-context.tsx b/services/web/frontend/js/features/ide-react/context/online-users-context.tsx index 26508f2f87..685baa10be 100644 --- a/services/web/frontend/js/features/ide-react/context/online-users-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/online-users-context.tsx @@ -76,7 +76,7 @@ const OnlineUsersContext = createContext( export const OnlineUsersProvider: FC = ({ children }) => { const { eventEmitter } = useIdeReactContext() const { socket } = useConnectionContext() - const [openDocId] = useScopeValue('editor.open_doc_id') + const [currentDocumentId] = useScopeValue('editor.open_doc_id') const { fileTreeData } = useFileTreeData() const [onlineUsers, setOnlineUsers] = @@ -235,14 +235,14 @@ export const OnlineUsersProvider: FC = ({ children }) => { socket.emit('clientTracking.updatePosition', { row: currentPosition?.row, column: currentPosition?.column, - doc_id: openDocId, + doc_id: currentDocumentId, }) }, cursorUpdateInterval) return () => { window.clearTimeout(timer) } - }, [currentPosition, cursorUpdateInterval, openDocId, socket]) + }, [currentPosition, cursorUpdateInterval, currentDocumentId, socket]) const handleClientUpdated = useCallback( (client: OnlineUser) => { diff --git a/services/web/frontend/js/features/ide-react/context/review-panel/hooks/use-review-panel-state.ts b/services/web/frontend/js/features/ide-react/context/review-panel/hooks/use-review-panel-state.ts index 43db1a236e..c758e9e7d3 100644 --- a/services/web/frontend/js/features/ide-react/context/review-panel/hooks/use-review-panel-state.ts +++ b/services/web/frontend/js/features/ide-react/context/review-panel/hooks/use-review-panel-state.ts @@ -138,7 +138,7 @@ function useReviewPanelState(): ReviewPanel.ReviewPanelState { } = project const { isRestrictedTokenMember } = useEditorContext() const { - openDocId, + openDocWithId, currentDocument, currentDocumentId, wantTrackChanges, @@ -845,9 +845,9 @@ function useReviewPanelState(): ReviewPanel.ReviewPanelState { const gotoEntry = useCallback( (docId: DocId, entryOffset: number) => { - openDocId(docId, { gotoOffset: entryOffset }) + openDocWithId(docId, { gotoOffset: entryOffset }) }, - [openDocId] + [openDocWithId] ) const view = reviewPanelOpen ? subView : 'mini' diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.jsx b/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.jsx index c7c28688a0..0b5dd1332d 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.jsx +++ b/services/web/frontend/js/features/pdf-preview/components/pdf-synctex-controls.jsx @@ -190,7 +190,7 @@ function PdfSynctexControls() { const [cursorPosition, setCursorPosition] = useState(() => { const position = localStorage.getItem( - `doc.position.${ide.editorManager.getCurrentDocId()}` + `doc.position.${ide.editorManager.getCurrentDocumentId()}` ) return position ? position.cursorPosition : null }) @@ -216,7 +216,7 @@ function PdfSynctexControls() { const [, setSynctexError] = useScopeValue('sync_tex_error') const getCurrentFilePath = useCallback(() => { - const docId = ide.editorManager.getCurrentDocId() + const docId = ide.editorManager.getCurrentDocumentId() let path = pathInFolder(docId) // If the root file is folder/main.tex, then synctex sees the path as folder/./main.tex @@ -238,7 +238,7 @@ function PdfSynctexControls() { return } - ide.editorManager.openDocId(doc._id, { + ide.editorManager.openDocWithId(doc._id, { gotoLine: line, }) } else { diff --git a/services/web/frontend/js/features/review-panel-new/components/review-panel-entry.tsx b/services/web/frontend/js/features/review-panel-new/components/review-panel-entry.tsx index 20784e45f9..4186f7a1a9 100644 --- a/services/web/frontend/js/features/review-panel-new/components/review-panel-entry.tsx +++ b/services/web/frontend/js/features/review-panel-new/components/review-panel-entry.tsx @@ -45,7 +45,7 @@ export const ReviewPanelEntry: FC<{ }) => { const state = useCodeMirrorStateContext() const view = useCodeMirrorViewContext() - const { openDocId, getCurrentDocId } = useEditorManagerContext() + const { openDocWithId, getCurrentDocumentId } = useEditorManagerContext() const [selected, setSelected] = useState(false) const [focused, setFocused] = useState(false) const [textareaFocused, setTextareaFocused] = useState(false) @@ -89,8 +89,8 @@ export const ReviewPanelEntry: FC<{ return } - if (getCurrentDocId() !== docId) { - openDocId(docId, { gotoOffset: position, keepCurrentView: true }) + if (getCurrentDocumentId() !== docId) { + openDocWithId(docId, { gotoOffset: position, keepCurrentView: true }) } else { setTimeout(() => view.dispatch({ @@ -101,12 +101,12 @@ export const ReviewPanelEntry: FC<{ } }, [ - getCurrentDocId, + getCurrentDocumentId, docId, selectLineOnFocus, view, position, - openDocId, + openDocWithId, reviewPanelOpen, ] ) diff --git a/services/web/frontend/js/features/source-editor/hooks/use-included-file.ts b/services/web/frontend/js/features/source-editor/hooks/use-included-file.ts index 33ce4e20c7..986d3f8332 100644 --- a/services/web/frontend/js/features/source-editor/hooks/use-included-file.ts +++ b/services/web/frontend/js/features/source-editor/hooks/use-included-file.ts @@ -12,7 +12,7 @@ import { export const useIncludedFile = (argumentType: string) => { const state = useCodeMirrorStateContext() const { findEntityByPath } = useFileTreePathContext() - const { openDocId } = useEditorManagerContext() + const { openDocWithId } = useEditorManagerContext() const openIncludedFile = useCallback(() => { const name = readIncludedPath(state, argumentType) @@ -21,12 +21,12 @@ export const useIncludedFile = (argumentType: string) => { for (const extension of ['.tex', '']) { const result = findEntityByPath(`${name}${extension}`) if (result) { - return openDocId(result.entity._id) + return openDocWithId(result.entity._id) } } // TODO: handle file not found } - }, [argumentType, findEntityByPath, openDocId, state]) + }, [argumentType, findEntityByPath, openDocWithId, state]) return { openIncludedFile } } diff --git a/services/web/frontend/js/shared/context/file-tree-data-context.tsx b/services/web/frontend/js/shared/context/file-tree-data-context.tsx index 5475c234c1..13c3e18e23 100644 --- a/services/web/frontend/js/shared/context/file-tree-data-context.tsx +++ b/services/web/frontend/js/shared/context/file-tree-data-context.tsx @@ -178,7 +178,7 @@ export function useFileTreeData() { export const FileTreeDataProvider: FC = ({ children }) => { const [project] = useScopeValue('project') - const [openDocId] = useScopeValue('editor.open_doc_id') + const [currentDocumentId] = useScopeValue('editor.open_doc_id') const [, setOpenDocName] = useScopeValueSetterOnly('editor.open_doc_name') const [permissionsLevel] = useScopeValue('permissionsLevel') const { fileTreeFromHistory, snapshot, snapshotVersion } = @@ -267,11 +267,11 @@ export const FileTreeDataProvider: FC = ({ children }) => { newName, id, }) - if (id === openDocId) { + if (id === currentDocumentId) { setOpenDocName(newName) } }, - [openDocId, setOpenDocName] + [currentDocumentId, setOpenDocName] ) const dispatchDelete = useCallback((id: string) => { diff --git a/services/web/frontend/js/shared/context/local-compile-context.tsx b/services/web/frontend/js/shared/context/local-compile-context.tsx index 4924160804..6cceec8ef5 100644 --- a/services/web/frontend/js/shared/context/local-compile-context.tsx +++ b/services/web/frontend/js/shared/context/local-compile-context.tsx @@ -115,7 +115,7 @@ export const LocalCompileProvider: FC = ({ children }) => { const ide = useIdeContext() const { hasPremiumCompile, isProjectOwner } = useEditorContext() - const { openDocId, openDocs } = useEditorManagerContext() + const { openDocWithId, openDocs } = useEditorManagerContext() const { _id: projectId, rootDocId } = useProjectContext() @@ -620,14 +620,14 @@ export const LocalCompileProvider: FC = ({ children }) => { const result = findEntityByPath(entry.file) if (result && result.type === 'doc') { - openDocId(result.entity._id, { + openDocWithId(result.entity._id, { gotoLine: entry.line ?? undefined, gotoColumn: entry.column ?? undefined, keepCurrentView, }) } }, - [findEntityByPath, openDocId] + [findEntityByPath, openDocWithId] ) // clear the cache then run a compile, triggered by a menu item diff --git a/services/web/frontend/js/shared/context/mock/mock-ide.js b/services/web/frontend/js/shared/context/mock/mock-ide.js index 52747022c6..c47651031a 100644 --- a/services/web/frontend/js/shared/context/mock/mock-ide.js +++ b/services/web/frontend/js/shared/context/mock/mock-ide.js @@ -55,7 +55,7 @@ export const getMockIde = () => { }, editorManager: { openDoc: () => {}, - getCurrentDocId: () => {}, + getCurrentDocumentId: () => {}, }, } } diff --git a/services/web/frontend/stories/decorators/scope.tsx b/services/web/frontend/stories/decorators/scope.tsx index 3aa56a0466..904f7d6fb0 100644 --- a/services/web/frontend/stories/decorators/scope.tsx +++ b/services/web/frontend/stories/decorators/scope.tsx @@ -103,7 +103,7 @@ const initialize = () => { new SocketIOMock() ) as unknown as Socket, editorManager: { - getCurrentDocId: () => 'foo', + getCurrentDocumentId: () => 'foo', openDoc: (id: string, options: unknown) => { console.log('open doc', id, options) }, diff --git a/services/web/test/frontend/components/pdf-preview/pdf-logs-entries.spec.tsx b/services/web/test/frontend/components/pdf-preview/pdf-logs-entries.spec.tsx index df3dd89fa7..d1c0a81c6f 100644 --- a/services/web/test/frontend/components/pdf-preview/pdf-logs-entries.spec.tsx +++ b/services/web/test/frontend/components/pdf-preview/pdf-logs-entries.spec.tsx @@ -36,7 +36,7 @@ describe('', function () { const EditorManagerProvider: FC = ({ children }) => { const value = { - openDocId: cy.spy().as('openDocId'), + openDocWithId: cy.spy().as('openDocWithId'), // @ts-ignore openDocs: new OpenDocuments(), } as unknown as EditorManager @@ -96,7 +96,7 @@ describe('', function () { }).click() cy.get('@findEntityByPath').should('have.been.calledOnceWith', 'main.tex') - cy.get('@openDocId').should( + cy.get('@openDocWithId').should( 'have.been.calledOnceWith', fakeFindEntityResult.entity._id, { @@ -136,7 +136,7 @@ describe('', function () { }) cy.get('@findEntityByPath').should('have.been.calledOnce') - cy.get('@openDocId').should( + cy.get('@openDocWithId').should( 'have.been.calledOnceWith', fakeFindEntityResult.entity._id, { @@ -168,7 +168,7 @@ describe('', function () { }).click() cy.get('@findEntityByPath').should('not.have.been.called') - cy.get('@openDocId').should('not.have.been.called') + cy.get('@openDocWithId').should('not.have.been.called') cy.get('@postDetachMessage').should('have.been.calledWith', { role: 'detached', event: 'action-sync-to-entry', diff --git a/services/web/test/frontend/helpers/editor-providers.jsx b/services/web/test/frontend/helpers/editor-providers.jsx index c85150c167..a86d28f460 100644 --- a/services/web/test/frontend/helpers/editor-providers.jsx +++ b/services/web/test/frontend/helpers/editor-providers.jsx @@ -72,7 +72,7 @@ export function EditorProviders({ getPreviewByPath: path => ({ url: path, extension: 'png' }), }, editorManager = { - getCurrentDocId: () => 'foo', + getCurrentDocumentId: () => 'foo', getCurrentDocValue: () => {}, openDoc: sinon.stub(), },