Skip to content

Commit 0ed0338

Browse files
committed
use selection. fix #14
1 parent 3fb9ba1 commit 0ed0338

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/extension.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ function activate(context) {
4545
})
4646
})
4747

48+
vscode.window.onDidChangeTextEditorSelection(e => {
49+
if (e.selections[0] && !e.selections[0].isEmpty) {
50+
vscode.commands.executeCommand('editor.action.clipboardCopyAction')
51+
vscode.commands.executeCommand('_workbench.htmlPreview.postMessage', indexUri, {
52+
type: 'update'
53+
})
54+
}
55+
})
56+
4857
vscode.commands.registerCommand('polacode._onmessage', ({ type, data }) => {
4958
if (type === 'updateBgColor') {
5059
context.globalState.update('polacode.bgColor', data.bgColor)

src/webview/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ function getSnippetBgColor(html) {
5656
return html.match(/background-color: (#[a-fA-F0-9]+)/)[1]
5757
}
5858

59-
6059
function updateEnvironment(snippetBgColor) {
6160
// update snippet bg color
6261
document.getElementById('snippet').style.backgroundColor = snippetBgColor
@@ -171,6 +170,8 @@ window.addEventListener('message', e => {
171170
}
172171

173172
snippetContainerNode.style.opacity = 1
173+
} else if (e.data.type === 'update') {
174+
document.execCommand('paste')
174175
}
175176
}
176177
})

0 commit comments

Comments
 (0)