|
|
@@ -8,6 +8,7 @@ import {
|
|
|
SetStateAction,
|
|
|
FC,
|
|
|
useState,
|
|
|
+ useRef,
|
|
|
} from 'react'
|
|
|
import useDetachLayout from '../hooks/use-detach-layout'
|
|
|
import localStorage from '../../infrastructure/local-storage'
|
|
|
@@ -61,6 +62,7 @@ export type LayoutContextValue = LayoutContextOwnStates & {
|
|
|
pdfPreviewOpen: boolean
|
|
|
setProjectSearchIsOpen: Dispatch<SetStateAction<boolean>>
|
|
|
setOpenFile: Dispatch<SetStateAction<BinaryFile | null>>
|
|
|
+ restoreView: () => void
|
|
|
}
|
|
|
|
|
|
const debugPdfDetach = getMeta('ol-debugPdfDetach')
|
|
|
@@ -85,6 +87,8 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
|
|
const historyToggleEmitter = useScopeEventEmitter('history:toggle', true)
|
|
|
const { isOpen: railIsOpen, setIsOpen: setRailIsOpen } = useRailContext()
|
|
|
const [prevRailIsOpen, setPrevRailIsOpen] = useState(railIsOpen)
|
|
|
+ // Whether we came from a file or a document when we left the ide
|
|
|
+ const lastIdeView = useRef<IdeView>('editor')
|
|
|
|
|
|
const setView = useCallback(
|
|
|
(value: IdeView | null) => {
|
|
|
@@ -103,12 +107,8 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
|
|
setRailIsOpen(prevRailIsOpen)
|
|
|
}
|
|
|
|
|
|
- if (value === 'editor' && openFile) {
|
|
|
- // if a file is currently opened, ensure the view is 'file' instead of
|
|
|
- // 'editor' when the 'editor' view is requested. This is to ensure
|
|
|
- // that the entity selected in the file tree is the one visible and
|
|
|
- // that docs don't take precedence over files.
|
|
|
- return 'file'
|
|
|
+ if (value === 'editor' || value === 'file') {
|
|
|
+ lastIdeView.current = value
|
|
|
}
|
|
|
|
|
|
return value
|
|
|
@@ -117,7 +117,6 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
|
|
[
|
|
|
_setView,
|
|
|
setRailIsOpen,
|
|
|
- openFile,
|
|
|
historyToggleEmitter,
|
|
|
prevRailIsOpen,
|
|
|
setPrevRailIsOpen,
|
|
|
@@ -125,6 +124,10 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
|
|
]
|
|
|
)
|
|
|
|
|
|
+ const restoreView = useCallback(() => {
|
|
|
+ setView(lastIdeView.current ?? 'editor')
|
|
|
+ }, [setView])
|
|
|
+
|
|
|
// whether the chat pane is open
|
|
|
const [chatIsOpen, setChatIsOpen] = usePersistedState<boolean>(
|
|
|
'ui.chatOpen',
|
|
|
@@ -192,11 +195,16 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
|
|
|
|
|
const changeLayout = useCallback(
|
|
|
(newLayout: IdeLayout, newView: IdeView = 'editor') => {
|
|
|
+ const targetView = newLayout === 'sideBySide' ? 'editor' : newView
|
|
|
setPdfLayout(newLayout)
|
|
|
- setView(newLayout === 'sideBySide' ? 'editor' : newView)
|
|
|
+ if (targetView === 'editor') {
|
|
|
+ restoreView()
|
|
|
+ } else {
|
|
|
+ setView(targetView)
|
|
|
+ }
|
|
|
setLayoutInLocalStorage(newLayout)
|
|
|
},
|
|
|
- [setPdfLayout, setView]
|
|
|
+ [setPdfLayout, setView, restoreView]
|
|
|
)
|
|
|
|
|
|
// Force codemirror to reposition all tooltips to prevent an issue
|
|
|
@@ -276,6 +284,7 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
|
|
setLoadingStyleSheet,
|
|
|
setView,
|
|
|
view,
|
|
|
+ restoreView,
|
|
|
}),
|
|
|
[
|
|
|
reattach,
|
|
|
@@ -302,6 +311,7 @@ export const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
|
|
|
setLoadingStyleSheet,
|
|
|
setView,
|
|
|
view,
|
|
|
+ restoreView,
|
|
|
]
|
|
|
)
|
|
|
|