updated to v1.12

This commit is contained in:
Dan Remollino
2023-03-29 16:30:21 -04:00
parent 32a2608219
commit 2297e68c86
3 changed files with 45 additions and 17 deletions

View File

@ -1,3 +1,7 @@
## Version 1.12
- added option toggle margin output
- added separate Comment Padding output options for block and inline comments
## Version 1.11 ## Version 1.11
- added option to use inline or block comments - added option to use inline or block comments

View File

@ -92,7 +92,10 @@ nova.commands.register('figletTextEditor', editor => {
let commentsEnabled = nova.config.get('figlet_text.comment', 'boolean') let commentsEnabled = nova.config.get('figlet_text.comment', 'boolean')
let commentType = nova.config.get('figlet_text.commentType', 'string') let commentType = nova.config.get('figlet_text.commentType', 'string')
let commentPadding = nova.config.get('figlet_text.commentPadding', 'number') let commentPadding = {
block: nova.config.get('figlet_text.commentPaddingBlock', 'number'),
inline: nova.config.get('figlet_text.commentPaddingInline', 'number')
}
let commentPaddingStr = nova.config.get('figlet_text.commentPaddingStr', 'string') let commentPaddingStr = nova.config.get('figlet_text.commentPaddingStr', 'string')
const getCommentChars = () => { const getCommentChars = () => {
switch (editor.document.syntax) { switch (editor.document.syntax) {
@ -110,6 +113,7 @@ nova.commands.register('figletTextEditor', editor => {
} }
} }
let marginsEnabled = nova.config.get('figlet_text.margins', 'boolean')
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')
@ -132,7 +136,7 @@ nova.commands.register('figletTextEditor', editor => {
// easier to modify line by line; order of transformations matter // easier to modify line by line; order of transformations matter
let figletTextArr = figletText.split('\n') let figletTextArr = figletText.split('\n')
// add borders if the option is enabled // add borders/padding if the option is enabled
if (bordersEnabled) { if (bordersEnabled) {
let longestLine = 0 let longestLine = 0
figletTextArr.map(line => { if (line.length > longestLine) longestLine = line.length }) figletTextArr.map(line => { if (line.length > longestLine) longestLine = line.length })
@ -230,7 +234,7 @@ nova.commands.register('figletTextEditor', editor => {
if (!borderBuffer.widthBottom.empty) figletTextArr = figletTextArr.concat(borderBuffer.widthBottom) if (!borderBuffer.widthBottom.empty) figletTextArr = figletTextArr.concat(borderBuffer.widthBottom)
} }
// comment each line if the option is selected and a // comment each line if the option is enabled and a
// comment structure is defined for the current syntax // comment structure is defined for the current syntax
if (commentsEnabled && getCommentChars() !== null) { if (commentsEnabled && getCommentChars() !== null) {
switch (commentType) { switch (commentType) {
@ -248,20 +252,26 @@ nova.commands.register('figletTextEditor', editor => {
// return the commented line if not whitespace // return the commented line if not whitespace
if (/^\s+$/.test(line)) return '\n' if (/^\s+$/.test(line)) return '\n'
return `${getCommentChars().inline.start}${commentPaddingStr.repeat(commentPadding)}${line}${' '.repeat(linePadding)}${commentPaddingStr.repeat(commentPadding)}${getCommentChars().inline.end}`.trimEnd() return `${getCommentChars().inline.start}${commentPaddingStr.repeat(commentPadding.inline)}${line}${' '.repeat(linePadding)}${commentPaddingStr.repeat(commentPadding.inline)}${getCommentChars().inline.end}`.trimEnd()
}) })
break break
case 'block': case 'block':
if (commentPadding.block > 0) {
figletTextArr.unshift('\n'.repeat(commentPadding.block - 1))
figletTextArr.push('\n'.repeat(commentPadding.block - 1))
}
figletTextArr.unshift(getCommentChars().block.start) figletTextArr.unshift(getCommentChars().block.start)
figletTextArr.push(getCommentChars().block.end) figletTextArr.push(getCommentChars().block.end)
break break
} }
} }
// prepend/append new lines // add margins if the option is enabled
if (marginsEnabled) {
// subtract one; Array.prototype.join('\n') before editor output // subtract one; Array.prototype.join('\n') before editor output
if (prependNewLines > 0) figletTextArr = [`${'\n'.repeat(prependNewLines - 1)}`].concat(figletTextArr) if (prependNewLines > 0) figletTextArr = [`${'\n'.repeat(prependNewLines - 1)}`].concat(figletTextArr)
if (appendNewLines > 0) figletTextArr = figletTextArr.concat([`${'\n'.repeat(appendNewLines - 1)}`]) if (appendNewLines > 0) figletTextArr = figletTextArr.concat([`${'\n'.repeat(appendNewLines)}`])
}
// indent subsequent lines after the first if // indent subsequent lines after the first if
// the line with the selection was indented // the line with the selection was indented

View File

@ -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.11", "version": "1.12",
"categories": ["commands", "formatters"], "categories": ["commands", "formatters"],
"entitlements": { "entitlements": {
@ -523,19 +523,26 @@
"title": "Comment Type", "title": "Comment Type",
"description": "Comment output line by line or as a single block.", "description": "Comment output line by line or as a single block.",
"type": "enum", "type": "enum",
"values": [["inline", "Inline"], ["block", "Block"]], "values": [["block", "Block"], ["inline", "Inline"]],
"default": "inline" "default": "inline"
}, },
{ {
"key": "figlet_text.commentPadding", "key": "figlet_text.commentPaddingBlock",
"title": "Comment Padding", "title": "Block Comment Padding",
"description": "The number of Comment Padding Characters to add between the converted text and comment symbols.", "description": "The number of new lines to add between the converted text and comment symbols.",
"type": "number",
"default": 1
},
{
"key": "figlet_text.commentPaddingInline",
"title": "Inline Comment Padding",
"description": "The number of Comment Padding Characters to add between the converted text and comment symbols on each line.",
"type": "number", "type": "number",
"default": 4 "default": 4
}, },
{ {
"key": "figlet_text.commentPaddingStr", "key": "figlet_text.commentPaddingStr",
"title": "Comment Padding Character", "title": "Inline Comment Padding Character",
"description": "Text string to use as Comment Padding. Defaults to a single space.", "description": "Text string to use as Comment Padding. Defaults to a single space.",
"type": "string", "type": "string",
"default": " " "default": " "
@ -640,19 +647,26 @@
"title": "Margins", "title": "Margins",
"description": "Spacing between FIGlet text and your content.", "description": "Spacing between FIGlet text and your content.",
"children": [ "children": [
{
"key": "figlet_text.margins",
"title": "Enable Margins",
"description": "Toggle margin output without needing to change individual settings.",
"type": "bool",
"default": false
},
{ {
"key": "figlet_text.prependNewLines", "key": "figlet_text.prependNewLines",
"title": "Top Margin", "title": "Top Margin",
"description": "Amount of new lines to prepend to the converted text.", "description": "Amount of new lines to prepend to the converted text.",
"type": "number", "type": "number",
"default": 0 "default": 4
}, },
{ {
"key": "figlet_text.appendNewLines", "key": "figlet_text.appendNewLines",
"title": "Bottom Margin", "title": "Bottom Margin",
"description": "Amount of new lines to append to the converted text.", "description": "Amount of new lines to append to the converted text. The curser will be placed on the line after the appended lines.",
"type": "number", "type": "number",
"default": 0 "default": 2
} }
] ]
} }