Skip to content

Commit 423cdd4

Browse files
Improve control char rendering and escape button styling (#37094)
Follow-up to #37078. - Use Unicode Control Pictures](U+2400-U+2421) to render C0 control characters - Make it work in diff view too - Replace escape warning emoji with SVG - Align escape warning button with code lines --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent e47c613 commit 423cdd4

37 files changed

+1539
-1772
lines changed

modules/charset/ambiguous.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// This file is generated by modules/charset/ambiguous/generate.go DO NOT EDIT
21
// Copyright 2022 The Gitea Authors. All rights reserved.
32
// SPDX-License-Identifier: MIT
43

@@ -14,11 +13,12 @@ import (
1413

1514
// AmbiguousTablesForLocale provides the table of ambiguous characters for this locale.
1615
func AmbiguousTablesForLocale(locale translation.Locale) []*AmbiguousTable {
16+
ambiguousTableMap := globalVars().ambiguousTableMap
1717
key := locale.Language()
1818
var table *AmbiguousTable
1919
var ok bool
2020
for len(key) > 0 {
21-
if table, ok = AmbiguousCharacters[key]; ok {
21+
if table, ok = ambiguousTableMap[key]; ok {
2222
break
2323
}
2424
idx := strings.LastIndexAny(key, "-_")
@@ -29,18 +29,18 @@ func AmbiguousTablesForLocale(locale translation.Locale) []*AmbiguousTable {
2929
}
3030
}
3131
if table == nil && (locale.Language() == "zh-CN" || locale.Language() == "zh_CN") {
32-
table = AmbiguousCharacters["zh-hans"]
32+
table = ambiguousTableMap["zh-hans"]
3333
}
3434
if table == nil && strings.HasPrefix(locale.Language(), "zh") {
35-
table = AmbiguousCharacters["zh-hant"]
35+
table = ambiguousTableMap["zh-hant"]
3636
}
3737
if table == nil {
38-
table = AmbiguousCharacters["_default"]
38+
table = ambiguousTableMap["_default"]
3939
}
4040

4141
return []*AmbiguousTable{
4242
table,
43-
AmbiguousCharacters["_common"],
43+
ambiguousTableMap["_common"],
4444
}
4545
}
4646

@@ -52,7 +52,7 @@ func isAmbiguous(r rune, confusableTo *rune, tables ...*AmbiguousTable) bool {
5252
i := sort.Search(len(table.Confusable), func(i int) bool {
5353
return table.Confusable[i] >= r
5454
})
55-
(*confusableTo) = table.With[i]
55+
*confusableTo = table.With[i]
5656
return true
5757
}
5858
return false

modules/charset/ambiguous/generate.go

Lines changed: 0 additions & 188 deletions
This file was deleted.

modules/charset/ambiguous_gen.go

Lines changed: 803 additions & 787 deletions
Large diffs are not rendered by default.

modules/charset/ambiguous_gen_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
"testing"
99
"unicode"
1010

11+
"code.gitea.io/gitea/modules/translation"
12+
1113
"github.com/stretchr/testify/assert"
1214
)
1315

1416
func TestAmbiguousCharacters(t *testing.T) {
15-
for locale, ambiguous := range AmbiguousCharacters {
17+
for locale, ambiguous := range globalVars().ambiguousTableMap {
1618
assert.Equal(t, locale, ambiguous.Locale)
1719
assert.Len(t, ambiguous.With, len(ambiguous.Confusable))
1820
assert.True(t, sort.SliceIsSorted(ambiguous.Confusable, func(i, j int) bool {
@@ -28,4 +30,8 @@ func TestAmbiguousCharacters(t *testing.T) {
2830
assert.True(t, found, "%c is not in %d", confusable, i)
2931
}
3032
}
33+
34+
var confusableTo rune
35+
ret := isAmbiguous('𝐾', &confusableTo, AmbiguousTablesForLocale(&translation.MockLocale{})...)
36+
assert.True(t, ret)
3137
}

modules/charset/breakwriter.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

modules/charset/breakwriter_test.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)