mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
chore: upgrade keyboard shortcuts and context menus to use non-deprecated APIs (#7352)
* chore: remove references to clipboard.copy in shortcuts * chore: remove references to clipboard.copy in context menus * chore: fix tests * chore: format * fix: PR comments
This commit is contained in:
@@ -11,7 +11,7 @@ import {BlockSvg} from './block_svg.js';
|
||||
import * as clipboard from './clipboard.js';
|
||||
import * as common from './common.js';
|
||||
import {Gesture} from './gesture.js';
|
||||
import {isCopyable} from './interfaces/i_copyable.js';
|
||||
import {ICopyData, isCopyable} from './interfaces/i_copyable.js';
|
||||
import {KeyboardShortcut, ShortcutRegistry} from './shortcut_registry.js';
|
||||
import {KeyCodes} from './utils/keycodes.js';
|
||||
import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
@@ -81,6 +81,9 @@ export function registerDelete() {
|
||||
ShortcutRegistry.registry.register(deleteShortcut);
|
||||
}
|
||||
|
||||
let copyData: ICopyData | null = null;
|
||||
let copyWorkspace: WorkspaceSvg | null = null;
|
||||
|
||||
/**
|
||||
* Keyboard shortcut to copy a block on ctrl+c, cmd+c, or alt+c.
|
||||
*/
|
||||
@@ -104,20 +107,20 @@ export function registerCopy() {
|
||||
!Gesture.inProgress() &&
|
||||
selected != null &&
|
||||
selected.isDeletable() &&
|
||||
selected.isMovable()
|
||||
selected.isMovable() &&
|
||||
isCopyable(selected)
|
||||
);
|
||||
},
|
||||
callback(workspace, e) {
|
||||
// Prevent the default copy behavior, which may beep or otherwise indicate
|
||||
// an error due to the lack of a selection.
|
||||
e.preventDefault();
|
||||
// AnyDuringMigration because: Property 'hideChaff' does not exist on
|
||||
// type 'Workspace'.
|
||||
(workspace as AnyDuringMigration).hideChaff();
|
||||
workspace.hideChaff();
|
||||
const selected = common.getSelected();
|
||||
if (!selected || !isCopyable(selected)) return false;
|
||||
clipboard.copy(selected);
|
||||
return true;
|
||||
copyData = selected.toCopyData();
|
||||
copyWorkspace = workspace;
|
||||
return !!copyData;
|
||||
},
|
||||
keyCodes: [ctrlC, altC, metaC],
|
||||
};
|
||||
@@ -152,10 +155,11 @@ export function registerCut() {
|
||||
!selected.workspace!.isFlyout
|
||||
);
|
||||
},
|
||||
callback() {
|
||||
callback(workspace) {
|
||||
const selected = common.getSelected();
|
||||
if (!selected || !isCopyable(selected)) return false;
|
||||
clipboard.copy(selected);
|
||||
copyData = selected.toCopyData();
|
||||
copyWorkspace = workspace;
|
||||
(selected as BlockSvg).checkAndDelete();
|
||||
return true;
|
||||
},
|
||||
@@ -185,7 +189,8 @@ export function registerPaste() {
|
||||
return !workspace.options.readOnly && !Gesture.inProgress();
|
||||
},
|
||||
callback() {
|
||||
return !!clipboard.paste();
|
||||
if (!copyData || !copyWorkspace) return false;
|
||||
return !!clipboard.paste(copyData, copyWorkspace);
|
||||
},
|
||||
keyCodes: [ctrlV, altV, metaV],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user