mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 13:58:46 -05:00
da2f7ff153
* Store editor selection on a per-user rather than per-project basis * set code editor if rich_text=false * format fix GitOrigin-RevId: 8efc33b682de211162e674839e6b891ec04e542e
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { ReactScopeValueStore } from '@/features/ide-react/scope-value-store/react-scope-value-store'
|
|
import customLocalStorage from '@/infrastructure/local-storage'
|
|
|
|
export function populateEditorScope(
|
|
store: ReactScopeValueStore,
|
|
projectId: string
|
|
) {
|
|
// This value is not used in the React code. It's just here to prevent errors
|
|
// from EditorProvider
|
|
store.set('state.loading', false)
|
|
|
|
store.set('project.name', null)
|
|
|
|
store.set('editor', {
|
|
showSymbolPalette: false,
|
|
toggleSymbolPalette: () => {},
|
|
sharejs_doc: null,
|
|
open_doc_id: null,
|
|
open_doc_name: null,
|
|
opening: true,
|
|
trackChanges: false,
|
|
wantTrackChanges: false,
|
|
// No Ace here
|
|
newSourceEditor: true,
|
|
error_state: false,
|
|
})
|
|
store.persisted(
|
|
'editor.showVisual',
|
|
showVisualFallbackValue(projectId),
|
|
`editor.lastUsedMode`,
|
|
{
|
|
toPersisted: showVisual => (showVisual ? 'visual' : 'code'),
|
|
fromPersisted: mode => mode === 'visual',
|
|
}
|
|
)
|
|
}
|
|
|
|
function showVisualFallbackValue(projectId: string) {
|
|
const editorModeKey = `editor.mode.${projectId}`
|
|
const editorModeVal = customLocalStorage.getItem(editorModeKey)
|
|
|
|
if (editorModeVal) {
|
|
// clean up the old key
|
|
customLocalStorage.removeItem(editorModeKey)
|
|
}
|
|
|
|
return editorModeVal === 'rich-text'
|
|
}
|