From 43f1a7fd2e5b935366c42f56ea56b207b0fbbc9c Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Thu, 19 Oct 2023 09:35:48 +0100 Subject: [PATCH] Enable editor toolbar for read-only users (#15279) * Make the editor toolbar available for read-only users * Hide replace in search form when read-only GitOrigin-RevId: 2867868d0914da797294084df37163e92578cd57 --- .../components/codemirror-search-form.tsx | 68 +++++++++++-------- .../components/codemirror-toolbar.tsx | 6 +- .../extensions/toolbar/toolbar-panel.ts | 3 - 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx b/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx index 270949c023..f04299fbb0 100644 --- a/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx +++ b/services/web/frontend/js/features/source-editor/components/codemirror-search-form.tsx @@ -214,6 +214,8 @@ const CodeMirrorSearchForm: FC = () => { return getSearchQuery(state) }, [state]) + const showReplace = !state.readOnly + return ( // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
{ - - - + className="ol-cm-search-input-group ol-cm-search-replace-input" + > + + + )}
{ )}
-
- + {showReplace && ( +
+ - -
+ +
+ )}
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 cac609ff86..6fcafa912f 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 @@ -113,10 +113,12 @@ const Toolbar = memo(function Toolbar() { return null } + const showActions = !state.readOnly && !insideTable + return (
{showSourceToolbar && } - {!insideTable && ( + {showActions && ( )}
- {!insideTable && ( + {showActions && ( () const toolbarState = StateField.define({ create: () => true, update: (value, tr) => { - if (tr.state.readOnly) { - return false - } for (const effect of tr.effects) { if (effect.is(toggleToolbarEffect)) { value = effect.value