updated to v1.6.1
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
## Version 1.6.1
|
||||||
|
- fixed FIGlet converted text output on indented selections
|
||||||
|
- refactored auto comment code
|
||||||
|
- added SCSS and Typescript auto comment support
|
||||||
|
|
||||||
## Version 1.6
|
## Version 1.6
|
||||||
- added option to auto comment FIGlet converted output for CSS, HTML, Javascript, and PHP syntaxes
|
- added option to auto comment FIGlet converted output for CSS, HTML, Javascript, and PHP syntaxes
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
- convert selected text to FIGlet text
|
- convert selected text to FIGlet text
|
||||||
- select FIGlet font
|
- select FIGlet font
|
||||||
- configure FIGlet text output options
|
- configure FIGlet text output options
|
||||||
- option to auto comment converted text (HTML, Javascript, and PHP syntaxes only)
|
- option to auto comment converted text; supported syntaxes: CSS, HTML, Javascript, PHP, Typescript, and SCSS
|
||||||
- prepend/append new lines to converted text
|
- prepend/append new lines to converted text
|
||||||
|
|
||||||
# Requirements
|
# Requirements
|
||||||
|
@ -44,6 +44,7 @@ nova.commands.register('figlet', (workspace, figletArgs, textToConvert, postConv
|
|||||||
process.start()
|
process.start()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// FIGlet convert the selected text in the editor
|
// FIGlet convert the selected text in the editor
|
||||||
nova.commands.register('figletTextEditor', editor => {
|
nova.commands.register('figletTextEditor', editor => {
|
||||||
let figConfig = {
|
let figConfig = {
|
||||||
@ -53,15 +54,23 @@ nova.commands.register('figletTextEditor', editor => {
|
|||||||
justification: nova.config.get('figlet_text.justification', 'string'),
|
justification: nova.config.get('figlet_text.justification', 'string'),
|
||||||
}
|
}
|
||||||
|
|
||||||
let syntax = editor.document.syntax
|
|
||||||
let comment = nova.config.get('figlet_text.comment', 'boolean')
|
let comment = nova.config.get('figlet_text.comment', 'boolean')
|
||||||
let commentPadding = nova.config.get('figlet_text.commentPadding', 'number')
|
let commentPadding = nova.config.get('figlet_text.commentPadding', 'number')
|
||||||
let commentPaddingStr = nova.config.get('figlet_text.commentPaddingStr', 'string')
|
let commentPaddingStr = nova.config.get('figlet_text.commentPaddingStr', 'string')
|
||||||
let commentChars = {
|
const getCommentChars = () => {
|
||||||
css: {start: '/*', end: '*/'},
|
switch (editor.document.syntax) {
|
||||||
html: {start: '<!--', end: '-->'},
|
case 'css':
|
||||||
javascript: {start: '//', end: ''},
|
case 'scss':
|
||||||
php: {start: '//', end: ''}
|
return {start: '/*', end: '*/'}
|
||||||
|
case 'html':
|
||||||
|
return {start: '<!--', end: '-->'}
|
||||||
|
case 'javascript':
|
||||||
|
case 'typescript':
|
||||||
|
case 'php':
|
||||||
|
return {start: '//', end: ''}
|
||||||
|
default:
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let prependNewLines = nova.config.get('figlet_text.prependNewLines', 'number')
|
let prependNewLines = nova.config.get('figlet_text.prependNewLines', 'number')
|
||||||
let appendNewLines = nova.config.get('figlet_text.appendNewLines', 'number')
|
let appendNewLines = nova.config.get('figlet_text.appendNewLines', 'number')
|
||||||
@ -70,31 +79,53 @@ nova.commands.register('figletTextEditor', editor => {
|
|||||||
|
|
||||||
for (let range of selectedRanges) {
|
for (let range of selectedRanges) {
|
||||||
let text = editor.getTextInRange(range)
|
let text = editor.getTextInRange(range)
|
||||||
|
let indentRange = new Range(editor.getLineRangeForRange(range).start, range.start)
|
||||||
|
|
||||||
nova.commands.invoke('figlet', figConfig, text, figletText => {
|
nova.commands.invoke('figlet', figConfig, text, figletText => {
|
||||||
// comment each line if the option is selected
|
// comment each line if the option is selected
|
||||||
if (comment && (syntax === 'css' || syntax === 'html' || syntax === 'javascript' || syntax === 'php')) {
|
// and the comment structure is defined
|
||||||
|
if (comment && getCommentChars() !== null) {
|
||||||
|
// convert the FIGlet string to an array of strings
|
||||||
|
// to make it easier to comment line by line
|
||||||
let lines = figletText.split('\n')
|
let lines = figletText.split('\n')
|
||||||
|
|
||||||
|
// find the longest line so we can add whitespace to shorter
|
||||||
|
// lines so closing comments line up if the syntax uses them
|
||||||
let longestLine = 0
|
let longestLine = 0
|
||||||
lines.map(line => {
|
lines.map(line => { if (line.length > longestLine) longestLine = line.length })
|
||||||
if (line.length > longestLine) longestLine = line.length
|
|
||||||
})
|
|
||||||
|
|
||||||
|
// add the comment characters, lengthen lines with closing
|
||||||
|
// comments, and add user configured comment padding
|
||||||
let linesCommented = lines.map(line => {
|
let linesCommented = lines.map(line => {
|
||||||
let linePadding = 0
|
let linePadding = 0
|
||||||
if (line.length < longestLine && (commentChars[syntax].end !== '')) linePadding = longestLine - line.length
|
if (line.length < longestLine && (getCommentChars().end !== '')) linePadding = longestLine - line.length
|
||||||
return `${commentChars[syntax].start}${commentPaddingStr.repeat(commentPadding)}${line}${' '.repeat(linePadding)}${commentPaddingStr.repeat(commentPadding)}${commentChars[syntax].end}`.trimEnd()
|
|
||||||
|
// return the fully commented and formatted array of strings
|
||||||
|
return `${getCommentChars().start}${commentPaddingStr.repeat(commentPadding)}${line}${' '.repeat(linePadding)}${commentPaddingStr.repeat(commentPadding)}${getCommentChars().end}`.trimEnd()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// convert the array of strings to a single string
|
||||||
figletText = linesCommented.join('\n')
|
figletText = linesCommented.join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!indentRange.empty) {
|
||||||
|
let lines = figletText.split('\n')
|
||||||
|
let indentText = editor.getTextInRange(indentRange)
|
||||||
|
let linesIndented = lines.map((line, index) => {
|
||||||
|
if (index === 0) {
|
||||||
|
return `${line}`.trimEnd()
|
||||||
|
} else {
|
||||||
|
return `${indentText}${line}`.trimEnd()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
figletText = linesIndented.join('\n')
|
||||||
|
}
|
||||||
|
|
||||||
// prepend/append new lines
|
// prepend/append new lines
|
||||||
if (prependNewLines > 0) figletText = `${'\n'.repeat(prependNewLines)}${figletText}`
|
if (prependNewLines > 0) figletText = `${'\n'.repeat(prependNewLines)}${figletText}`
|
||||||
if (appendNewLines > 0) figletText = `${figletText}${'\n'.repeat(appendNewLines)}`
|
if (appendNewLines > 0) figletText = `${figletText}${'\n'.repeat(appendNewLines)}`
|
||||||
|
|
||||||
// replace the selection with the converted/transformed FIGlet text
|
// replace the selection with the fully final FIGlet text
|
||||||
editor.edit(e => { e.replace(range, figletText) })
|
editor.edit(e => { e.replace(range, figletText) })
|
||||||
|
|
||||||
// deselect and position the cursor
|
// deselect and position the cursor
|
||||||
@ -103,6 +134,7 @@ nova.commands.register('figletTextEditor', editor => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// FIGlet convert the preview text in the extension config
|
// FIGlet convert the preview text in the extension config
|
||||||
nova.commands.register('figletTextFontPreview', workspace => {
|
nova.commands.register('figletTextFontPreview', workspace => {
|
||||||
let figConfig = {
|
let figConfig = {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "FIGlet Text",
|
"name": "FIGlet Text",
|
||||||
"organization": "Dan Remollino",
|
"organization": "Dan Remollino",
|
||||||
"description": "Convert selected text to FIGlet. Great for adding readable text to the Minimap, creating l33t text headers, and organizing files.",
|
"description": "Convert selected text to FIGlet. Great for adding readable text to the Minimap, creating l33t text headers, and organizing files.",
|
||||||
"version": "1.6",
|
"version": "1.6.1",
|
||||||
"categories": ["commands", "formatters"],
|
"categories": ["commands", "formatters"],
|
||||||
|
|
||||||
"entitlements": {
|
"entitlements": {
|
||||||
@ -240,7 +240,7 @@
|
|||||||
{
|
{
|
||||||
"key": "figlet_text.comment",
|
"key": "figlet_text.comment",
|
||||||
"title": "Comment FIGlet Output",
|
"title": "Comment FIGlet Output",
|
||||||
"description": "FIGlet Text will auto line comment the output. Currently supported in CSS, HTML, Javascript, and PHP syntaxes.",
|
"description": "FIGlet Text will auto line comment the output. Currently supported in CSS, HTML, Javascript, PHP, Typescript, and SCSS syntaxes.",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user