Skip to content

Commit 2ce500a

Browse files
committed
Fix #44 and some refactor
1 parent 515d736 commit 2ce500a

File tree

2 files changed

+46
-35
lines changed

2 files changed

+46
-35
lines changed

src/extension.js

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ function activate(context) {
2020
let panel
2121

2222
vscode.window.registerWebviewPanelSerializer('polacode', {
23-
async deserializeWebviewPanel(panel, state) {
24-
panel = panel
23+
async deserializeWebviewPanel(_panel, state) {
24+
panel = _panel
2525
panel.webview.html = getHtmlContent(htmlPath)
2626
panel.webview.postMessage({
2727
type: 'restore',
2828
innerHTML: state.innerHTML,
2929
bgColor: context.globalState.get('polacode.bgColor', '#2e3440')
3030
})
31+
setupSelectionSync()
32+
setupMessageListeners()
3133
}
3234
})
3335

@@ -39,6 +41,28 @@ function activate(context) {
3941

4042
panel.webview.html = getHtmlContent(htmlPath)
4143

44+
setupMessageListeners()
45+
46+
const fontFamily = vscode.workspace.getConfiguration('editor').fontFamily
47+
const bgColor = context.globalState.get('polacode.bgColor', '#2e3440')
48+
panel.webview.postMessage({
49+
type: 'init',
50+
fontFamily,
51+
bgColor
52+
})
53+
54+
syncSettings()
55+
})
56+
57+
vscode.workspace.onDidChangeConfiguration(e => {
58+
if (e.affectsConfiguration('polacode') || e.affectsConfiguration('editor')) {
59+
syncSettings()
60+
}
61+
})
62+
63+
setupSelectionSync()
64+
65+
function setupMessageListeners() {
4266
panel.webview.onDidReceiveMessage(({ type, data }) => {
4367
switch (type) {
4468
case 'shoot':
@@ -74,48 +98,30 @@ function activate(context) {
7498
break
7599
}
76100
})
77-
78-
const fontFamily = vscode.workspace.getConfiguration('editor').fontFamily
79-
const bgColor = context.globalState.get('polacode.bgColor', '#2e3440')
80-
panel.webview.postMessage({
81-
type: 'init',
82-
fontFamily,
83-
bgColor
84-
})
85-
86-
syncSettings()
87-
})
101+
}
88102

89103
function syncSettings() {
90104
const settings = vscode.workspace.getConfiguration('polacode')
105+
const editorSettings = vscode.workspace.getConfiguration('editor')
91106
panel.webview.postMessage({
92107
type: 'updateSettings',
93108
shadow: settings.get('shadow'),
94109
background: settings.get('background'),
95-
target: settings.get('target')
110+
target: settings.get('target'),
111+
ligature: editorSettings.get('fontLigatures')
96112
})
97113
}
98114

99-
vscode.window.onDidChangeTextEditorSelection(e => {
100-
if (e.selections[0] && !e.selections[0].isEmpty) {
101-
vscode.commands.executeCommand('editor.action.clipboardCopyAction')
102-
panel.postMessage({
103-
type: 'update'
104-
})
105-
}
106-
})
107-
108-
vscode.workspace.onDidChangeConfiguration(e => {
109-
if (e.affectsConfiguration('polacode')) {
110-
const settings = vscode.workspace.getConfiguration('polacode')
111-
panel.webview.postMessage({
112-
type: 'updateSettings',
113-
shadow: settings.get('shadow'),
114-
transparentBackground: settings.get('transparentBackground'),
115-
target: settings.get('target')
116-
})
117-
}
118-
})
115+
function setupSelectionSync() {
116+
vscode.window.onDidChangeTextEditorSelection(e => {
117+
if (e.selections[0] && !e.selections[0].isEmpty) {
118+
vscode.commands.executeCommand('editor.action.clipboardCopyAction')
119+
panel.postMessage({
120+
type: 'update'
121+
})
122+
}
123+
})
124+
}
119125
}
120126

121127
function getHtmlContent(htmlPath) {

webview/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,14 @@
236236
} else if (e.data.type === 'restoreBgColor') {
237237
updateEnvironment(e.data.bgColor)
238238
} else if (e.data.type === 'updateSettings') {
239-
snippet.style.boxShadow = e.data.shadow
239+
snippetNode.style.boxShadow = e.data.shadow
240240
target = e.data.target
241241
transparentBackground = e.data.transparentBackground
242+
if (e.data.ligature) {
243+
snippetNode.style.fontVariantLigatures = 'normal'
244+
} else {
245+
snippetNode.style.fontVariantLigatures = 'none'
246+
}
242247
}
243248
}
244249
})

0 commit comments

Comments
 (0)