Skip to content

Commit

Permalink
fix: Fix theme config array merge bug #713
Browse files Browse the repository at this point in the history
  • Loading branch information
Binaryify committed Apr 21, 2022
1 parent 60d6ea3 commit 88e6160
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# CHANGELOG
## 3.13.23 | 2022.04.21
- Fix theme config array merge bug [#713](https://github.com/Binaryify/OneDark-Pro/issues/713)

## 3.13.22 | 2022.04.21
- Change `invalid.deprecated.entity.other.attribute-name.html` highlight color

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "material-theme",
"displayName": "One Dark Pro",
"description": "Atom‘s iconic One Dark theme for Visual Studio Code",
"version": "3.13.22",
"version": "3.13.23",
"publisher": "zhuangtongfa",
"license": "MIT",
"bugs": {
Expand Down
29 changes: 17 additions & 12 deletions src/themes/Theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Colors, ThemeConfiguration, TokenColor } from '../interface'
import data from './themeData'

import { uniqBy } from 'lodash'
async function createEditorTokens(config: ThemeConfiguration) {
return config.editorTheme in data.editorThemes
? (await data.editorThemes[config.editorTheme]()).default
Expand All @@ -12,22 +12,27 @@ function configFactory(configuration) {
JSON.stringify(data.tokenColors.default)
)

function uniqBy(
baseArray: TokenColor[],
overrides: TokenColor[]
): TokenColor[] {
const obj = {}
baseArray
.concat(overrides)
.forEach((item) => (obj[item.name + item.scope] = item))
return Object.values(obj)
function mergeTheme(baseArray, overrides) {
let mergeArr = [...baseArray, ...overrides]
let newArr = uniqBy(mergeArr, 'scope')
overrides.forEach((item) => {
newArr.forEach((cell) => {
if (cell.scope === item.scope) {
cell.settings = {
...cell.settings,
...item.settings,
}
}
})
})
return JSON.parse(JSON.stringify(newArr))
}

if (configuration.bold) {
result = uniqBy(result, data.tokenColors.bold)
result = mergeTheme(result, data.tokenColors.bold)
}
if (configuration.italic) {
result = uniqBy(result, data.tokenColors.italic)
result = mergeTheme(result, data.tokenColors.italic)
}

// Fill in color placeholders with concrete color values
Expand Down
24 changes: 16 additions & 8 deletions themes/OneDark-Pro-flat.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,14 @@
"variable.function"
],
"settings": {
"fontStyle": "bold"
"foreground": "#61afef"
}
},
{
"name": "Classes",
"scope": "entity.name.type.namespace",
"settings": {
"foreground": "#e5c07b",
"fontStyle": "bold"
}
},
Expand Down Expand Up @@ -838,6 +839,7 @@
"name": "Headings",
"scope": "markup.heading",
"settings": {
"foreground": "#e06c75",
"fontStyle": "bold"
}
},
Expand All @@ -859,6 +861,7 @@
"name": "Bold",
"scope": "markup.bold,todo.bold",
"settings": {
"foreground": "#d19a66",
"fontStyle": "bold"
}
},
Expand Down Expand Up @@ -2016,13 +2019,6 @@
"foreground": "#e06c75"
}
},
{
"name": "Markup: Heading",
"scope": "markup.heading",
"settings": {
"fontStyle": "bold"
}
},
{
"name": "Markup: Strong",
"scope": "markup.bold",
Expand All @@ -2044,6 +2040,18 @@
"fontStyle": "bold"
}
},
{
"name": "Functions",
"scope": [
"entity.name.function",
"meta.require",
"support.function.any-method",
"variable.function"
],
"settings": {
"fontStyle": "bold"
}
},
{
"name": "markup.bold.markdown",
"scope": "markup.bold.markdown",
Expand Down
1 change: 1 addition & 0 deletions themes/OneDark-Pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,7 @@
"name": "Comments",
"scope": "comment, punctuation.definition.comment",
"settings": {
"foreground": "#7f848e",
"fontStyle": "italic"
}
},
Expand Down

0 comments on commit 88e6160

Please sign in to comment.