Skip to content

Commit 2d791e5

Browse files
authored
Merge pull request #427 from ember-tooling/improve-path-detection-inside-blocks
fix: improve path detection inside blocks
2 parents f81bbbf + 385e1c5 commit 2d791e5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/glimmer-utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,11 @@ function _findFocusPath(node: ASTv1.BaseNode, position: Position, seen = new Set
327327
if (containsPosition(range, position)) {
328328
path.push(node);
329329
} else {
330-
return [];
330+
// Special handling for Block nodes whose loc might not encompass all children
331+
if (node.type !== 'Block') {
332+
return [];
333+
}
334+
// For Block nodes, continue searching children even if loc doesn't contain position
331335
}
332336
}
333337

test/glimmer-utils-test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ describe('glimmer-utils', function () {
1919

2020
expect(astPath?.node).toMatchSnapshot();
2121
});
22+
it('support nested ifs', function () {
23+
const input = `
24+
{{#if @hasError}}
25+
<Error />
26+
{{else if this.hasFiles}}
27+
<File />
28+
{{else}}
29+
<Empty />
30+
{{/if}}
31+
`;
32+
const astPath = ASTPath.toPosition(preprocess(input), toPosition(Position.create(6, 4)));
33+
34+
expect(astPath?.node.type).toBe('ElementNode');
35+
});
2236
});
2337
describe('getLocalScope', function () {
2438
it('works as expected', function () {

0 commit comments

Comments
 (0)