mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Store editor selection on a per-user rather than per-project basis (#16246)
* Store editor selection on a per-user rather than per-project basis * set code editor if rich_text=false * format fix GitOrigin-RevId: 8efc33b682de211162e674839e6b891ec04e542e
This commit is contained in:
parent
b0028a2789
commit
da2f7ff153
3 changed files with 38 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
|||
import { ReactScopeValueStore } from '@/features/ide-react/scope-value-store/react-scope-value-store'
|
||||
import customLocalStorage from '@/infrastructure/local-storage'
|
||||
|
||||
export function populateEditorScope(
|
||||
store: ReactScopeValueStore,
|
||||
|
@ -23,8 +24,25 @@ export function populateEditorScope(
|
|||
newSourceEditor: true,
|
||||
error_state: false,
|
||||
})
|
||||
store.persisted('editor.showVisual', false, `editor.mode.${projectId}`, {
|
||||
toPersisted: showVisual => (showVisual ? 'rich-text' : 'source'),
|
||||
fromPersisted: mode => mode === 'rich-text',
|
||||
})
|
||||
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'
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import './controllers/CompileButton'
|
|||
import './controllers/SwitchToPDFButton'
|
||||
import '../metadata/services/metadata'
|
||||
import { debugConsole } from '@/utils/debugging'
|
||||
import customLocalStorage from '@/infrastructure/local-storage'
|
||||
|
||||
let EditorManager
|
||||
|
||||
|
@ -161,10 +162,20 @@ export default EditorManager = (function () {
|
|||
}
|
||||
|
||||
showVisual() {
|
||||
return (
|
||||
this.localStorage(`editor.mode.${this.$scope.project_id}`) ===
|
||||
'rich-text'
|
||||
)
|
||||
const editorModeKey = `editor.mode.${this.$scope.project_id}`
|
||||
const editorModeVal = this.localStorage(editorModeKey)
|
||||
|
||||
if (editorModeVal) {
|
||||
// clean up the old key
|
||||
customLocalStorage.removeItem(editorModeKey)
|
||||
}
|
||||
|
||||
const lastUsedMode = this.localStorage(`editor.lastUsedMode`)
|
||||
if (lastUsedMode) {
|
||||
return lastUsedMode === 'visual'
|
||||
} else {
|
||||
return editorModeVal === 'rich-text'
|
||||
}
|
||||
}
|
||||
|
||||
autoOpenDoc() {
|
||||
|
|
|
@ -5,10 +5,7 @@ App.controller('EditorLoaderController', [
|
|||
'localStorage',
|
||||
function ($scope, localStorage) {
|
||||
$scope.$watch('editor.showVisual', function (val) {
|
||||
localStorage(
|
||||
`editor.mode.${$scope.project_id}`,
|
||||
val === true ? 'rich-text' : 'source'
|
||||
)
|
||||
localStorage(`editor.lastUsedMode`, val === true ? 'visual' : 'code')
|
||||
})
|
||||
},
|
||||
])
|
||||
|
|
Loading…
Reference in a new issue