Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
16 changes: 16 additions & 0 deletions src/line_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,22 @@ export class LineCursor extends Marker {
}
}

override hide(): void {
super.hide();

// If there's a block currently selected, remove the selection since the
// cursor should now be hidden.
const curNode = this.getCurNode();
if (curNode.getType() === ASTNode.types.BLOCK) {
const block = curNode.getLocation() as Blockly.BlockSvg;
if (!block.isShadow()) {
Blockly.common.setSelected(null);
} else {
block.removeSelect();
}
}
}

/**
* Redraw the current marker.
*
Expand Down
9 changes: 9 additions & 0 deletions src/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,15 @@ export class Navigation {
}

if (this.markedNode) {
// Note that this hide happens twice, one before setCurNode() and once in
// removeMark. The latter is actually a logical no-op because setCurNode()
// will trigger a selection update of the currently marked node (if it's a
// block) and that, in turn, clones the underlying block's
// pathObject.svgPath. Since svgPath is updated to remove any passive
// focus indicator after selection clones it, the effect of removing the
// indicator doesn't do anything (hence it needs to be done *before*
// selection is added in order to immediately take effect).
this.passiveFocusIndicator.hide();
cursor.setCurNode(this.markedNode);
this.removeMark(workspace);
return;
Expand Down
5 changes: 5 additions & 0 deletions src/navigation_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ export class NavigationController {
this.hasNavigationFocus = isFocused;
if (isFocused) {
this.navigation.focusWorkspace(workspace, true);
} else {
// Hide cursor to indicate lost focus. Also, mark the current node so that
// it can be properly restored upon returning to the workspace.
this.navigation.markAtCursor(workspace);
workspace.getCursor()?.hide();
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/passive_focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ export class PassiveFocus {
*/
showAtBlock(node: ASTNode) {
const block = node.getLocation() as BlockSvg;
// Note that this changes rendering but does not change Blockly's
// internal selected state.
block.addSelect();
utils.dom.addClass(block.pathObject.svgPath, 'passiveBlockFocus');
}

/**
Expand All @@ -106,9 +104,7 @@ export class PassiveFocus {
*/
hideAtBlock(node: ASTNode) {
const block = node.getLocation() as BlockSvg;
// Note that this changes rendering but does not change Blockly's
// internal selected state.
block.removeSelect();
utils.dom.removeClass(block.pathObject.svgPath, 'passiveBlockFocus');
}

/**
Expand All @@ -122,8 +118,6 @@ export class PassiveFocus {
'width': 100,
'height': 5,
'class': 'passiveNextIndicator',
'stroke': '#4286f4',
'fill': '#4286f4',
});
return indicator;
}
Expand Down
11 changes: 11 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@
#announcer {
height: 25%;
}

.passiveBlockFocus.blocklyPath {
stroke-dasharray: 5 3;
stroke-width: 3;
stroke: #ff69b4;
}

.passiveNextIndicator {
stroke: #ff69b4;
fill: #ff69b4;
}
</style>
</head>

Expand Down