Skip to content

Commit b53d827

Browse files
committed
feat!: change config key
1 parent fab7e17 commit b53d827

File tree

7 files changed

+57
-47
lines changed

7 files changed

+57
-47
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ VSCode extension that custom ui css style in both editor and webview
2929

3030
| Key | Description | Type | Default |
3131
| --------------------------------------------- | ---------------------------------------------------------------------------------------------------- | --------- | ---------- |
32-
| `custom-ui-style.monospace` | Global monospace font family that apply in both editor and webview, fallback to editor's font family | `string` | `` |
33-
| `custom-ui-style.sansSerif` | Global sans-serif font family that apply in both editor and webview | `string` | `` |
34-
| `custom-ui-style.backgroundUrl` | Full-screen background image url, support protocol: 'https://', 'file://', 'data:' | `string` | `` |
35-
| `custom-ui-style.backgroundOpacity` | Background image opacity | `number` | `0.9` |
36-
| `custom-ui-style.backgroundSize` | Background image size | `string` | `"cover"` |
37-
| `custom-ui-style.backgroundPosition` | Background image size | `string` | `"center"` |
32+
| `custom-ui-style.font.monospace` | Global monospace font family that apply in both editor and webview, fallback to editor's font family | `string` | `` |
33+
| `custom-ui-style.font.sansSerif` | Global sans-serif font family that apply in both editor and webview | `string` | `` |
34+
| `custom-ui-style.background.url` | Full-screen background image url, support protocol: 'https://', 'file://', 'data:' | `string` | `` |
35+
| `custom-ui-style.background.opacity` | Background image opacity | `number` | `0.9` |
36+
| `custom-ui-style.background.size` | Background image size | `string` | `"cover"` |
37+
| `custom-ui-style.background.position` | Background image size | `string` | `"center"` |
3838
| `custom-ui-style.stylesheet` | Custom css for editor, support nest selectors | `object` | `{}` |
39-
| `custom-ui-style.webviewMonospaceSelector` | Custom monospace selector in webview | `array` | `` |
40-
| `custom-ui-style.webviewSansSerifSelector` | Custom sans-serif selector in webview | `array` | `` |
41-
| `custom-ui-style.webviewStylesheet` | Custom css for webview, support nest selectors | `object` | `{}` |
42-
| `custom-ui-style.applyOnConfigurationChanged` | Whether to apply styles when configuration changed | `boolean` | `false` |
39+
| `custom-ui-style.webview.monospaceSelector` | Custom monospace selector in webview | `array` | `` |
40+
| `custom-ui-style.webview.sansSerifSelector` | Custom sans-serif selector in webview | `array` | `` |
41+
| `custom-ui-style.webview.stylesheet` | Custom css for webview, support nest selectors | `object` | `{}` |
42+
| `custom-ui-style.applyOnConfigurationChanged` | Whether to apply styles when configuration changed, 1500ms debounce | `boolean` | `false` |
4343

