mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-03 14:19:01 +02:00
Standardise naming of openDocId as openDocWithId or currentDocumentId (#23307)
GitOrigin-RevId: d71b6d878188c7b916f02a3749976ecd96d648a3
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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<boolean>('editor.showVisual')
|
||||
const [currentDocument, setCurrentDocument] =
|
||||
useScopeValue<DocumentContainer>('editor.sharejs_doc')
|
||||
const [openDocId, setOpenDocId] = useScopeValue<DocId | null>(
|
||||
const [currentDocumentId, setCurrentDocumentId] = useScopeValue<DocId | null>(
|
||||
'editor.open_doc_id'
|
||||
)
|
||||
const [, setOpenDocName] = useScopeValue<string | null>(
|
||||
@@ -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,
|
||||
|
||||
@@ -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<BinaryFile | null>('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.
|
||||
|
||||
@@ -76,7 +76,7 @@ const OnlineUsersContext = createContext<OnlineUsersContextValue | undefined>(
|
||||
export const OnlineUsersProvider: FC = ({ children }) => {
|
||||
const { eventEmitter } = useIdeReactContext()
|
||||
const { socket } = useConnectionContext()
|
||||
const [openDocId] = useScopeValue<string | null>('editor.open_doc_id')
|
||||
const [currentDocumentId] = useScopeValue<string | null>('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) => {
|
||||
|
||||
+3
-3
@@ -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'
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+5
-5
@@ -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,
|
||||
]
|
||||
)
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ export function useFileTreeData() {
|
||||
|
||||
export const FileTreeDataProvider: FC = ({ children }) => {
|
||||
const [project] = useScopeValue<Project>('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) => {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -55,7 +55,7 @@ export const getMockIde = () => {
|
||||
},
|
||||
editorManager: {
|
||||
openDoc: () => {},
|
||||
getCurrentDocId: () => {},
|
||||
getCurrentDocumentId: () => {},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
},
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('<PdfLogsEntries/>', 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('<PdfLogsEntries/>', 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('<PdfLogsEntries/>', 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('<PdfLogsEntries/>', 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',
|
||||
|
||||
@@ -72,7 +72,7 @@ export function EditorProviders({
|
||||
getPreviewByPath: path => ({ url: path, extension: 'png' }),
|
||||
},
|
||||
editorManager = {
|
||||
getCurrentDocId: () => 'foo',
|
||||
getCurrentDocumentId: () => 'foo',
|
||||
getCurrentDocValue: () => {},
|
||||
openDoc: sinon.stub(),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user