Add filename and date to screenshot file if not Untitled#135
Open
emajeru wants to merge 3 commits intooctref:masterfrom
Open
Add filename and date to screenshot file if not Untitled#135emajeru wants to merge 3 commits intooctref:masterfrom
emajeru wants to merge 3 commits intooctref:masterfrom
Conversation
emajeru
commented
Mar 30, 2020
Comment on lines
-19
to
+20
| let lastUsedImageUri = vscode.Uri.file(path.resolve(homedir(), 'Desktop/code.png')) | ||
| let lastUsedImageUri | ||
| let lastFile |
Author
There was a problem hiding this comment.
- Set lastUserImageUri to undefined until it is assigned for the first time during the call to the
shootevent. - Added variable to contain data on the last updated TextDocument object.
emajeru
commented
Mar 30, 2020
Comment on lines
-77
to
+78
| defaultUri: lastUsedImageUri, | ||
| defaultUri: getFileName(), |
Author
There was a problem hiding this comment.
- Call to the
getFileNamefunction instead of using the global variable as it becomes a derived value.
emajeru
commented
Mar 30, 2020
| function setupSelectionSync() { | ||
| return vscode.window.onDidChangeTextEditorSelection(e => { | ||
| if (e.selections[0] && !e.selections[0].isEmpty) { | ||
| lastFile = e.textEditor.document |
Author
There was a problem hiding this comment.
- Monitor document selection during each update.
emajeru
commented
Mar 30, 2020
Comment on lines
+123
to
+140
| 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 | ||
| } | ||
|
|
Author
There was a problem hiding this comment.
- Computes the default file name with both the referenced document title and date appended.
- Prefix of
coderemains to identify the document as a Polacode export. - Fallback to the original name
code.pngif the selected document is Untitled. - Set the global
lastUsedImageUrivariable for use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added
Monitors the TextDocument object of the file with selected text and uses the last calculated value to computer the filename when 'shoot' message is received. If the file that was referenced has never been saved the name will default to 'code.png'.
Fixes #96