Remove hidden comment button from editor toolbar (#17386)

GitOrigin-RevId: 61b3725a7b2112c6e5abca0349b1be910e97266a
This commit is contained in:
Alf Eaton 2024-03-07 10:46:01 +00:00 committed by Copybot
parent 749660e168
commit 5df35093ea
4 changed files with 2 additions and 46 deletions

View file

@ -1335,7 +1335,6 @@
"too_many_search_results": "",
"too_recently_compiled": "",
"took_a_while": "",
"toolbar_add_comment": "",
"toolbar_bullet_list": "",
"toolbar_choose_section_heading_level": "",
"toolbar_decrease_indent": "",

View file

@ -1,15 +1,11 @@
import { FC, memo, useCallback } from 'react'
import { EditorSelection, EditorState } from '@codemirror/state'
import { EditorView } from '@codemirror/view'
import { FC, memo } from 'react'
import { EditorState } from '@codemirror/state'
import { useEditorContext } from '../../../../shared/context/editor-context'
import useScopeEventEmitter from '../../../../shared/hooks/use-scope-event-emitter'
import { useLayoutContext } from '../../../../shared/context/layout-context'
import { withinFormattingCommand } from '../../utils/tree-operations/ancestors'
import { ToolbarButton } from './toolbar-button'
import { redo, undo } from '@codemirror/commands'
import * as commands from '../../extensions/toolbar/commands'
import { SectionHeadingDropdown } from './section-heading-dropdown'
import { canAddComment } from '../../extensions/toolbar/comments'
import getMeta from '../../../../utils/meta'
import { InsertFigureDropdown } from './insert-figure-dropdown'
import { useTranslation } from 'react-i18next'
@ -34,22 +30,6 @@ export const ToolbarItems: FC<{
const { t } = useTranslation()
const { toggleSymbolPalette, showSymbolPalette } = useEditorContext()
const isActive = withinFormattingCommand(state)
const addCommentEmitter = useScopeEventEmitter('comment:start_adding')
const { setReviewPanelOpen } = useLayoutContext()
const addComment = useCallback(
(view: EditorView) => {
const range = view.state.selection.main
if (range.empty) {
const line = view.state.doc.lineAt(range.head)
view.dispatch({
selection: EditorSelection.range(line.from, line.to),
})
}
setReviewPanelOpen(true)
addCommentEmitter()
},
[addCommentEmitter, setReviewPanelOpen]
)
const symbolPaletteAvailable = getMeta('ol-symbolPaletteAvailable')
const showGroup = (group: string) => !overflowed || overflowed.has(group)
@ -146,14 +126,6 @@ export const ToolbarItems: FC<{
command={commands.insertCite}
icon="book"
/>
<ToolbarButton
id="toolbar-add-comment"
label={t('toolbar_add_comment')}
command={addComment}
disabled={!canAddComment(state)}
icon="comment"
hidden // enable this if an alternative to the floating "Add Comment" button is needed
/>
<InsertFigureDropdown />
<TableInserterDropdown />
</div>

View file

@ -1,14 +0,0 @@
import { EditorState } from '@codemirror/state'
export const canAddComment = (state: EditorState) => {
// TODO: permissions.comment
// allow an empty selection if there's content on the line
const range = state.selection.main
if (range.empty) {
return state.doc.lineAt(range.head).text.length > 0
}
// always allow a non-empty selection
return true
}

View file

@ -1927,7 +1927,6 @@
"too_many_search_results": "There are more than 100 results. Please refine your search.",
"too_recently_compiled": "This project was compiled very recently, so this compile has been skipped.",
"took_a_while": "That took a while...",
"toolbar_add_comment": "Add Comment",
"toolbar_bullet_list": "Bullet List",
"toolbar_choose_section_heading_level": "Choose section heading level",
"toolbar_decrease_indent": "Decrease Indent",