From 91632a4861e223cdc01c884d05cd6c273d2bd3a2 Mon Sep 17 00:00:00 2001 From: Ben Henning Date: Mon, 19 May 2025 10:16:38 -0700 Subject: [PATCH] fix: Limit LineCursor<-focus syncing. (#9062) ## The basics - [x] I [validated my changes](https://developers.google.com/blockly/guides/contribute/core#making_and_verifying_a_change) ## The details ### Resolves Fixes https://github.com/google/blockly-keyboard-experimentation/issues/526 ### Proposed Changes This limits synchronizing in `LineCursor` from `FocusManager` to just nodes that have a corresponding block. ### Reason for Changes Limiting the synchronizing in this way ensures that navigation can't enter a bad state. The reason for why this is needed is explained in https://github.com/google/blockly-keyboard-experimentation/issues/526#issuecomment-2885117998. Longer term it would maybe be ideal to do one or both of the following: - Figure out ways of making navigation a bit more robust (perhaps on the keyboard navigation side) such that if cursor _is_ in a bad state there's some way to recover (rather than ending up permanently broken). - Remove `Marker`'s internal state in favor of always relying on `FocusManager`'s state to cover the cases where there can be automatic focus shifting. ### Test Coverage This was manually tested with the keyboard navigation plugin and verified to ensure that both https://github.com/google/blockly-keyboard-experimentation/issues/526 and https://github.com/google/blockly-keyboard-experimentation/issues/499 are (still) working as expected. Some basic testing was done with the core simple playground with the developer console open to ensure there weren't any expected failures. Automated testing cases would be better addressed as part of resolving #8915. ### Documentation No new documentation is needed here. ### Additional Information This behavior is expected to only affect the keyboard navigation plugin. --- core/keyboard_nav/line_cursor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/keyboard_nav/line_cursor.ts b/core/keyboard_nav/line_cursor.ts index 8cc51f903..85c0f414a 100644 --- a/core/keyboard_nav/line_cursor.ts +++ b/core/keyboard_nav/line_cursor.ts @@ -378,7 +378,7 @@ export class LineCursor extends Marker { // Ensure the current node matches what's currently focused. const focused = getFocusManager().getFocusedNode(); const block = this.getSourceBlockFromNode(focused); - if (!block || block.workspace === this.workspace) { + if (block && block.workspace === this.workspace) { // If the current focused node corresponds to a block then ensure that it // belongs to the correct workspace for this cursor. this.setCurNode(focused);