diff --git a/FIGlet Text.novaextension/CHANGELOG.md b/FIGlet Text.novaextension/CHANGELOG.md index 7cef63e..613e069 100644 --- a/FIGlet Text.novaextension/CHANGELOG.md +++ b/FIGlet Text.novaextension/CHANGELOG.md @@ -1,3 +1,6 @@ +## Version 1.8.1 +- fixed duplicate text on every output line when indented selection was preceded by non-whitespace characters + ## Version 1.8 - fixed missing font links - added BDF and C64 font sets diff --git a/FIGlet Text.novaextension/README.md b/FIGlet Text.novaextension/README.md index 46f05ed..07c6b06 100644 --- a/FIGlet Text.novaextension/README.md +++ b/FIGlet Text.novaextension/README.md @@ -16,8 +16,5 @@ FIGlet Text requires [FIGlet](http://www.figlet.org) to be installed locally. Th # How to Use FIGlet Text FIGlet Text will add a 'Convert Selection to FIGlet' menu item to the Editor menu. Make one or more selections in the editor and run the command. -# Known Issues -- selected text with non-whitespace characters preceding the selection will output the text on each line - # Planned Features - borders diff --git a/FIGlet Text.novaextension/Scripts/main.js b/FIGlet Text.novaextension/Scripts/main.js index b7e9b59..aa8c343 100644 --- a/FIGlet Text.novaextension/Scripts/main.js +++ b/FIGlet Text.novaextension/Scripts/main.js @@ -92,9 +92,16 @@ nova.commands.register('figletTextEditor', editor => { let selectedRanges = editor.selectedRanges.reverse() for (let range of selectedRanges) { + // the text to be processed let text = editor.getTextInRange(range) + + // get the range of the start of the line with selection to the start of + // the selection and calculate the amount of characters for indentation let indentRange = new Range(editor.getLineRangeForRange(range).start, range.start) - let indentText = editor.getTextInRange(indentRange) + let indentText = (() => { + let charCount = editor.getTextInRange(indentRange).length + return ' '.repeat(charCount) + })() nova.commands.invoke('figlet', figConfig, text, figletText => { // convert the FIGlet string to an array of strings to make it @@ -128,11 +135,8 @@ nova.commands.register('figletTextEditor', editor => { // the line with the selection was indented if (!indentRange.empty) { figletTextArr = figletTextArr.map((line, index) => { - if (index === 0) { - return `${line}` - } else { - return `${indentText}${line}` - } + if (index === 0) { return `${line}` } + return `${indentText}${line}` }) }