diff --git a/services/web/frontend/js/features/source-editor/hooks/use-context-menu-items.tsx b/services/web/frontend/js/features/source-editor/hooks/use-context-menu-items.tsx index 13a7c8416c..2dd4b1020b 100644 --- a/services/web/frontend/js/features/source-editor/hooks/use-context-menu-items.tsx +++ b/services/web/frontend/js/features/source-editor/hooks/use-context-menu-items.tsx @@ -32,6 +32,7 @@ import { ContextMenuItemSegmentation, } from '../utils/context-menu-analytics' import { isCursorOnEmptyLine } from '../utils/is-cursor-on-empty-line' +import { selectAll } from '@codemirror/commands' export const useContextMenuItems = () => { const view = useCodeMirrorViewContext() @@ -144,6 +145,9 @@ export const useContextMenuItems = () => { return result } ) + const handleSelectAll = wrapForContextMenu('select-all', () => + selectAll(view) + ) const handleDelete = wrapForContextMenu('delete', () => commands.deleteSelection(view) ) @@ -223,6 +227,13 @@ export const useContextMenuItems = () => { show: canEdit, shortcut: inVisualMode ? getShortcut('paste-special') : undefined, }, + { + label: t('select_all'), + handler: handleSelectAll, + disabled: false, + show: true, + shortcut: getShortcut('select-all'), + }, { label: t('delete'), handler: handleDelete, diff --git a/services/web/frontend/js/features/source-editor/utils/context-menu-analytics.ts b/services/web/frontend/js/features/source-editor/utils/context-menu-analytics.ts index 446e36804a..29ceb8be46 100644 --- a/services/web/frontend/js/features/source-editor/utils/context-menu-analytics.ts +++ b/services/web/frontend/js/features/source-editor/utils/context-menu-analytics.ts @@ -6,6 +6,7 @@ export type ContextMenuItemSegmentation = | 'paste' | 'paste-without-formatting' | 'paste-with-formatting' + | 'select-all' | 'give-feedback' | 'delete' | 'jump-to-location-in-pdf' diff --git a/services/web/test/frontend/features/source-editor/components/codemirror-editor-context-menu.spec.tsx b/services/web/test/frontend/features/source-editor/components/codemirror-editor-context-menu.spec.tsx index d53153e62b..b0140c4ee4 100644 --- a/services/web/test/frontend/features/source-editor/components/codemirror-editor-context-menu.spec.tsx +++ b/services/web/test/frontend/features/source-editor/components/codemirror-editor-context-menu.spec.tsx @@ -663,7 +663,7 @@ describe('editor context menu', { scrollBehavior: false }, function () { }) describe('when a user does not have edit permissions', function () { - it('should only show Copy and Comment (hidden Cut, Paste, Delete, Suggest edits)', function () { + it('should only show Copy, Select all, Comment (hidden Cut, Paste, Delete, Suggest edits)', function () { const scope = mockScope() scope.permissions.write = false scope.permissions.trackedWrite = false @@ -701,6 +701,7 @@ describe('editor context menu', { scrollBehavior: false }, function () { cy.findByRole('menu').within(() => { cy.findByRole('menuitem', { name: /cut/i }).should('not.exist') cy.findByRole('menuitem', { name: /copy/i }).should('be.enabled') + cy.findByRole('menuitem', { name: /select all/i }).should('be.enabled') cy.findByRole('menuitem', { name: pasteLabelMatcher }).should( 'not.exist' )