Merge pull request #30495 from overleaf/mg-context-menu-paste

[web] Support paste with formatting in context menu

GitOrigin-RevId: 551ed1d49ca423395bd9bfc756e10e8d59d71ecd
This commit is contained in:
Malik Glossop
2026-01-15 14:19:03 +00:00
committed by Copybot
parent f087d125c1
commit a0fc14b367
8 changed files with 390 additions and 114 deletions
@@ -20,7 +20,9 @@ import {
cutSelection,
copySelection,
pasteWithoutFormatting,
pasteWithFormatting,
} from '../commands/clipboard'
import { isVisual } from '../extensions/visual/visual'
export const useContextMenuItems = () => {
const view = useCodeMirrorViewContext()
@@ -68,9 +70,16 @@ export const useContextMenuItems = () => {
[view, closeMenu]
)
const inVisualMode = isVisual(view)
const handleCut = wrapForContextMenu(() => cutSelection(view))
const handleCopy = wrapForContextMenu(() => copySelection(view))
const handlePaste = wrapForContextMenu(() => pasteWithoutFormatting(view))
const handlePaste = wrapForContextMenu(() =>
inVisualMode ? pasteWithFormatting(view) : pasteWithoutFormatting(view)
)
const handlePasteSpecial = wrapForContextMenu(() =>
inVisualMode ? pasteWithoutFormatting(view) : pasteWithFormatting(view)
)
const handleDelete = wrapForContextMenu(() => commands.deleteSelection(view))
const handleToggleTrackChanges = wrapForContextMenu(() => {
@@ -120,6 +129,15 @@ export const useContextMenuItems = () => {
show: canEdit,
shortcut: getShortcut('paste'),
},
{
label: inVisualMode
? t('paste_without_formatting')
: t('paste_with_formatting'),
handler: handlePasteSpecial,
disabled: false,
show: canEdit,
shortcut: inVisualMode ? getShortcut('paste-special') : undefined,
},
{
label: t('delete'),
handler: handleDelete,