4444
<!-- configs -->
4545

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,28 @@
5353
"type": "object",
5454
"title": "Custom UI Style",
5555
"properties": {
56-
"custom-ui-style.monospace": {
56+
"custom-ui-style.font.monospace": {
5757
"scope": "application",
5858
"type": "string",
5959
"description": "Global monospace font family that apply in both editor and webview, fallback to editor's font family"
6060
},
61-
"custom-ui-style.sansSerif": {
61+
"custom-ui-style.font.sansSerif": {
6262
"scope": "application",
6363
"type": "string",
6464
"description": "Global sans-serif font family that apply in both editor and webview"
6565
},
66-
"custom-ui-style.backgroundUrl": {
66+
"custom-ui-style.background.url": {
6767
"scope": "machine",
6868
"type": "string",
6969
"description": "Full-screen background image url, support protocol: 'https://', 'file://', 'data:'"
7070
},
71-
"custom-ui-style.backgroundOpacity": {
71+
"custom-ui-style.background.opacity": {
7272
"scope": "application",
7373
"type": "number",
7474
"description": "Background image opacity",
7575
"default": 0.9
7676
},
77-
"custom-ui-style.backgroundSize": {
77+
"custom-ui-style.background.size": {
7878
"scope": "application",
7979
"type": "string",
8080
"enum": [
@@ -84,7 +84,7 @@
8484
"description": "Background image size",
8585
"default": "cover"
8686
},
87-
"custom-ui-style.backgroundPosition": {
87+
"custom-ui-style.background.position": {
8888
"scope": "application",
8989
"type": "string",
9090
"description": "Background image size",
@@ -95,23 +95,23 @@
9595
"type": "object",
9696
"description": "Custom css for editor, support nest selectors"
9797
},
98-
"custom-ui-style.webviewMonospaceSelector": {
98+
"custom-ui-style.webview.monospaceSelector": {
9999
"scope": "application",
100100
"type": "array",
101101
"items": {
102102
"type": "string"
103103
},
104104
"description": "Custom monospace selector in webview"
105105
},
106-
"custom-ui-style.webviewSansSerifSelector": {
106+
"custom-ui-style.webview.sansSerifSelector": {
107107
"scope": "application",
108108
"type": "array",
109109
"items": {
110110
"type": "string"
111111
},
112112
"description": "Custom sans-serif selector in webview"
113113
},
114-
"custom-ui-style.webviewStylesheet": {
114+
"custom-ui-style.webview.stylesheet": {
115115
"scope": "application",
116116
"type": "object",
117117
"description": "Custom css for webview, support nest selectors"
@@ -120,7 +120,7 @@
120120
"scope": "resource",
121121
"type": "boolean",
122122
"default": false,
123-
"description": "Whether to apply styles when configuration changed"
123+
"description": "Whether to apply styles when configuration changed, 1500ms debounce"
124124
}
125125
}
126126
}

src/config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const editorConfig = defineConfigObject('editor', {
1111
})
1212

1313
export function getFamilies() {
14-
let { monospace, sansSerif } = config
15-
monospace ||= editorConfig.fontFamily
16-
return { monospace, sansSerif }
14+
return {
15+
monospace: config['font.monospace'] || editorConfig.fontFamily,
16+
sansSerif: config['font.sansSerif'],
17+
}
1718
}

src/manager/css.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ import { config, getFamilies } from '../config'
33
import { normalizeUrl } from '../path'
44
import { generateStyleFromObject } from '../utils'
55
import { BaseFileManager } from './base'
6-
import { VSC_DFAULT_SANS_FONT, VSC_NOTEBOOK_MONO_FONT } from './js'
6+
import { VSC_DFAULT_SANS_FONT, VSC_NOTEBOOK_MONO_FONT } from './renderer'
77

88
const banner = '/* Custom UI Style Start */'
99
const footer = '/* Custom UI Style End */'
1010

1111
function generateBackgroundCSS() {
12-
const url = config.backgroundUrl
12+
const url = config['background.url']
1313
if (!url) {
1414
return ''
1515
}
1616
return `
1717
body:has([id='workbench.parts.editor']) {
18-
background-size: ${config.backgroundSize};
18+
background-size: ${config['background.size']};
1919
background-repeat: no-repeat;
2020
background-attachment: fixed; // for code-server
21-
background-position: ${config.backgroundPosition};
22-
opacity: ${config.backgroundOpacity};
21+
background-position: ${config['background.position']};
22+
opacity: ${config['background.opacity']};
2323
background-image: url('${normalizeUrl(url)}');
2424
}`
2525
}

src/manager/js.ts renamed to src/manager/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const VSC_DFAULT_SANS_FONT = {
1616

1717
export const VSC_NOTEBOOK_MONO_FONT = `"SF Mono", Monaco, Menlo, Consolas, "Ubuntu Mono", "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace`
1818

19-
export class JsFileManager extends BaseFileManager {
19+
export class RendererFileManager extends BaseFileManager {
2020
patch(fontChanged: boolean, content: () => string): Promisable<string | undefined> {
2121
if (!fontChanged) {
2222
return undefined

src/manager/webview.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,17 @@ const defaultSansSerifSelector: string[] = ['.font-sans', '.github-markdown-body
1111

1212
function getCSS() {
1313
const { monospace, sansSerif } = getFamilies()
14-
const {
15-
webviewSansSerifSelector = [],
16-
webviewMonospaceSelector = [],
17-
webviewStylesheet,
18-
} = config
1914
let result = ''
2015
if (monospace) {
21-
const monoSelectors = [...defaultMonospaceSelector, ...webviewMonospaceSelector]
16+
const monoSelectors = [...defaultMonospaceSelector, ...config['webview.monospaceSelector'] || []]
2217
result += `${monoSelectors}{font-family:${escapeQuote(monospace)}!important}`
2318
}
2419
if (sansSerif) {
25-
const sansSelectors = [...defaultSansSerifSelector, ...webviewSansSerifSelector]
20+
const sansSelectors = [...defaultSansSerifSelector, ...config['webview.sansSerifSelector'] || []]
2621
result += `${sansSelectors}{font-family:${escapeQuote(sansSerif)}!important}`
2722
}
28-
if (webviewStylesheet) {
29-
result += generateStyleFromObject(webviewStylesheet)
23+
if (config['webview.stylesheet']) {
24+
result += generateStyleFromObject(config['webview.stylesheet'])
3025
}
3126
return result
3227
}

src/path.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const webviewHTMLBakPath = getWebviewHTML(`.${bakExt}.html`)
2929
/**
3030
* See https://code.visualstudio.com/api/references/vscode-api#env
3131
*/
32-
function getMainPath(baseExt: string, backupExt?: string) {
32+
function getRendererPath(baseExt: string, backupExt?: string) {
3333
const ext = backupExt ? `${backupExt}.${baseExt}` : baseExt
3434
return path.join(
3535
baseDir,
@@ -42,21 +42,35 @@ function getMainPath(baseExt: string, backupExt?: string) {
4242
)
4343
}
4444
/**
45-
* css file path
45+
* CSS file path
4646
*/
47-
export const cssPath = getMainPath('css')
47+
export const cssPath = getRendererPath('css')
4848
/**
49-
* css file path
49+
* CSS file backup path
5050
*/
51-
export const cssBakPath = getMainPath('css', bakExt)
51+
export const cssBakPath = getRendererPath('css', bakExt)
5252
/**
53-
* js file path
53+
* Main js file path
5454
*/
55-
export const jsPath = getMainPath('js')
55+
export const rendererPath = getRendererPath('js')
5656
/**
57-
* js file path
57+
* Main js file backup path
5858
*/
59-
export const jsBakPath = getMainPath('js', bakExt)
59+
export const rendererBakPath = getRendererPath('js', bakExt)
60+
61+
function getMainPath(baseExt: string, backupExt?: string) {
62+
const ext = backupExt ? `${backupExt}.${baseExt}` : baseExt
63+
return path.join(
64+
baseDir,
65+
'vs',
66+
'code',
67+
'electron-main',
68+
`main.${ext}`,
69+
)
70+
}
71+
72+
export const mainPath = getMainPath('js')
73+
export const mainBakPath = getMainPath('js', bakExt)
6074

6175
export function normalizeUrl(url: string) {
6276
if (!url.startsWith('file://')) {

0 commit comments

Comments
 (0)