-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
Add filename and date to screenshot file if not Untitled #135
base: master
Are you sure you want to change the base?
Conversation
let lastUsedImageUri = vscode.Uri.file(path.resolve(homedir(), 'Desktop/code.png')) | ||
let lastUsedImageUri | ||
let lastFile |
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.
- Set lastUserImageUri to undefined until it is assigned for the first time during the call to the
shoot
event. - Added variable to contain data on the last updated TextDocument object.
defaultUri: lastUsedImageUri, | ||
defaultUri: getFileName(), |
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.
- Call to the
getFileName
function instead of using the global variable as it becomes a derived value.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
- Monitor document selection during each update.
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 | ||
} | ||
|
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.
- Computes the default file name with both the referenced document title and date appended.
- Prefix of
code
remains to identify the document as a Polacode export. - Fallback to the original name
code.png
if the selected document is Untitled. - Set the global
lastUsedImageUri
variable for use.
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