refboard: await clipboard writes before copy success

This commit is contained in:
Hiren Kangad
2026-03-13 15:33:37 +05:30
parent 3dd110f491
commit 80ec4808e8
2 changed files with 14 additions and 10 deletions
+7 -3
View File
@@ -45,9 +45,13 @@ export function buildContextMenuItems(ctx: MenuContext): MenuItem[] {
return [ return [
// -- Clipboard -- // -- Clipboard --
{ label: 'Copy', shortcut: 'Ctrl+C', onClick: () => { { label: 'Copy', shortcut: 'Ctrl+C', onClick: async () => {
if (hasSel) { ctx.clipboardRef.current = [...selected]; ctx.writeCanvasToClipboard(selected); } if (hasSel) {
else ctx.writeCanvasToClipboard(); ctx.clipboardRef.current = [...selected];
await ctx.writeCanvasToClipboard(selected);
} else {
await ctx.writeCanvasToClipboard();
}
} }, } },
{ label: 'Cut', shortcut: 'Ctrl+X', onClick: () => { { label: 'Cut', shortcut: 'Ctrl+X', onClick: () => {
if (!scene || !hasSel || !selection) return; if (!scene || !hasSel || !selection) return;
+7 -7
View File
@@ -467,16 +467,16 @@ export const shortcuts: ShortcutDef[] = [
{ {
id: 'copy', keys: { key: 'c', ctrl: true }, id: 'copy', keys: { key: 'c', ctrl: true },
category: 'editing', description: 'Copy', category: 'editing', description: 'Copy',
handler: (ctx) => { handler: async (ctx) => {
const selected = ctx.selection.getSelectedItems(); const selected = ctx.selection.getSelectedItems();
if (selected.length > 0) { if (selected.length > 0) {
// Include group children in clipboard for proper paste // Include group children in clipboard for proper paste
ctx.clipboardRef.current = _collectGroupChildren(selected, ctx.scene); ctx.clipboardRef.current = _collectGroupChildren(selected, ctx.scene);
markInternalCopy(); markInternalCopy();
ctx.writeCanvasToClipboard(selected); await ctx.writeCanvasToClipboard(selected);
ctx.showToast('Copied'); ctx.showToast('Copied');
} else { } else {
ctx.writeCanvasToClipboard(); await ctx.writeCanvasToClipboard();
ctx.showToast('Copied canvas'); ctx.showToast('Copied canvas');
} }
}, },
@@ -484,9 +484,9 @@ export const shortcuts: ShortcutDef[] = [
{ {
id: 'copy-as-image', keys: { key: 'c', ctrl: true, shift: true }, id: 'copy-as-image', keys: { key: 'c', ctrl: true, shift: true },
category: 'editing', description: 'Copy as image to clipboard', category: 'editing', description: 'Copy as image to clipboard',
handler: (ctx) => { handler: async (ctx) => {
const selected = ctx.selection.getSelectedItems(); const selected = ctx.selection.getSelectedItems();
ctx.writeCanvasToClipboard(selected.length > 0 ? selected : undefined); await ctx.writeCanvasToClipboard(selected.length > 0 ? selected : undefined);
}, },
}, },
{ {
@@ -512,12 +512,12 @@ export const shortcuts: ShortcutDef[] = [
{ {
id: 'cut', keys: { key: 'x', ctrl: true }, id: 'cut', keys: { key: 'x', ctrl: true },
category: 'editing', description: 'Cut', category: 'editing', description: 'Cut',
handler: (ctx) => { handler: async (ctx) => {
const selected = ctx.selection.getSelectedItems(); const selected = ctx.selection.getSelectedItems();
if (selected.length === 0) return; if (selected.length === 0) return;
ctx.clipboardRef.current = _collectGroupChildren(selected, ctx.scene); ctx.clipboardRef.current = _collectGroupChildren(selected, ctx.scene);
markInternalCopy(); markInternalCopy();
ctx.writeCanvasToClipboard(selected); await ctx.writeCanvasToClipboard(selected);
for (const item of selected) { for (const item of selected) {
ctx.scene.removeItem(item.id, true); ctx.scene.removeItem(item.id, true);
} }