From 98bf2ac055397d6797617759986060763e98dd23 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 22 Oct 2024 12:23:36 +0100 Subject: [PATCH] Disable spell check setting when doc is read-only (#21253) GitOrigin-RevId: 1053fefd953d4f60b1c2aef4170f99c6885c265d --- .../settings/settings-spell-check-language.tsx | 3 +++ .../source-editor/extensions/spelling/spellchecker.ts | 1 - .../features/source-editor/hooks/use-codemirror-scope.ts | 9 ++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-spell-check-language.tsx b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-spell-check-language.tsx index 0d52ab4b49..64430f413c 100644 --- a/services/web/frontend/js/features/editor-left-menu/components/settings/settings-spell-check-language.tsx +++ b/services/web/frontend/js/features/editor-left-menu/components/settings/settings-spell-check-language.tsx @@ -5,6 +5,7 @@ import { useProjectSettingsContext } from '../../context/project-settings-contex import SettingsMenuSelect from './settings-menu-select' import type { Optgroup } from './settings-menu-select' import { useFeatureFlag } from '@/shared/context/split-test-context' +import { useEditorContext } from '@/shared/context/editor-context' export default function SettingsSpellCheckLanguage() { const { t } = useTranslation() @@ -15,6 +16,7 @@ export default function SettingsSpellCheckLanguage() { const { spellCheckLanguage, setSpellCheckLanguage } = useProjectSettingsContext() + const { permissionsLevel } = useEditorContext() const optgroup: Optgroup = useMemo(() => { const options = (languages ?? []).filter(language => { @@ -48,6 +50,7 @@ export default function SettingsSpellCheckLanguage() { optgroup={optgroup} label={t('spell_check')} name="spellCheckLanguage" + disabled={permissionsLevel === 'readOnly'} /> ) } diff --git a/services/web/frontend/js/features/source-editor/extensions/spelling/spellchecker.ts b/services/web/frontend/js/features/source-editor/extensions/spelling/spellchecker.ts index 72c83dc969..8bbeafca84 100644 --- a/services/web/frontend/js/features/source-editor/extensions/spelling/spellchecker.ts +++ b/services/web/frontend/js/features/source-editor/extensions/spelling/spellchecker.ts @@ -62,7 +62,6 @@ export class SpellChecker { destroy() { this._clearPendingSpellCheck() - // this.hunspellManager?.destroy() } _abortRequest() { diff --git a/services/web/frontend/js/features/source-editor/hooks/use-codemirror-scope.ts b/services/web/frontend/js/features/source-editor/hooks/use-codemirror-scope.ts index b28d6885d8..d44be37b3b 100644 --- a/services/web/frontend/js/features/source-editor/hooks/use-codemirror-scope.ts +++ b/services/web/frontend/js/features/source-editor/hooks/use-codemirror-scope.ts @@ -108,9 +108,12 @@ function useCodeMirrorScope(view: EditorView) { 'onlineUserCursorHighlights' ) - const [spellCheckLanguage] = useScopeValue( - 'project.spellCheckLanguage' - ) + let [spellCheckLanguage] = useScopeValue('project.spellCheckLanguage') + // spell check is off when read-only + if (!permissions.write) { + spellCheckLanguage = '' + } + const [projectFeatures] = useScopeValue>( 'project.features'