Skip to content

Allows user to customize container padding and background color #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 65 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
{
"name": "polacode",
"displayName": "Polacode",
"description": "📸 Polaroid for your code",
"version": "0.2.2",
"repository": {
"type": "git",
"url": "https://github.com/octref/polacode.git"
},
"publisher": "pnp",
"keywords": [
"polacode",
"polaroid",
"screenshot",
"snippet",
"share"
],
"galleryBanner": {
"color": "#fbfbfb",
"theme": "light"
},
"icon": "icon.png",
"categories": ["Other"],
"engines": {
"vscode": "^1.19.0"
},
"activationEvents": ["onCommand:polacode.activate"],
"main": "./src/extension",
"contributes": {
"commands": [
{
"command": "polacode.activate",
"title": "Polacode 📸"
}
]
}
"name": "polacode",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recommend changing the indent of the file.

"displayName": "Polacode",
"description": "📸 Polaroid for your code",
"version": "0.2.2",
"repository": {
"type": "git",
"url": "https://github.com/octref/polacode.git"
},
"publisher": "pnp",
"keywords": [
"polacode",
"polaroid",
"screenshot",
"snippet",
"share"
],
"galleryBanner": {
"color": "#fbfbfb",
"theme": "light"
},
"icon": "icon.png",
"categories": ["Other"],
"engines": {
"vscode": "^1.19.0"
},
"activationEvents": ["onCommand:polacode.activate"],
"main": "./src/extension",
"contributes": {
"commands": [
{
"command": "polacode.activate",
"title": "Polacode 📸"
}
],
"configuration": {
"title": "Polacode Custom Styles",
"properties": {
"polacode.container.paddingLeft": {
"type": "number",
"default": "22",
"description": "Specifies the padding left that will be applied to the container"
},
"polacode.container.paddingRight": {
"type": "number",
"default": "22",
"description": "Specifies the padding right that will be applied to the container"
},
"polacode.container.paddingTop": {
"type": "number",
"default": "22",
"description": "Specifies the padding top that will be applied to the container"
},
"polacode.container.paddingBottom": {
"type": "number",
"default": "22",
"description": "Specifies the padding bottom that will be applied to the container"
},
"polacode.container.backgroundColor": {
"type": "string",
"default": "#f2f2f2",
"description": "Specifies the background color that will be applied to the container"
}
}
}
}
}
4 changes: 3 additions & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const vscode = require('vscode')
const path = require('path')
const { writeFileSync } = require('fs')
const { homedir } = require('os')
const customizations = vscode.workspace.getConfiguration("polacode").container;

const writeSerializedBlobToFile = (serializeBlob, fileName) => {
const bytes = new Uint8Array(serializeBlob.split(','))
Expand Down Expand Up @@ -40,7 +41,8 @@ function activate(context) {
vscode.commands.executeCommand('_workbench.htmlPreview.postMessage', indexUri, {
type: 'init',
fontFamily,
bgColor
bgColor,
customizations
})
})
})
Expand Down
9 changes: 5 additions & 4 deletions src/webview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ obturateur.addEventListener('mouseover', () => {
window.addEventListener('message', e => {
if (e) {
if (e.data.type === 'init') {
const { fontFamily, bgColor } = e.data
const { fontFamily, bgColor, customizations } = e.data

const initialHtml = getInitialHtml(fontFamily)
snippetNode.innerHTML = initialHtml

// update backdrop color, using bgColor from last pasted snippet
// cannot deduce from initialHtml since it's always using Nord color
// update container padding and background color using user settings
snippetContainerNode.style.padding = `${customizations.paddingTop}px ${customizations.paddingRight}px ${customizations.paddingBottom}px ${customizations.paddingLeft}px`;

if (isDark(bgColor)) {
snippetContainerNode.style.backgroundColor = '#f2f2f2'
snippetContainerNode.style.backgroundColor = customizations.backgroundColor
} else {
snippetContainerNode.style.background = 'none'
}
Expand Down