From 34fa28c90b2958956b7eec29529c4191c318c16a Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 11 Jul 2023 14:28:53 +0100 Subject: [PATCH] Hide most toolbar buttons for non-latex documents (#13725) GitOrigin-RevId: 3bf487d86d1a465a1653b40891277380270ea7ff --- .../components/codemirror-toolbar.tsx | 13 +- .../components/toolbar/toolbar-items.tsx | 256 +++++++++--------- .../languages/bibtex/bibtex-language.ts | 1 + .../languages/latex/latex-language.ts | 1 + 4 files changed, 147 insertions(+), 124 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/components/codemirror-toolbar.tsx b/services/web/frontend/js/features/source-editor/components/codemirror-toolbar.tsx index 7b92b0fb10..3203687d07 100644 --- a/services/web/frontend/js/features/source-editor/components/codemirror-toolbar.tsx +++ b/services/web/frontend/js/features/source-editor/components/codemirror-toolbar.tsx @@ -20,6 +20,7 @@ import DetachCompileButtonWrapper from '../../pdf-preview/components/detach-comp import getMeta from '../../../utils/meta' import { isVisual } from '../extensions/visual/visual' import SplitTestBadge from '../../../shared/components/split-test-badge' +import { language } from '@codemirror/language' export const CodeMirrorToolbar = () => { const view = useCodeMirrorViewContext() @@ -44,6 +45,8 @@ const Toolbar = memo(function Toolbar() { const overflowBeforeRef = useRef(null) const overflowedItemsRef = useRef>(new Set()) + const languageName = state.facet(language)?.name + const { open: overflowOpen, onToggle: setOverflowOpen, @@ -97,7 +100,7 @@ const Toolbar = memo(function Toolbar() { return (
{showSourceToolbar && } - +
- +
@@ -121,7 +128,7 @@ const Toolbar = memo(function Toolbar() { active={searchPanelOpen(state)} icon="search" /> - {!isVisual(view) && ( + {languageName === 'latex' && !isVisual(view) && ( -}> = memo(function ToolbarItems({ state, overflowed }) { + languageName?: string +}> = memo(function ToolbarItems({ state, overflowed, languageName }) { const { t } = useTranslation() const { toggleSymbolPalette, showSymbolPalette } = useEditorContext() const isActive = withinFormattingCommand(state) @@ -70,128 +71,141 @@ export const ToolbarItems: FC<{ />
)} - {showGroup('group-section') && ( -
- -
- )} - {showGroup('group-format') && ( -
- - -
- )} - {showGroup('group-math') && ( -
- - {symbolPaletteAvailable && ( - + {languageName === 'latex' && ( + <> + {showGroup('group-section') && ( +
+ +
)} -
- )} - {showGroup('group-misc') && ( -
- - - -
- )} - {showGroup('group-list') && ( -
- - - - -
+ {showGroup('group-math') && ( +
+ + {symbolPaletteAvailable && ( + + )} +
+ )} + {showGroup('group-misc') && ( +
+ + + +
+ )} + {showGroup('group-list') && ( +
+ + + + +
+ )} + )} ) diff --git a/services/web/frontend/js/features/source-editor/languages/bibtex/bibtex-language.ts b/services/web/frontend/js/features/source-editor/languages/bibtex/bibtex-language.ts index e0f9d45d9a..c9dbdb4d26 100644 --- a/services/web/frontend/js/features/source-editor/languages/bibtex/bibtex-language.ts +++ b/services/web/frontend/js/features/source-editor/languages/bibtex/bibtex-language.ts @@ -3,6 +3,7 @@ import { parser } from '../../lezer-bibtex/bibtex.mjs' import { bibtexEntryCompletions } from './completions/snippets' export const BibTeXLanguage = LRLanguage.define({ + name: 'bibtex', parser, languageData: { autocomplete: bibtexEntryCompletions, diff --git a/services/web/frontend/js/features/source-editor/languages/latex/latex-language.ts b/services/web/frontend/js/features/source-editor/languages/latex/latex-language.ts index 8b3dd5ce77..f906154539 100644 --- a/services/web/frontend/js/features/source-editor/languages/latex/latex-language.ts +++ b/services/web/frontend/js/features/source-editor/languages/latex/latex-language.ts @@ -48,6 +48,7 @@ const typeMap: Record = { } export const LaTeXLanguage = LRLanguage.define({ + name: 'latex', parser: parser.configure({ props: [ foldNodeProp.add({