editor-manager-context-adapter.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { ReactScopeValueStore } from '@/features/ide-react/scope-value-store/react-scope-value-store'
  2. import customLocalStorage from '@/infrastructure/local-storage'
  3. export function populateEditorScope(
  4. store: ReactScopeValueStore,
  5. projectId: string
  6. ) {
  7. // This value is not used in the React code. It's just here to prevent errors
  8. // from EditorProvider
  9. store.set('state.loading', false)
  10. store.set('project.name', null)
  11. store.set('editor', {
  12. showSymbolPalette: false,
  13. toggleSymbolPalette: () => {},
  14. sharejs_doc: null,
  15. open_doc_id: null,
  16. open_doc_name: null,
  17. opening: true,
  18. trackChanges: false,
  19. wantTrackChanges: false,
  20. // No Ace here
  21. newSourceEditor: true,
  22. error_state: false,
  23. })
  24. store.persisted(
  25. 'editor.showVisual',
  26. showVisualFallbackValue(projectId),
  27. `editor.lastUsedMode`,
  28. {
  29. toPersisted: showVisual => (showVisual ? 'visual' : 'code'),
  30. fromPersisted: mode => mode === 'visual',
  31. }
  32. )
  33. }
  34. function showVisualFallbackValue(projectId: string) {
  35. const editorModeKey = `editor.mode.${projectId}`
  36. const editorModeVal = customLocalStorage.getItem(editorModeKey)
  37. if (editorModeVal) {
  38. // clean up the old key
  39. customLocalStorage.removeItem(editorModeKey)
  40. }
  41. return editorModeVal === 'rich-text'
  42. }