Skip to content

Commit 0dfa94e

Browse files
authored
Add old svg class name to git entry icon (#33884)
Fix #33837 (comment)
1 parent cb6b33c commit 0dfa94e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

modules/fileicon/material.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (m *MaterialIconProvider) loadData() {
6262
log.Debug("Loaded material icon rules and SVG images")
6363
}
6464

65-
func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name, svg string) template.HTML {
65+
func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name, svg, extraClass string) template.HTML {
6666
data := ctx.GetData()
6767
renderedSVGs, _ := data["_RenderedSVGs"].(map[string]bool)
6868
if renderedSVGs == nil {
@@ -75,7 +75,7 @@ func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name
7575
panic("Invalid SVG icon")
7676
}
7777
svgID := "svg-mfi-" + name
78-
svgCommonAttrs := `class="svg fileicon" width="16" height="16" aria-hidden="true"`
78+
svgCommonAttrs := `class="svg git-entry-icon ` + extraClass + `" width="16" height="16" aria-hidden="true"`
7979
posOuterBefore := strings.IndexByte(svg, '>')
8080
if renderedSVGs[svgID] && posOuterBefore != -1 {
8181
return template.HTML(`<svg ` + svgCommonAttrs + `><use xlink:href="#` + svgID + `"></use></svg>`)
@@ -92,18 +92,28 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
9292

9393
if entry.IsLink() {
9494
if te, err := entry.FollowLink(); err == nil && te.IsDir() {
95-
return svg.RenderHTML("material-folder-symlink")
95+
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
96+
return svg.RenderHTML("material-folder-symlink", 16, "octicon-file-directory-symlink")
9697
}
9798
return svg.RenderHTML("octicon-file-symlink-file") // TODO: find some better icons for them
9899
}
99100

100101
name := m.findIconNameByGit(entry)
101102
if name == "folder" {
102103
// the material icon pack's "folder" icon doesn't look good, so use our built-in one
103-
return svg.RenderHTML("material-folder-generic")
104+
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
105+
return svg.RenderHTML("material-folder-generic", 16, "octicon-file-directory-fill")
104106
}
105107
if iconSVG, ok := m.svgs[name]; ok && iconSVG != "" {
106-
return m.renderFileIconSVG(ctx, name, iconSVG)
108+
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
109+
extraClass := "octicon-file"
110+
switch {
111+
case entry.IsDir():
112+
extraClass = "octicon-file-directory-fill"
113+
case entry.IsSubModule():
114+
extraClass = "octicon-file-submodule"
115+
}
116+
return m.renderFileIconSVG(ctx, name, iconSVG, extraClass)
107117
}
108118
return svg.RenderHTML("octicon-file")
109119
}

web_src/css/modules/svg.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
fill: currentcolor;
55
}
66

7-
.svg.fileicon {
7+
.svg.git-entry-icon {
88
fill: transparent; /* some material icons have dark background fill, so need to reset */
99
}
1010

0 commit comments

Comments
 (0)