Skip to content

Commit c644025

Browse files
committed
Adds support for Heroicons v2
1 parent 1af58a5 commit c644025

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ vsc-extension-quickstart.md
88
package-lock.json
99
.vscode
1010
.vscodeignore
11-
CHANGELOG.md
11+
CHANGELOG.md
12+
.DS_store

package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "heroicons-preview",
33
"displayName": "VSCode Heroicons Preview",
44
"description": "Inline SVG previews for Heroicons",
5-
"version": "0.0.6",
5+
"version": "1.0.0",
66
"publisher": "BButner",
77
"homepage": "https://github.com/BButner/VSCode-Heroicons-Preview",
88
"repository": {
@@ -41,13 +41,22 @@
4141
},
4242
"hip.fileDecorationExtensions": {
4343
"type": "array",
44-
"default": [".tsx", ".jsx", ".vue", ".html", ".svelte"],
44+
"default": [
45+
".tsx",
46+
".jsx",
47+
".vue",
48+
".html",
49+
".svelte"
50+
],
4551
"description": "Array of file extensions to search for Icons to decorate. Example: [\".tsx\", \".jsx\"]"
4652
},
4753
"hip.iconStyleFallback": {
4854
"type": "string",
4955
"default": "outline",
50-
"enum": ["solid", "outline"],
56+
"enum": [
57+
"solid",
58+
"outline"
59+
],
5160
"description": "If HIP cannot detect a style from an import, it will fall back to this style."
5261
}
5362
}
@@ -78,6 +87,6 @@
7887
"typescript": "^4.1.3",
7988
"vscode-test": "^1.5.0",
8089
"webpack": "^5.19.0",
81-
"webpack-cli": "^4.4.0"
90+
"webpack-cli": "^4.10.0"
8291
}
8392
}

src/lib/decoration.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ export const registerDocument = (documentName: string): void => {
2525
})
2626
}
2727

28-
export const getDocumentDecorationTypeByName = (documentName: string): vscode.TextEditorDecorationType => {
29-
return documentDecorationTypes.filter(type => type.documentName === documentName)[0].decorationType
28+
export const getDocumentDecorationTypeByName = (documentName: string): vscode.TextEditorDecorationType | null => {
29+
const decoration = documentDecorationTypes.find(type => type.documentName === documentName)
30+
return decoration ? decoration.decorationType : null
3031
}
3132

3233
interface DocumentDecorationType {
@@ -42,21 +43,22 @@ export class Decorator {
4243
}
4344

4445
clearEditorDecorations = (documentName: string): void => {
45-
const visibleEditors: vscode.TextEditor[] = vscode.window.visibleTextEditors
46+
const visibleEditors: readonly vscode.TextEditor[] = vscode.window.visibleTextEditors
4647
const potentialEditor: vscode.TextEditor[] = visibleEditors.filter(editor => editor.document.fileName === documentName)
4748

4849
if (visibleEditors.length > 0 && potentialEditor.length > 0) {
4950
const editor: vscode.TextEditor = potentialEditor[0]
5051

51-
editor.setDecorations(
52-
getDocumentDecorationTypeByName(editor.document.fileName),
53-
[]
54-
)
52+
const decoration = getDocumentDecorationTypeByName(editor.document.fileName)
53+
54+
if (decoration) {
55+
editor.setDecorations(decoration, [])
56+
}
5557
}
5658
}
5759

5860
decorateEditor = (documentName: string): void => {
59-
const visibleEditors: vscode.TextEditor[] = vscode.window.visibleTextEditors
61+
const visibleEditors: readonly vscode.TextEditor[] = vscode.window.visibleTextEditors
6062
const potentialEditor: vscode.TextEditor[] = visibleEditors.filter(editor => editor.document.fileName === documentName)
6163

6264
let decorationsArray: any[] = []
@@ -111,10 +113,13 @@ export class Decorator {
111113
}
112114
}
113115

114-
editor.setDecorations(
115-
getDocumentDecorationTypeByName(editor.document.fileName),
116-
decorationsArray
117-
)
116+
const decoration = getDocumentDecorationTypeByName(editor.document.fileName)
117+
118+
console.log('decoration', editor.document.fileName, decoration)
119+
120+
if (decoration) {
121+
editor.setDecorations(decoration, decorationsArray)
122+
}
118123
}
119124
}
120125
}

src/lib/events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class Events {
4141
}
4242

4343
private configChanged = () => {
44-
const editors: vscode.TextEditor[] = vscode.window.visibleTextEditors
44+
const editors = vscode.window.visibleTextEditors
4545

4646
editors.forEach(editor => {
4747
if (editor.document && editor.document.getText()) {

src/lib/icon.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export class IconHandler {
7474
}
7575

7676
private getIconPath = (iconStyle: string): string => {
77-
return join(this.heroIconsLocation + '/' + this.mode + '/' + iconStyle)
77+
const isV2 = readdirSync(join(this.heroIconsLocation, this.mode!)).filter((dir: string) => dir === '24').length > 0
78+
79+
return isV2 ? join(this.heroIconsLocation, this.mode!, '24', iconStyle) : join(this.heroIconsLocation, this.mode!, iconStyle)
7880
}
7981

8082
private isIconCached = (iconName: string, iconStyle: IconStyleType): boolean => {

0 commit comments

Comments
 (0)