Skip to content

Commit ad68c9c

Browse files
silverwindmrsdizzielafriks
authored
Backport emoji fixes to 1.12 (#12327)
* Fix emoji detection in certain cases (#12320) * Fix emoji detection certain cases Previous tests weren't complicated enough so there were some situations where emojis were't detected properly. Find the earliest occurance in addition to checking for the longest combination. Fixes #12312 * ok spell bot Co-authored-by: Lauris BH <[email protected]> * Reduce emoji size (#12317) * Reduce emoji size Rendering should now pretty much match GitHub with 1.25em. I verified that emojis don't increase the line height and removed unecessary size overrides because now all emojis should appear similar in relation to the font size. * fix reaction hover Co-authored-by: mrsdizzie <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent 8d1cd4d commit ad68c9c

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

modules/emoji/emoji.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,35 @@ func ReplaceAliases(s string) string {
130130
// FindEmojiSubmatchIndex returns index pair of longest emoji in a string
131131
func FindEmojiSubmatchIndex(s string) []int {
132132
loadMap()
133+
found := make(map[int]int)
134+
keys := make([]int, 0)
133135

134136
//see if there are any emoji in string before looking for position of specific ones
135137
//no performance difference when there is a match but 10x faster when there are not
136138
if s == ReplaceCodes(s) {
137139
return nil
138140
}
139141

142+
// get index of first emoji occurrence while also checking for longest combination
140143
for j := range GemojiData {
141144
i := strings.Index(s, GemojiData[j].Emoji)
142145
if i != -1 {
143-
return []int{i, i + len(GemojiData[j].Emoji)}
146+
if _, ok := found[i]; !ok {
147+
if len(keys) == 0 || i < keys[0] {
148+
found[i] = j
149+
keys = []int{i}
150+
}
151+
if i == 0 {
152+
break
153+
}
154+
}
144155
}
145156
}
157+
158+
if len(keys) > 0 {
159+
index := keys[0]
160+
return []int{index, index + len(GemojiData[found[index]].Emoji)}
161+
}
162+
146163
return nil
147164
}

modules/markup/html_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ func TestRender_emoji(t *testing.T) {
266266
test(
267267
"Some text with 😄😄 2 emoji next to each other",
268268
`<p>Some text with <span class="emoji" aria-label="grinning face with smiling eyes">😄</span><span class="emoji" aria-label="grinning face with smiling eyes">😄</span> 2 emoji next to each other</p>`)
269+
test(
270+
"😎🤪🔐🤑❓",
271+
`<p><span class="emoji" aria-label="smiling face with sunglasses">😎</span><span class="emoji" aria-label="zany face">🤪</span><span class="emoji" aria-label="locked with key">🔐</span><span class="emoji" aria-label="money-mouth face">🤑</span><span class="emoji" aria-label="question mark">❓</span></p>`)
272+
269273
// should match nothing
270274
test(
271275
"2001:0db8:85a3:0000:0000:8a2e:0370:7334",

web_src/less/_base.less

+4-19
Original file line numberDiff line numberDiff line change
@@ -1271,33 +1271,18 @@ i.icon.centerlock {
12711271

12721272
.emoji,
12731273
.reaction {
1274-
font-size: 1.5em;
1275-
line-height: 1.2;
1274+
font-size: 1.25em;
1275+
line-height: 1;
12761276
font-style: normal !important;
12771277
font-weight: normal !important;
1278-
vertical-align: middle;
1279-
}
1280-
1281-
#issue-title > .emoji {
1282-
font-size: 1em;
1283-
}
1284-
1285-
.commit-summary > .emoji {
1286-
font-size: 1em;
1287-
}
1288-
1289-
.label > .emoji {
1290-
font-size: 1em;
1278+
vertical-align: -.075em;
12911279
}
12921280

1293-
.dropdown .emoji {
1294-
font-size: 1em;
1295-
}
12961281
.emoji img,
12971282
.reaction img {
12981283
border-width: 0 !important;
12991284
margin: 0 !important;
13001285
width: 1em !important;
13011286
height: 1em !important;
1302-
vertical-align: middle !important;
1287+
vertical-align: -.15em;
13031288
}

web_src/less/_repository.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -2246,7 +2246,7 @@
22462246
.select-reaction {
22472247
display: flex;
22482248
align-items: center;
2249-
padding: .5rem;
2249+
padding: 0 .5rem;
22502250

22512251
&:not(.active) a {
22522252
display: none;

0 commit comments

Comments
 (0)