mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #23026 from overleaf/mj-wc-settings-second-try
[web] Move write and cite setting storage GitOrigin-RevId: 88a234c15b4dd2a9b451170e3b474d88bb6d45f7
This commit is contained in:
committed by
Copybot
parent
0d42173034
commit
77dd468c20
@@ -792,6 +792,7 @@ const _ProjectController = {
|
||||
lineHeight: user.ace.lineHeight || 'normal',
|
||||
overallTheme: user.ace.overallTheme,
|
||||
mathPreview: user.ace.mathPreview,
|
||||
referencesSearchMode: user.ace.referencesSearchMode,
|
||||
},
|
||||
privilegeLevel,
|
||||
anonymous,
|
||||
|
||||
@@ -386,6 +386,11 @@ async function updateUserSettings(req, res, next) {
|
||||
if (req.body.mathPreview != null) {
|
||||
user.ace.mathPreview = req.body.mathPreview
|
||||
}
|
||||
if (req.body.referencesSearchMode != null) {
|
||||
const mode =
|
||||
req.body.referencesSearchMode === 'simple' ? 'simple' : 'advanced'
|
||||
user.ace.referencesSearchMode = mode
|
||||
}
|
||||
await user.save()
|
||||
|
||||
const newEmail = req.body.email?.trim().toLowerCase()
|
||||
|
||||
@@ -97,6 +97,7 @@ const UserSchema = new Schema(
|
||||
fontFamily: { type: String },
|
||||
lineHeight: { type: String },
|
||||
mathPreview: { type: Boolean, default: true },
|
||||
referencesSearchMode: { type: String, default: 'advanced' }, // 'advanced' or 'simple'
|
||||
},
|
||||
features: {
|
||||
collaborators: {
|
||||
|
||||
@@ -115,6 +115,7 @@ export const createExtensions = (options: Record<string, any>): Extension[] => [
|
||||
autoComplete({
|
||||
enabled: options.settings.autoComplete,
|
||||
projectFeatures: options.projectFeatures,
|
||||
referencesSearchMode: options.settings.referencesSearchMode,
|
||||
}),
|
||||
|
||||
// NOTE: `keybindings` needs to be before `language` so that Vim/Emacs bindings take
|
||||
|
||||
@@ -96,6 +96,7 @@ function useCodeMirrorScope(view: EditorView) {
|
||||
mode,
|
||||
syntaxValidation,
|
||||
mathPreview,
|
||||
referencesSearchMode,
|
||||
} = userSettings
|
||||
|
||||
const [cursorHighlights] = useScopeValue<Record<string, Highlight[]>>(
|
||||
@@ -169,6 +170,7 @@ function useCodeMirrorScope(view: EditorView) {
|
||||
mode,
|
||||
syntaxValidation,
|
||||
mathPreview,
|
||||
referencesSearchMode,
|
||||
})
|
||||
|
||||
const currentDocRef = useRef({
|
||||
@@ -430,6 +432,7 @@ function useCodeMirrorScope(view: EditorView) {
|
||||
setAutoComplete({
|
||||
enabled: autoComplete,
|
||||
projectFeatures: projectFeaturesRef.current,
|
||||
referencesSearchMode: settingsRef.current.referencesSearchMode,
|
||||
})
|
||||
)
|
||||
})
|
||||
@@ -458,6 +461,10 @@ function useCodeMirrorScope(view: EditorView) {
|
||||
})
|
||||
}, [view, mathPreview])
|
||||
|
||||
useEffect(() => {
|
||||
settingsRef.current.referencesSearchMode = referencesSearchMode
|
||||
}, [referencesSearchMode])
|
||||
|
||||
const emitSyncToPdf = useScopeEventEmitter('cursor:editor:syncToPdf')
|
||||
|
||||
const handleGoToLine = useCallback(
|
||||
|
||||
@@ -25,6 +25,7 @@ const defaultSettings: UserSettings = {
|
||||
fontFamily: 'monaco',
|
||||
lineHeight: 'normal',
|
||||
mathPreview: true,
|
||||
referencesSearchMode: 'advanced',
|
||||
}
|
||||
|
||||
type UserSettingsContextValue = {
|
||||
|
||||
@@ -425,6 +425,33 @@ describe('UserController', function () {
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should set referencesSearchMode to advanced', function (done) {
|
||||
this.req.body = { referencesSearchMode: 'advanced' }
|
||||
this.res.sendStatus = code => {
|
||||
this.user.ace.referencesSearchMode.should.equal('advanced')
|
||||
done()
|
||||
}
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should set referencesSearchMode to simple', function (done) {
|
||||
this.req.body = { referencesSearchMode: 'simple' }
|
||||
this.res.sendStatus = code => {
|
||||
this.user.ace.referencesSearchMode.should.equal('simple')
|
||||
done()
|
||||
}
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should not allow arbitrary referencesSearchMode', function (done) {
|
||||
this.req.body = { referencesSearchMode: 'foobar' }
|
||||
this.res.sendStatus = code => {
|
||||
this.user.ace.referencesSearchMode.should.equal('advanced')
|
||||
done()
|
||||
}
|
||||
this.UserController.updateUserSettings(this.req, this.res)
|
||||
})
|
||||
|
||||
it('should send an error if the email is 0 len', function (done) {
|
||||
this.req.body.email = ''
|
||||
this.res.sendStatus = function (code) {
|
||||
|
||||
@@ -15,4 +15,5 @@ export type UserSettings = {
|
||||
fontFamily: FontFamily
|
||||
lineHeight: LineHeight
|
||||
mathPreview: boolean
|
||||
referencesSearchMode: 'advanced' | 'simple'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user