Skip to content
Merged
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
11 changes: 7 additions & 4 deletions core/utils/focusable_tree_traverser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export class FocusableTreeTraverser {
* @returns The IFocusableNode currently with focus, or null if none.
*/
static findFocusedNode(tree: IFocusableTree): IFocusableNode | null {
const root = tree.getRootFocusableNode().getFocusableElement();
const rootNode = tree.getRootFocusableNode();
if (!rootNode.canBeFocused()) return null;
const root = rootNode.getFocusableElement();
if (
dom.hasClass(root, FocusableTreeTraverser.ACTIVE_CLASS_NAME) ||
dom.hasClass(root, FocusableTreeTraverser.PASSIVE_CSS_CLASS_NAME)
) {
// The root has focus.
return tree.getRootFocusableNode();
return rootNode;
}

const activeEl = root.querySelector(this.ACTIVE_FOCUS_NODE_CSS_SELECTOR);
Expand Down Expand Up @@ -99,8 +101,9 @@ export class FocusableTreeTraverser {
}

// Second, check against the tree's root.
if (element === tree.getRootFocusableNode().getFocusableElement()) {
return tree.getRootFocusableNode();
const rootNode = tree.getRootFocusableNode();
if (rootNode.canBeFocused() && element === rootNode.getFocusableElement()) {
return rootNode;
}

// Third, check if the element has a node.
Expand Down
17 changes: 14 additions & 3 deletions core/workspace_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2746,7 +2746,9 @@ export class WorkspaceSvg
const block = this.getBlockById(blockId);
if (block) {
for (const field of block.getFields()) {
if (field.getFocusableElement().id === id) return field;
if (field.canBeFocused() && field.getFocusableElement().id === id) {
return field;
}
}
}
return null;
Expand All @@ -2769,6 +2771,7 @@ export class WorkspaceSvg
for (const comment of this.getTopComments()) {
if (
comment instanceof RenderedWorkspaceComment &&
comment.canBeFocused() &&
comment.getFocusableElement().id === id
) {
return comment;
Expand All @@ -2780,10 +2783,18 @@ export class WorkspaceSvg
.map((block) => block.getIcons())
.flat();
for (const icon of icons) {
if (icon.getFocusableElement().id === id) return icon;
if (icon.canBeFocused() && icon.getFocusableElement().id === id) {
return icon;
}
if (hasBubble(icon)) {
const bubble = icon.getBubble();
if (bubble && bubble.getFocusableElement().id === id) return bubble;
if (
bubble &&
bubble.canBeFocused() &&
bubble.getFocusableElement().id === id
) {
return bubble;
}
}
}

Expand Down