Skip to content

Commit 56ed38e

Browse files
committed
fix(demos/custom-ui): show Bold/Italic in context menu without a selection
1 parent 3ae665d commit 56ed38e

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

demos/custom-ui/src/components/ContextMenuRegistrations.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ export function ContextMenuRegistrations({ decided, onComposeComment }: Props) {
9292
// browser's native menu is suppressed there. Without these
9393
// entries the menu would be empty whenever the click isn't over a
9494
// tracked change or comment.
95+
// Bold / Italic stay available on a collapsed selection: toggling
96+
// a mark with no range applies it to the cursor's stored marks
97+
// so the next typed character picks up the formatting. Same UX
98+
// Word and Google Docs offer on right-click. Gate on
99+
// `selection.target` so we don't surface them when the editor
100+
// isn't focused at all.
95101
const bold = ui.commands.register({
96102
id: 'demo.bold',
97103
execute: () => {
@@ -102,7 +108,7 @@ export function ContextMenuRegistrations({ decided, onComposeComment }: Props) {
102108
label: 'Bold',
103109
group: 'format',
104110
order: 0,
105-
when: ({ selection }) => !selection.empty,
111+
when: ({ selection }) => selection.target !== null,
106112
},
107113
});
108114
const italic = ui.commands.register({
@@ -115,7 +121,7 @@ export function ContextMenuRegistrations({ decided, onComposeComment }: Props) {
115121
label: 'Italic',
116122
group: 'format',
117123
order: 1,
118-
when: ({ selection }) => !selection.empty,
124+
when: ({ selection }) => selection.target !== null,
119125
},
120126
});
121127
const copy = ui.commands.register({

0 commit comments

Comments
 (0)