Skip to content

Commit eed4cec

Browse files
authored
Merge pull request #121 from kufii/patch-1
Fix font-family not loading correctly
2 parents d822477 + 87a0d00 commit eed4cec

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

webview/index.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
let target = 'container'
55
let transparentBackground = false
66
let backgroundColor = '#f2f2f2'
7+
let fontFamily
78

89
vscode.postMessage({
910
type: 'getAndUpdateCacheAndSettings'
@@ -14,14 +15,15 @@
1415
const obturateur = document.getElementById('save')
1516

1617
snippetContainerNode.style.opacity = '1'
17-
const oldState = vscode.getState();
18+
const oldState = vscode.getState()
1819
if (oldState && oldState.innerHTML) {
1920
snippetNode.innerHTML = oldState.innerHTML
2021
}
2122

22-
const getInitialHtml = fontFamily => {
23+
const getInitialHtml = ff => {
2324
const cameraWithFlashEmoji = String.fromCodePoint(128248)
24-
const monoFontStack = `${fontFamily},SFMono-Regular,Consolas,DejaVu Sans Mono,Ubuntu Mono,Liberation Mono,Menlo,Courier,monospace`
25+
const monoFontStack = `${ff},SFMono-Regular,Consolas,DejaVu Sans Mono,Ubuntu Mono,Liberation Mono,Menlo,Courier,monospace`
26+
fontFamily = monoFontStack
2527
return `<meta charset="utf-8"><div style="color: #d8dee9;background-color: #2e3440; font-family: ${monoFontStack};font-weight: normal;font-size: 12px;line-height: 18px;white-space: pre;"><div><span style="color: #8fbcbb;">console</span><span style="color: #eceff4;">.</span><span style="color: #88c0d0;">log</span><span style="color: #d8dee9;">(</span><span style="color: #eceff4;">'</span><span style="color: #a3be8c;">0. Run command \`Polacode ${cameraWithFlashEmoji}\`</span><span style="color: #eceff4;">'</span><span style="color: #d8dee9;">)</span></div><div><span style="color: #8fbcbb;">console</span><span style="color: #eceff4;">.</span><span style="color: #88c0d0;">log</span><span style="color: #d8dee9;">(</span><span style="color: #eceff4;">'</span><span style="color: #a3be8c;">1. Copy some code</span><span style="color: #eceff4;">'</span><span style="color: #d8dee9;">)</span></div><div><span style="color: #8fbcbb;">console</span><span style="color: #eceff4;">.</span><span style="color: #88c0d0;">log</span><span style="color: #d8dee9;">(</span><span style="color: #eceff4;">'</span><span style="color: #a3be8c;">2. Paste into Polacode view</span><span style="color: #eceff4;">'</span><span style="color: #d8dee9;">)</span></div><div><span style="color: #8fbcbb;">console</span><span style="color: #eceff4;">.</span><span style="color: #88c0d0;">log</span><span style="color: #d8dee9;">(</span><span style="color: #eceff4;">'</span><span style="color: #a3be8c;">3. Click the button ${cameraWithFlashEmoji}</span><span style="color: #eceff4;">'</span><span style="color: #d8dee9;">)</span></div></div></div>`
2628
}
2729

@@ -61,7 +63,7 @@
6163
}
6264
function getSnippetBgColor(html) {
6365
const match = html.match(/background-color: (#[a-fA-F0-9]+)/)
64-
return match ? match[1] : undefined;
66+
return match ? match[1] : undefined
6567
}
6668

6769
function updateEnvironment(snippetBgColor) {
@@ -102,7 +104,10 @@
102104
}
103105

104106
document.addEventListener('paste', e => {
105-
const innerHTML = e.clipboardData.getData('text/html')
107+
const div = document.createElement('div')
108+
div.innerHTML = e.clipboardData.getData('text/html')
109+
div.querySelector('div').style.fontFamily = fontFamily
110+
const innerHTML = div.innerHTML
106111

107112
const code = e.clipboardData.getData('text/plain')
108113
const minIndent = getMinIndent(code)
@@ -129,7 +134,7 @@
129134

130135
obturateur.addEventListener('click', () => {
131136
if (target === 'container') {
132-
shootAll()
137+
shootAll()
133138
} else {
134139
shootSnippet()
135140
}
@@ -228,7 +233,6 @@
228233
} else {
229234
snippetContainerNode.style.background = 'none'
230235
}
231-
232236
} else if (e.data.type === 'update') {
233237
document.execCommand('paste')
234238
} else if (e.data.type === 'restore') {
@@ -253,10 +257,10 @@
253257
})()
254258

255259
function getRgba(hex, transparentBackground) {
256-
const bigint = parseInt(hex.slice(1), 16);
257-
const r = (bigint >> 16) & 255;
258-
const g = (bigint >> 8) & 255;
259-
const b = bigint & 255;
260+
const bigint = parseInt(hex.slice(1), 16)
261+
const r = (bigint >> 16) & 255
262+
const g = (bigint >> 8) & 255
263+
const b = bigint & 255
260264
const a = transparentBackground ? 0 : 1
261265
return `rgba(${r}, ${g}, ${b}, ${a})`
262-
}
266+
}

0 commit comments

Comments
 (0)