Skip to content

Commit f506167

Browse files
committed
fix: read font family from global instead of workspace
1 parent 7061e8c commit f506167

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { defineConfigObject } from 'reactive-vscode'
2+
import { workspace } from 'vscode'
23
import * as Meta from './generated/meta'
34

45
export const config = defineConfigObject<Meta.ScopedConfigKeyTypeMap>(
56
Meta.scopedConfigs.scope,
67
Meta.scopedConfigs.defaults,
78
)
89

9-
export const editorConfig = defineConfigObject('editor', {
10-
fontFamily: String,
11-
})
10+
export const ffKey = 'editor.fontFamily'
1211

1312
export function getFamilies() {
1413
return {
15-
monospace: config['font.monospace'] || editorConfig.fontFamily,
14+
monospace: config['font.monospace']
15+
|| workspace.getConfiguration().inspect<string>(ffKey)!.globalValue,
1616
sansSerif: config['font.sansSerif'],
1717
}
1818
}

src/index.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineExtension, useCommand, useDisposable } from 'reactive-vscode'
22
import { workspace } from 'vscode'
3-
import { config } from './config'
3+
import { config, ffKey } from './config'
44
import * as Meta from './generated/meta'
55
import { createFileManagers } from './manager'
66
import { debounce, showMessage } from './utils'
@@ -23,13 +23,32 @@ const { activate, deactivate } = defineExtension(() => {
2323
useCommand(Meta.commands.reload, () => reload(changedMsg))
2424
useCommand(Meta.commands.rollback, () => rollback(rollbackMsg))
2525

26+
const notifyChanged = () => showMessage(
27+
'Configuration changed, apply now?',
28+
'Yes',
29+
'No',
30+
)
31+
.then<any>(item => item === 'Yes' && reload(changedMsg))
32+
2633
useDisposable(
2734
workspace.onDidChangeConfiguration(
2835
debounce(
29-
e => (e.affectsConfiguration(Meta.name) || e.affectsConfiguration('editor.fontFamily'))
30-
&& config.watch
31-
&& showMessage('Configuration changed, apply now?', 'Yes', 'No')
32-
.then<any>(item => item === 'Yes' && reload(changedMsg)),
36+
(e) => {
37+
if (!config.watch) {
38+
return
39+
}
40+
if (e.affectsConfiguration(Meta.name)) {
41+
notifyChanged()
42+
} else if (e.affectsConfiguration(ffKey) && !config['font.monospace']) {
43+
const {
44+
globalValue,
45+
workspaceValue,
46+
} = workspace.getConfiguration().inspect<string>(ffKey)!
47+
if (globalValue === workspaceValue) {
48+
notifyChanged()
49+
}
50+
}
51+
},
3352
1000,
3453
),
3554
),

0 commit comments

Comments
 (0)