Skip to content

Conversation

@RoboErikG
Copy link
Contributor

@RoboErikG RoboErikG commented May 28, 2025

The basics

The details

Resolves

Fixes RaspberryPiFoundation/blockly-keyboard-experimentation#546

This is a dependency for RaspberryPiFoundation/blockly-keyboard-experimentation#556

Proposed Changes

Updates the preconditions for cut/copy/paste to be more aware of flyouts and to use the following criteria:

  • Allow copying any blocks that could be moved, deleted, and edited once pasted (isOwnable)
  • Allow cutting any blocks that are currently movable and deletable (isable).
  • Allow pasting onto editable workspaces when there's copydata available.

Reason for Changes

You couldn't copy a block in the toolbox and then paste it into the workspace and when paste was enabled was inconsistent.

Test Coverage

Documentation

Additional Information

Copy link
Contributor

@maribethb maribethb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I think this makes sense but it would be nice if there were more test cases specifically covering the kinds of blocks that weren't copyable before this and now are.

lgtm pending question about editable though.

@maribethb
Copy link
Contributor

Sorry, just merged my change so you got the merge conflict, please be sure to add the ephemeralFocusTaken check as well. Thanks!

@RoboErikG RoboErikG requested a review from maribethb May 30, 2025 17:00
@RoboErikG RoboErikG merged commit fdffd65 into RaspberryPiFoundation:develop May 30, 2025
8 checks passed
Copy link
Collaborator

@cpcallen cpcallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a number of significant issues with this PR, including making a change that we had decided not to make as well as breaking copying of workspace comments.

I think it should be (mostly) reverted, and a different stab taken at making it possible to copy blocks from the workspace, by ascertaining what change had made them uncopybable and addressing that as narrowly as possible. Further increasing the range of things that can be copied should be left until we decide we want to implement the proposed changes described in #9098 (or a comparable alternative approach).

*
* @param focused The focused object.
*/
function isCuttable(focused: IFocusableNode): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I created isCopyable, above, was to ensure that cut and copy used common criteria for deciding if something can be cut/copied, with cut being allowed for anything that can be copied and is additionally deletable—AFAICT there is no circumstance where it should be possible to cut something but not copy it.

So isCuttable should call isCopyable (not just isICopyable), and return false if it does. Or… we could just have the cut preconditionFn just check isCopyable(focused) && focused.isDeletable(), as it previously did.

Comment on lines +131 to +137
return (
isICopyable(focused) &&
isIDeletable(focused) &&
focused.isOwnDeletable() &&
isDraggable(focused) &&
focused.isOwnMovable()
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes things that we decided we did not want to make copyable copyable.

This includes shadow blocks, but also blocks that have custom isDeletable and isMovable methods.

While I was working on #9084 we decided we did not want to do that in v12.

I'm not necessarily averse to making some things copyable (which were not previously copyable), but It is in my opinion a mistake to have done so without introducing an isCopyable method on ICopyable so that block definition authors can have more fine-grained control.

name: names.COPY,
preconditionFn(workspace, scope) {
const focused = scope.focusedNode;
if (!(focused instanceof BlockSvg)) return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents anything except blocks—e.g., workspace comments—from being copied.

isCopyable(focused) &&
!getFocusManager().ephemeralFocusTaken()
!!targetWorkspace &&
!targetWorkspace.isReadOnly() &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me that the main workspace being readonly should prevent blocks from being copied from the flyout.

(It also isn't clear to me that it should prevent blocks from being copied from the main workspace either—but that was the previous behaviour so leaving it as-is for the time being is fine.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: fix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can no longer use keyboard actions on blocks in the flyout

3 participants