Skip to content

Commit cf48115

Browse files
authored
Fix getMenuNode() for leaf nodes (#15845)
Fixes #15828 Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
1 parent c43fc0f commit cf48115

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/core/src/browser/menu/menu.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class TestMenuNodeFactory implements MenuNodeFactory {
5050
}
5151

5252
describe('menu-model-registry', () => {
53-
5453
describe('01 #register', () => {
5554
it('Should allow to register menu actions.', () => {
5655
const fileMenu = ['main', 'File'];
@@ -86,6 +85,9 @@ describe('menu-model-registry', () => {
8685
const openGroup = file.children[0] as Submenu;
8786
expect(openGroup.children.length).equals(2);
8887
expect(openGroup.label).undefined;
88+
89+
expect(service.getMenuNode([...fileOpenMenu, 'open'])).exist;
90+
expect(service.getMenuNode([...fileOpenMenu, 'Gurkensalat'])).undefined;
8991
});
9092

9193
it('Should not allow to register cyclic menus.', () => {

packages/core/src/common/menu/menu-model-registry.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,15 @@ export class MenuModelRegistry {
311311
}
312312
}
313313

314-
protected findInNode(root: CompoundMenuNode, menuPath: MenuPath, pathIndex: number): MenuNode | undefined {
314+
protected findInNode(root: MenuNode, menuPath: MenuPath, pathIndex: number): MenuNode | undefined {
315315
if (pathIndex === menuPath.length) {
316316
return root;
317317
}
318-
const child = root.children.find(c => c.id === menuPath[pathIndex]);
319-
if (CompoundMenuNode.is(child)) {
320-
return this.findInNode(child, menuPath, pathIndex + 1);
318+
if (CompoundMenuNode.is(root)) {
319+
const child = root.children.find(c => c.id === menuPath[pathIndex]);
320+
if (child) {
321+
return this.findInNode(child, menuPath, pathIndex + 1);
322+
}
321323
}
322324
return undefined;
323325
}

0 commit comments

Comments
 (0)