-
-
Couldn't load subscription status.
- Fork 185
Add filename and date to screenshot file if not Untitled #135
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,8 @@ const P_TITLE = 'Polacode 📸' | |
| function activate(context) { | ||
| const htmlPath = path.resolve(context.extensionPath, 'webview/index.html') | ||
|
|
||
| let lastUsedImageUri = vscode.Uri.file(path.resolve(homedir(), 'Desktop/code.png')) | ||
| let lastUsedImageUri | ||
| let lastFile | ||
| let panel | ||
|
|
||
| vscode.window.registerWebviewPanelSerializer('polacode', { | ||
|
|
@@ -74,7 +75,7 @@ function activate(context) { | |
| case 'shoot': | ||
| vscode.window | ||
| .showSaveDialog({ | ||
| defaultUri: lastUsedImageUri, | ||
| defaultUri: getFileName(), | ||
|
Comment on lines
-77
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| filters: { | ||
| Images: ['png'] | ||
| } | ||
|
|
@@ -119,9 +120,28 @@ function activate(context) { | |
| }) | ||
| } | ||
|
|
||
| function getFileName() { | ||
| let fileName = 'code.png' | ||
| if (!lastFile.isUntitled) { | ||
| const file = lastFile.uri.path.replace(/.*\/(.+[\..+]*)?(\..+)?$/, '$1$2') | ||
| const dateString = () => { | ||
| const date = new Date() | ||
| return date.toLocaleString() | ||
| .replace(/\//g, '-') | ||
| .replace(/,/, ' at') | ||
| .replace(/:/g, '.') | ||
| .replace(/(\d+)-(\d+)-(\d+)/, '$3-$1-$2') | ||
| } | ||
| fileName = `code - ${file} ${dateString()}.png` | ||
| } | ||
| lastUsedImageUri = vscode.Uri.file(path.resolve(homedir(), 'Desktop', fileName)) | ||
| return lastUsedImageUri | ||
| } | ||
|
|
||
|
Comment on lines
+123
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| function setupSelectionSync() { | ||
| return vscode.window.onDidChangeTextEditorSelection(e => { | ||
| if (e.selections[0] && !e.selections[0].isEmpty) { | ||
| lastFile = e.textEditor.document | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| vscode.commands.executeCommand('editor.action.clipboardCopyWithSyntaxHighlightingAction') | ||
| panel.postMessage({ | ||
| type: 'update' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shootevent.