diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 58e84e4fc..ed8cb87d5 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -323,7 +323,8 @@ const Editor = createClass({ theme={this.props.brew.theme} undo={this.undo} redo={this.redo} - historySize={this.historySize()} /> + historySize={this.historySize()} + cursorPos={this.refs.codeEditor?.getCursorPosition() || {}} /> {this.renderEditor()} diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index cfd2d5e91..adba5ff59 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -15,8 +15,8 @@ ThemeSnippets['V3_5eDMG'] = require('themes/V3/5eDMG/snippets.js'); ThemeSnippets['V3_Journal'] = require('themes/V3/Journal/snippets.js'); ThemeSnippets['V3_Blank'] = require('themes/V3/Blank/snippets.js'); -const execute = function(val, brew){ - if(_.isFunction(val)) return val(brew); +const execute = function(val, brew, params){ + if(_.isFunction(val)) return val(brew, params); return val; }; @@ -33,7 +33,8 @@ const Snippetbar = createClass({ renderer : 'legacy', undo : ()=>{}, redo : ()=>{}, - historySize : ()=>{} + historySize : ()=>{}, + cursorPos : {} }; }, @@ -105,6 +106,7 @@ const Snippetbar = createClass({ snippets={snippetGroup.snippets} key={snippetGroup.groupName} onSnippetClick={this.handleSnippetClick} + cursorPos={this.props.cursorPos} />; }); }, @@ -165,7 +167,7 @@ const SnippetGroup = createClass({ }, handleSnippetClick : function(e, snippet){ e.stopPropagation(); - this.props.onSnippetClick(execute(snippet.gen, this.props.brew)); + this.props.onSnippetClick(execute(snippet.gen, this.props.brew, { cursorPos: this.props.cursorPos })); }, renderSnippets : function(snippets){ return _.map(snippets, (snippet)=>{ diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index 9a9c39ee9..2b5685e49 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -145,20 +145,6 @@ const CodeEditor = createClass({ 'Shift-Cmd-Enter' : this.newColumn, 'Ctrl-Enter' : this.newPage, 'Cmd-Enter' : this.newPage, - 'Ctrl-Alt-Enter' : ()=>this.newPageWithFooter(), - 'Cmd-Alt-Enter' : ()=>this.newPageWithFooter(), - 'Ctrl-Alt-1' : ()=>this.newPageWithFooter(1), - 'Cmd-Alt-1' : ()=>this.newPageWithFooter(1), - 'Ctrl-Alt-2' : ()=>this.newPageWithFooter(2), - 'Cmd-Alt-2' : ()=>this.newPageWithFooter(2), - 'Ctrl-Alt-3' : ()=>this.newPageWithFooter(3), - 'Cmd-Alt-3' : ()=>this.newPageWithFooter(3), - 'Ctrl-Alt-4' : ()=>this.newPageWithFooter(4), - 'Cmd-Alt-4' : ()=>this.newPageWithFooter(4), - 'Ctrl-Alt-5' : ()=>this.newPageWithFooter(5), - 'Cmd-Alt-5' : ()=>this.newPageWithFooter(5), - 'Ctrl-Alt-6' : ()=>this.newPageWithFooter(6), - 'Cmd-Alt-6' : ()=>this.newPageWithFooter(6), 'Ctrl-F' : 'findPersistent', 'Cmd-F' : 'findPersistent', 'Shift-Enter' : 'findPersistentPrevious', @@ -259,23 +245,6 @@ const CodeEditor = createClass({ this.codeMirror.replaceSelection('\n\\page\n\n', 'end'); }, - newPageWithFooter : function(headerSize=1) { - let header=''; - while (header.length < headerSize) { - header = header.concat('#'); - } - header = header.concat(' '); - - const cursorPos = this.codeMirror.getCursor(); - - const cmText = this.codeMirror.getValue(); - const cmTextArray = cmText.split('\n').slice(0, cursorPos.line).reverse(); - const cmTextArrayFilter = cmTextArray.filter((line)=>{ return line.slice(0, header.length) == header; }); - const text = cmTextArrayFilter[0].slice(header.length) || 'PART 1 | SECTION NAME'; - - this.codeMirror.replaceSelection(`\n{{footnote ${text}}}\n{{pageNumber,auto}}\n\n\\page\n\n`, 'end'); - }, - injectText : function(injectText, overwrite=true) { const cm = this.codeMirror; if(!overwrite) { diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index dba4ad8d5..2a9b26b68 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -8,6 +8,7 @@ const ClassFeatureGen = require('./snippets/classfeature.gen.js'); const CoverPageGen = require('./snippets/coverpage.gen.js'); const TableOfContentsGen = require('./snippets/tableOfContents.gen.js'); const indexGen = require('./snippets/index.gen.js'); +const FooterGen = require('./snippets/footer.gen.js'); const dedent = require('dedent-tabs').default; @@ -29,6 +30,11 @@ module.exports = [ icon : 'fas fa-sort-numeric-down', gen : '{{pageNumber,auto}}\n{{footnote PART 1 | SECTION NAME}}\n\n' }, + { + name : 'Footer', + icon : 'fas fa-sort-numeric-down', + gen : FooterGen + }, { name : 'Table of Contents', icon : 'fas fa-book', diff --git a/themes/V3/5ePHB/snippets/footer.gen.js b/themes/V3/5ePHB/snippets/footer.gen.js new file mode 100644 index 000000000..7a5d64fdb --- /dev/null +++ b/themes/V3/5ePHB/snippets/footer.gen.js @@ -0,0 +1,16 @@ +module.exports = function(brew, params){ + const cursorPos = params.cursorPos; + const headerSize = params.headerSize || 1; + + 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'; + + return `\n{{footnote ${text}}}\n`; +}; \ No newline at end of file