Skip to content

Commit

Permalink
fix: upgrade keyboard navigation to use new clipboard API
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Aug 3, 2023
1 parent 34784e6 commit 21d4a54
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
14 changes: 10 additions & 4 deletions plugins/keyboard-navigation/src/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,16 +1111,22 @@ export class Navigation {
}

/**
* Pastes the coped block to the marked location.
* Pastes the copied block to the marked location.
* @param {Blockly.BlockCopyData} copyData The data
* to paste into the workspace.
* @param {Blockly.WorkspaceSvg} workspace The workspace to paste the data
* into.
* @returns {boolean} True if the paste was sucessful, false otherwise.
* @package
*/
paste() {
paste(copyData, workspace) {
let isHandled = false;
Blockly.Events.setGroup(true);
const block = Blockly.clipboard.paste();
const block = /** @type {Blockly.BlockSvg} */ (
Blockly.clipboard.paste(copyData, workspace)
);
if (block) {
isHandled = this.insertPastedBlock(block.workspace, block);
isHandled = this.insertPastedBlock(workspace, block);
}
Blockly.Events.setGroup(false);
return isHandled;
Expand Down
22 changes: 17 additions & 5 deletions plugins/keyboard-navigation/src/navigation_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import {Navigation} from './navigation';
* Class for registering shortcuts for keyboard navigation.
*/
export class NavigationController {
/** Data copied by the copy or cut keyboard shortcuts. */
copyData = null;

/** The workspace a copy or cut keyboard shortcut happened in. */
copyWorkspace = null;

/**
* Constructor used for registering shortcuts.
* This will register any default shortcuts for keyboard navigation.
Expand Down Expand Up @@ -715,9 +721,12 @@ export class NavigationController {
return false;
},
callback: (workspace) => {
const sourceBlock = workspace.getCursor().getCurNode().getSourceBlock();
const sourceBlock =/** @type {Blockly.BlockSvg} */ (
workspace.getCursor().getCurNode().getSourceBlock());
workspace.hideChaff();
Blockly.clipboard.copy(sourceBlock);
this.copyData = sourceBlock.toCopyData();
this.copyWorkspace = sourceBlock.workspace;
return !!this.copyData;
},
};

Expand Down Expand Up @@ -752,7 +761,8 @@ export class NavigationController {
!workspace.options.readOnly && !Blockly.Gesture.inProgress();
},
callback: () => {
return this.navigation.paste();
if (!this.copyData || !this.copyWorkspace) return false;
return this.navigation.paste(this.copyData, this.copyWorkspace);
},
};

Expand Down Expand Up @@ -797,8 +807,10 @@ export class NavigationController {
return false;
},
callback: (workspace) => {
const sourceBlock = workspace.getCursor().getCurNode().getSourceBlock();
Blockly.clipboard.copy(sourceBlock);
const sourceBlock =/** @type {Blockly.BlockSvg} */ (
workspace.getCursor().getCurNode().getSourceBlock());
this.copyData = sourceBlock.toCopyData();
this.copyWorkspace = sourceBlock.workspace;
this.navigation.moveCursorOnBlockDelete(workspace, sourceBlock);
sourceBlock.checkAndDelete();
return true;
Expand Down

0 comments on commit 21d4a54

Please sign in to comment.