feat: Beep when navigating across nesting levels (#9521)

This commit is contained in:
Aaron Dodson
2025-12-09 11:44:36 -08:00
committed by GitHub
parent d57e66ed8f
commit 40e9ac8e00
2 changed files with 27 additions and 0 deletions

View File

@@ -1990,6 +1990,22 @@ export class BlockSvg
return true;
}
/**
* Returns how deeply nested this block is in parent C-shaped blocks.
*
* @internal
* @returns The nesting level of this block, starting at 0 for root blocks.
*/
getNestingLevel(): number {
// Don't consider value blocks to be nested.
if (this.outputConnection) {
return this.getParent()?.getNestingLevel() ?? 0;
}
const surroundParent = this.getSurroundParent();
return surroundParent ? surroundParent.getNestingLevel() + 1 : 0;
}
/**
* Announces the current dynamic state of the specified block, if any.
*

View File

@@ -542,6 +542,17 @@ export class LineCursor extends Marker {
* @param newNode The new location of the cursor.
*/
setCurNode(newNode: IFocusableNode) {
const oldBlock = this.getSourceBlock();
const newBlock = this.getSourceBlockFromNode(newNode);
if (
oldBlock &&
newBlock &&
oldBlock.getNestingLevel() !== newBlock.getNestingLevel()
) {
newBlock.workspace
.getAudioManager()
.beep(400 + newBlock.getNestingLevel() * 40);
}
getFocusManager().focusNode(newNode);
}