ソースを参照

Merge pull request #34152 from overleaf/mj-select-all

[web] Add select all to context menu

GitOrigin-RevId: ff5fb828db8e1cd57d1361a2e572918339e5e18b
Mathias Jakobsen 2 ヶ月 前
コミット
24dba36060

+ 11 - 0
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,

+ 1 - 0
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'

+ 2 - 1
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'
         )