Skip to content

Commit

Permalink
Add support for navigating to element tagname
Browse files Browse the repository at this point in the history
  • Loading branch information
Jojoshua committed Dec 21, 2022
1 parent c87212b commit 6010236
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class CSSClassDefinitionLocator {
return this.getStandardFormatClassName();
}

if (this.isTargetHTMLElement()) {
return this.getHTMlElementName();
}

if (this.isDirectiveFormat() && this.initialNodeAt.name) {
return this.getDefinitionRangeWithinStyleSection(`.${this.initialNodeAt.name}`);
}
Expand All @@ -41,6 +45,18 @@ export class CSSClassDefinitionLocator {
return false;
}

/**
* HTML Element target:
* <main>
*/
private isTargetHTMLElement() {
if (this.initialNodeAt?.type == 'Element') {
return true;
}

return false;
}

/**
* Conditional Expression format:
* class="{current === 'baz' ? 'selected' : ''
Expand Down Expand Up @@ -104,8 +120,25 @@ export class CSSClassDefinitionLocator {
return this.getDefinitionRangeWithinStyleSection(`.${cssClassName}`);
}

private getHTMlElementName() {
const result = this.getDefinitionRangeWithinStyleSection(`${this.initialNodeAt.name}`);
if (result) {
//Shift start/end to get the highlight right
const originalStart = result.start.character;
result.start.character -= 1;
if (this.initialNodeAt.name) {
result.end.character = originalStart + this.initialNodeAt.name.length;
}

return result;
}
}

private getDefinitionRangeWithinStyleSection(targetClass: string) {
let indexOccurence = this.document.content.indexOf(targetClass, 0);
let indexOccurence = this.document.content.indexOf(
targetClass,
this.document.styleInfo?.start
);

while (indexOccurence >= 0) {
if (this.isOffsetWithinStyleSection(indexOccurence)) {
Expand All @@ -124,6 +157,8 @@ export class CSSClassDefinitionLocator {
}

return targetRange;
} else {
break;
}
}
}
Expand Down

0 comments on commit 6010236

Please sign in to comment.