Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 46 additions & 10 deletions core/block_dragger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,18 @@ export class BlockDragger implements IBlockDragger {

/** Whether the block would be deleted if dropped immediately. */
protected wouldDeleteBlock_ = false;

protected startXY_: Coordinate;

/** The parent block at the start of the drag. */
private startParentConn: RenderedConnection | null = null;

/**
* The child block at the start of the drag. Only gets set if
* `healStack` is true.
*/
private startChildConn: RenderedConnection | null = null;

/**
* @deprecated To be removed in v11. Updating icons is now handled by the
* block's `moveDuringDrag` method.
Expand Down Expand Up @@ -137,6 +147,13 @@ export class BlockDragger implements IBlockDragger {
blockAnimation.disconnectUiStop();

if (this.shouldDisconnect_(healStack)) {
this.startParentConn =
this.draggingBlock_.outputConnection?.targetConnection ??
this.draggingBlock_.previousConnection?.targetConnection;
if (healStack) {
this.startChildConn =
this.draggingBlock_.nextConnection?.targetConnection;
}
this.disconnectBlock_(healStack, currentDragDeltaXY);
}
this.draggingBlock_.setDragging(true);
Expand Down Expand Up @@ -424,17 +441,10 @@ export class BlockDragger implements IBlockDragger {
.getLayerManager()
?.moveOffDragLayer(this.draggingBlock_, layers.BLOCK);
this.draggingBlock_.setDragging(false);
if (delta) {
// !preventMove
if (preventMove) {
this.moveToOriginalPosition();
} else if (delta) {
this.updateBlockAfterMove_();
} else {
// Blocks dragged directly from a flyout may need to be bumped into
// bounds.
bumpObjects.bumpIntoBounds(
this.draggingBlock_.workspace,
this.workspace_.getMetricsManager().getScrollMetrics(true),
this.draggingBlock_,
);
}
}
// Must dispose after `updateBlockAfterMove_` is called to not break the
Expand All @@ -445,6 +455,32 @@ export class BlockDragger implements IBlockDragger {
eventUtils.setGroup(false);
}

/**
* Moves the dragged block back to its original position before the start of
* the drag. Reconnects any parent and child blocks.
*/
private moveToOriginalPosition() {
this.startChildConn?.connect(this.draggingBlock_.nextConnection);
if (this.startParentConn) {
switch (this.startParentConn.type) {
case ConnectionType.INPUT_VALUE:
this.startParentConn.connect(this.draggingBlock_.outputConnection);
break;
case ConnectionType.NEXT_STATEMENT:
this.startParentConn.connect(this.draggingBlock_.previousConnection);
}
} else {
this.draggingBlock_.moveTo(this.startXY_, ['drag']);
// Blocks dragged directly from a flyout may need to be bumped into
// bounds.
bumpObjects.bumpIntoBounds(
this.draggingBlock_.workspace,
this.workspace_.getMetricsManager().getScrollMetrics(true),
this.draggingBlock_,
);
}
}

/**
* Calculates the drag delta and new location values after a block is dragged.
*
Expand Down
1 change: 1 addition & 0 deletions core/connection_previewers/insertion_marker_previewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class InsertionMarkerPreviewer implements IConnectionPreviewer {
private createInsertionMarker(origBlock: BlockSvg) {
const result = this.workspace.newBlock(origBlock.type);
result.setInsertionMarker(true);
result.setInputsInline(origBlock.getInputsInline());
if (origBlock.saveExtraState) {
const state = origBlock.saveExtraState(true);
if (state && result.loadExtraState) {
Expand Down
4 changes: 2 additions & 2 deletions core/trashcan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,10 @@ const ANIMATION_LENGTH = 80;
const ANIMATION_FRAMES = 4;

/** The minimum (resting) opacity of the trashcan and lid. */
const OPACITY_MIN = 0.4;
const OPACITY_MIN = 1.0;

/** The maximum (hovered) opacity of the trashcan and lid. */
const OPACITY_MAX = 0.8;
const OPACITY_MAX = 1.0;

/**
* The maximum angle the trashcan lid can opens to. At the end of the open
Expand Down
Binary file modified media/sprites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions media/sprites.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blockly",
"version": "10.4.3",
"version": "10.5.0-beta.1",
"description": "Blockly is a library for building visual programming editors.",
"keywords": [
"blockly"
Expand Down