From 83ce9f2e1cfdf62c752160cfe5180362327284ac Mon Sep 17 00:00:00 2001 From: Dan Remollino Date: Thu, 23 Mar 2023 16:55:46 -0400 Subject: [PATCH] updated to v1.6.3 --- FIGlet Text.novaextension/CHANGELOG.md | 3 ++ FIGlet Text.novaextension/Scripts/main.js | 49 ++++++++++++----------- FIGlet Text.novaextension/extension.json | 2 +- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/FIGlet Text.novaextension/CHANGELOG.md b/FIGlet Text.novaextension/CHANGELOG.md index 47204f9..6e5449b 100644 --- a/FIGlet Text.novaextension/CHANGELOG.md +++ b/FIGlet Text.novaextension/CHANGELOG.md @@ -1,3 +1,6 @@ +## Version 1.6.3 +- refactored transformation workflow when outputting FIGlet converted text to the editor + ## Version 1.6.2 - fixed FIGlet converted text on indented selections with prepended or appended lines diff --git a/FIGlet Text.novaextension/Scripts/main.js b/FIGlet Text.novaextension/Scripts/main.js index 177773b..1c9c41b 100644 --- a/FIGlet Text.novaextension/Scripts/main.js +++ b/FIGlet Text.novaextension/Scripts/main.js @@ -72,61 +72,64 @@ nova.commands.register('figletTextEditor', editor => { return null } } - let prependNewLines = nova.config.get('figlet_text.prependNewLines', 'number') - let appendNewLines = nova.config.get('figlet_text.appendNewLines', 'number') + + // subtract one; will Array.prototype.join('\n') before final editor output + let prependNewLines = nova.config.get('figlet_text.prependNewLines', 'number') - 1 + let appendNewLines = nova.config.get('figlet_text.appendNewLines', 'number') - 1 let selectedRanges = editor.selectedRanges.reverse() for (let range of selectedRanges) { let text = editor.getTextInRange(range) let indentRange = new Range(editor.getLineRangeForRange(range).start, range.start) + let indentText = editor.getTextInRange(indentRange) nova.commands.invoke('figlet', figConfig, text, figletText => { - // comment each line if the option is selected - // 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') + // convert the FIGlet string to an array of strings to make it + // easier to modify line by line; order of transformations matter + let figletTextArr = figletText.split('\n') + // comment each line if the option is selected and a + // comment structure is defined for the current syntax + if (comment && getCommentChars() !== null) { // 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 - lines.map(line => { if (line.length > longestLine) longestLine = line.length }) + figletTextArr.map(line => { 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 => { + figletTextArr = figletTextArr.map(line => { let linePadding = 0 if (line.length < longestLine && (getCommentChars().end !== '')) linePadding = longestLine - line.length // 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') } // prepend/append new lines - if (prependNewLines > 0) figletText = `${'\n'.repeat(prependNewLines)}${figletText}` - if (appendNewLines > 0) figletText = `${figletText}${'\n'.repeat(appendNewLines)}` + if (prependNewLines > 0) figletTextArr = Array.of(`${'\n'.repeat(prependNewLines)}`).concat(figletTextArr) + if (appendNewLines > 0) figletTextArr = figletTextArr.concat(Array.of(`${'\n'.repeat(appendNewLines)}`)) + // indent subsequent lines after the line + // with an initial indented selection if (!indentRange.empty) { - let lines = figletText.split('\n') - let indentText = editor.getTextInRange(indentRange) - let linesIndented = lines.map((line, index) => { + figletTextArr = figletTextArr.map((line, index) => { if (index === 0) { - return `${line}`.trimEnd() + return `${line}` } else { - return `${indentText}${line}`.trimEnd() + return `${indentText}${line}` } }) - figletText = linesIndented.join('\n') } - // replace the selection with the fully final FIGlet text - editor.edit(e => { e.replace(range, figletText) }) + // convert the array of strings to a + // single string for output to editor + let figletTextStr = figletTextArr.join('\n') + + // replace the selection with the fully transformed FIGlet text + editor.edit(e => { e.replace(range, figletTextStr) }) // deselect and position the cursor editor.moveRight(1) diff --git a/FIGlet Text.novaextension/extension.json b/FIGlet Text.novaextension/extension.json index d71369b..607d7ca 100644 --- a/FIGlet Text.novaextension/extension.json +++ b/FIGlet Text.novaextension/extension.json @@ -3,7 +3,7 @@ "name": "FIGlet Text", "organization": "Dan Remollino", "description": "Convert selected text to FIGlet. Great for adding readable text to the Minimap, creating l33t text headers, and organizing files.", - "version": "1.6.2", + "version": "1.6.3", "categories": ["commands", "formatters"], "entitlements": {