Merge pull request #29899 from overleaf/mj-dark-mode-file-flash

[web] Avoid background color flash when switching files

GitOrigin-RevId: e5d2fbb631fd54d195b9cb51b2a9db584d205138
This commit is contained in:
Mathias Jakobsen
2025-11-28 09:05:18 +00:00
committed by Copybot
parent ff5b469b20
commit 7c1a225be4
15 changed files with 145 additions and 85 deletions
@@ -14,8 +14,8 @@ export default function SettingsEditorTheme() {
const options = useMemo(() => {
const editorThemeOptions: Array<Option> =
editorThemes?.map(theme => ({
value: theme,
label: theme.replace(/_/g, ' '),
value: theme.name,
label: theme.name.replace(/_/g, ' '),
})) ?? []
const dividerOption: Option = {
@@ -26,8 +26,8 @@ export default function SettingsEditorTheme() {
const legacyEditorThemeOptions: Array<Option> =
legacyEditorThemes?.map(theme => ({
value: theme,
label: theme.replace(/_/g, ' ') + ' (Legacy)',
value: theme.name,
label: theme.name.replace(/_/g, ' ') + ' (Legacy)',
})) ?? []
return [...editorThemeOptions, dividerOption, ...legacyEditorThemeOptions]
@@ -0,0 +1,25 @@
import { FC, useMemo } from 'react'
import LoadingSpinner from '@/shared/components/loading-spinner'
import { useProjectSettingsContext } from '@/features/editor-left-menu/context/project-settings-context'
import getMeta from '@/utils/meta'
import classNames from 'classnames'
export const EditorLoadingPane: FC = () => {
const { editorTheme } = useProjectSettingsContext()
const isDark = useMemo(() => {
const themes = getMeta('ol-editorThemes') || []
const legacyThemes = getMeta('ol-legacyEditorThemes') || []
const selectedTheme =
themes.find(theme => theme.name === editorTheme) ||
legacyThemes.find(theme => theme.name === editorTheme)
return selectedTheme?.dark ?? false
}, [editorTheme])
return (
<div
className={classNames('loading-panel', { 'loading-panel-dark': isDark })}
>
<LoadingSpinner />
</div>
)
}
@@ -4,7 +4,7 @@ import SourceEditor from '@/features/source-editor/components/source-editor'
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
import { useEditorOpenDocContext } from '@/features/ide-react/context/editor-open-doc-context'
import classNames from 'classnames'
import { LoadingPane } from '@/features/ide-react/components/editor/loading-pane'
import { EditorLoadingPane } from '@/features/ide-react/components/editor/editor-loading-pane'
import { FullSizeLoadingSpinner } from '@/shared/components/loading-spinner'
import { VerticalResizeHandle } from '@/features/ide-react/components/resize/vertical-resize-handle'
import { useFileTreeOpenContext } from '@/features/ide-react/context/file-tree-open-context'
@@ -37,7 +37,7 @@ export const EditorPane: FC = () => {
className="ide-react-editor-panel"
>
<SourceEditor />
{isLoading && <LoadingPane />}
{isLoading && <EditorLoadingPane />}
</Panel>
{showSymbolPalette && (
@@ -1,10 +0,0 @@
import { FC } from 'react'
import LoadingSpinner from '@/shared/components/loading-spinner'
export const LoadingPane: FC = () => {
return (
<div className="loading-panel">
<LoadingSpinner />
</div>
)
}
@@ -1,4 +1,4 @@
import { LoadingPane } from '@/features/ide-react/components/editor/loading-pane'
import { EditorLoadingPane } from '@/features/ide-react/components/editor/editor-loading-pane'
import { useEditorOpenDocContext } from '@/features/ide-react/context/editor-open-doc-context'
import { useFileTreeOpenContext } from '@/features/ide-react/context/file-tree-open-context'
import classNames from 'classnames'
@@ -40,7 +40,7 @@ export const Editor = () => {
className="ide-redesign-editor-panel"
>
<SourceEditor />
{isLoading && <LoadingPane />}
{isLoading && <EditorLoadingPane />}
</Panel>
{showSymbolPalette && (
<>
@@ -14,8 +14,8 @@ export default function EditorThemeSetting() {
const options = useMemo(() => {
const editorThemeOptions: Array<Option> =
editorThemes?.map(theme => ({
value: theme,
label: theme.replace(/_/g, ' '),
value: theme.name,
label: theme.name.replace(/_/g, ' '),
})) ?? []
const dividerOption: Option = {
@@ -26,8 +26,8 @@ export default function EditorThemeSetting() {
const legacyEditorThemeOptions: Array<Option> =
legacyEditorThemes?.map(theme => ({
value: theme,
label: theme.replace(/_/g, ' ') + ' (Legacy)',
value: theme.name,
label: theme.name.replace(/_/g, ' ') + ' (Legacy)',
})) ?? []
return [...editorThemeOptions, dividerOption, ...legacyEditorThemeOptions]
@@ -287,7 +287,8 @@ const loadSelectedTheme = async (editorTheme: string) => {
const themes = getMeta('ol-editorThemes') || []
const legacyThemes = getMeta('ol-legacyEditorThemes') || []
const themeExists =
themes.includes(editorTheme) || legacyThemes.includes(editorTheme)
themes.some(theme => theme.name === editorTheme) ||
legacyThemes.some(theme => theme.name === editorTheme)
if (!themeExists) {
editorTheme = 'textmate' // fallback to default if the theme is not found
}
+2 -2
View File
@@ -117,7 +117,7 @@ export interface Meta {
'ol-domainCaptureEnabled': boolean | undefined
'ol-domainCaptureTestURL': string | undefined
'ol-dropbox': { error: boolean; registered: boolean }
'ol-editorThemes': string[]
'ol-editorThemes': { name: string; dark: boolean }[]
'ol-email': string
'ol-emailAddressLimit': number
'ol-error': { name: string } | undefined
@@ -188,7 +188,7 @@ export interface Meta {
'ol-labsExperiments': ActiveExperiment[] | undefined
'ol-languages': SpellCheckLanguage[]
'ol-learnedWords': string[]
'ol-legacyEditorThemes': string[]
'ol-legacyEditorThemes': { name: string; dark: boolean }[]
'ol-licenseQuantity'?: number
'ol-loadingText': string
'ol-managedGroupSubscriptions': ManagedGroupSubscription[]
@@ -7,6 +7,11 @@
.file-view .no-preview {
color: var(--content-secondary-themed);
}
.file-view .loading-panel {
color: var(--content-secondary-themed);
background: var(--bg-primary-themed);
}
}
.file-view {
@@ -77,6 +77,17 @@ $editor-toggler-bg-dark-color: color.adjust(
background-color: var(--bg-tertiary-themed);
}
}
.loading-panel {
background-color: var(--bg-light-primary);
color: var(--content-primary);
// Based on editor theme rather than overall theme
&.loading-panel-dark {
background-color: var(--bg-dark-primary);
color: var(--content-primary-dark);
}
}
}
.global-alerts {