diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index f157e6107..6048af6b0 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -167,7 +167,7 @@ const SnippetGroup = createClass({ }, handleSnippetClick : function(e, snippet){ e.stopPropagation(); - this.props.onSnippetClick(execute(snippet.gen, this.props.brew, { ...snippet.params, cursorPos: this.props.cursorPos })); + this.props.onSnippetClick(execute(snippet.gen, this.props)); }, renderSnippets : function(snippets){ return _.map(snippets, (snippet)=>{ diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index 8031efece..e91e1f0ad 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -33,43 +33,37 @@ module.exports = [ { name : 'Footer', icon : 'fas fa-shoe-prints', - gen : FooterGen.createFooter, + gen : FooterGen.createFooterFunc(), subsnippets : [ { - name : 'Footer from H1', - icon : 'fas fa-dice-one', - gen : FooterGen.createFooter, - params : { headerSize: 1 } + name : 'Footer from H1', + icon : 'fas fa-dice-one', + gen : FooterGen.createFooterFunc(1) }, { - name : 'Footer from H2', - icon : 'fas fa-dice-two', - gen : FooterGen.createFooter, - params : { headerSize: 2 } + name : 'Footer from H2', + icon : 'fas fa-dice-two', + gen : FooterGen.createFooterFunc(2) }, { - name : 'Footer from H3', - icon : 'fas fa-dice-three', - gen : FooterGen.createFooter, - params : { headerSize: 3 } + name : 'Footer from H3', + icon : 'fas fa-dice-three', + gen : FooterGen.createFooterFunc(3) }, { - name : 'Footer from H4', - icon : 'fas fa-dice-four', - gen : FooterGen.createFooter, - params : { headerSize: 4 } + name : 'Footer from H4', + icon : 'fas fa-dice-four', + gen : FooterGen.createFooterFunc(4) }, { - name : 'Footer from H5', - icon : 'fas fa-dice-five', - gen : FooterGen.createFooter, - params : { headerSize: 5 } + name : 'Footer from H5', + icon : 'fas fa-dice-five', + gen : FooterGen.createFooterFunc(5) }, { - name : 'Footer from H6', - icon : 'fas fa-dice-six', - gen : FooterGen.createFooter, - params : { headerSize: 6 } + name : 'Footer from H6', + icon : 'fas fa-dice-six', + gen : FooterGen.createFooterFunc(6) } ] }, diff --git a/themes/V3/5ePHB/snippets/footer.gen.js b/themes/V3/5ePHB/snippets/footer.gen.js index 59c736836..6da003cb9 100644 --- a/themes/V3/5ePHB/snippets/footer.gen.js +++ b/themes/V3/5ePHB/snippets/footer.gen.js @@ -1,18 +1,19 @@ module.exports = { - createFooter : function(brew, params){ - const cursorPos = params.cursorPos; - const headerSize = params.headerSize || 1; + createFooterFunc : function(headerSize=1){ + return (props)=>{ + const cursorPos = props.cursorPos; - let header=''; - while (header.length < headerSize) { - header = header.concat('#'); - } - header = header.concat(' '); + let header=''; + while (header.length < headerSize) { + header = header.concat('#'); + } + header = header.concat(' '); - const textArray = brew.text.split('\n').slice(0, cursorPos.line).reverse(); - const textArrayFilter = textArray.filter((line)=>{ return line.slice(0, header.length) == header; }); - const text = textArrayFilter[0]?.slice(header.length) || 'PART 1 | SECTION NAME'; + const textArray = props.brew.text.split('\n').slice(0, cursorPos.line).reverse(); + const textArrayFilter = textArray.filter((line)=>{ return line.slice(0, header.length) == header; }); + const text = textArrayFilter[0]?.slice(header.length).trim() || 'PART 1 | SECTION NAME'; - return `\n{{footnote ${text}}}\n`; + return `\n{{footnote ${text}}}\n`; + }; } }; \ No newline at end of file