diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 58e84e4f..ed8cb87d 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 cfd2d5e9..fee1a578 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, props){ + if(_.isFunction(val)) return val(props); 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)); }, renderSnippets : function(snippets){ return _.map(snippets, (snippet)=>{ diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx index d127bfdd..2b5685e4 100644 --- a/shared/naturalcrit/codeEditor/codeEditor.jsx +++ b/shared/naturalcrit/codeEditor/codeEditor.jsx @@ -176,7 +176,7 @@ const CodeEditor = createClass({ indent : function () { const cm = this.codeMirror; - if (cm.somethingSelected()) { + if(cm.somethingSelected()) { cm.execCommand('indentMore'); } else { cm.execCommand('insertSoftTab'); diff --git a/themes/Legacy/5ePHB/snippets/tableOfContents.gen.js b/themes/Legacy/5ePHB/snippets/tableOfContents.gen.js index 4082ac4e..40d64af2 100644 --- a/themes/Legacy/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/Legacy/5ePHB/snippets/tableOfContents.gen.js @@ -47,8 +47,8 @@ const getTOC = (pages)=>{ return res; }; -module.exports = function(brew){ - const pages = brew.text.split('\\page'); +module.exports = function(props){ + const pages = props.brew.text.split('\\page'); const TOC = getTOC(pages); const markdown = _.reduce(TOC, (r, g1, idx1)=>{ r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`); diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index dba4ad8d..53bb6d3d 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -19,16 +19,6 @@ module.exports = [ icon : 'fas fa-pencil-alt', view : 'text', snippets : [ - { - name : 'Page Number', - icon : 'fas fa-bookmark', - gen : '{{pageNumber 1}}\n{{footnote PART 1 | SECTION NAME}}\n\n' - }, - { - name : 'Auto-incrementing Page Number', - icon : 'fas fa-sort-numeric-down', - gen : '{{pageNumber,auto}}\n{{footnote PART 1 | SECTION NAME}}\n\n' - }, { name : 'Table of Contents', icon : 'fas fa-book', diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 1c52d5cf..44605c05 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -48,8 +48,8 @@ const getTOC = (pages)=>{ return res; }; -module.exports = function(brew){ - const pages = brew.text.split('\\page'); +module.exports = function(props){ + const pages = props.brew.text.split('\\page'); const TOC = getTOC(pages); const markdown = _.reduce(TOC, (r, g1, idx1)=>{ if(g1.title !== null) { diff --git a/themes/V3/Blank/snippets.js b/themes/V3/Blank/snippets.js index 9d64496c..72372c29 100644 --- a/themes/V3/Blank/snippets.js +++ b/themes/V3/Blank/snippets.js @@ -2,6 +2,7 @@ const WatercolorGen = require('./snippets/watercolor.gen.js'); const ImageMaskGen = require('./snippets/imageMask.gen.js'); +const FooterGen = require('./snippets/footer.gen.js'); const dedent = require('dedent-tabs').default; module.exports = [ @@ -21,6 +22,53 @@ module.exports = [ icon : 'fas fa-file-alt', gen : '\n\\page\n' }, + { + name : 'Page Number', + icon : 'fas fa-bookmark', + gen : '{{pageNumber 1}}\n' + }, + { + name : 'Auto-incrementing Page Number', + icon : 'fas fa-sort-numeric-down', + gen : '{{pageNumber,auto}}\n' + }, + { + name : 'Footer', + icon : 'fas fa-shoe-prints', + gen : FooterGen.createFooterFunc(), + subsnippets : [ + { + name : 'Footer from H1', + icon : 'fas fa-dice-one', + gen : FooterGen.createFooterFunc(1) + }, + { + name : 'Footer from H2', + icon : 'fas fa-dice-two', + gen : FooterGen.createFooterFunc(2) + }, + { + name : 'Footer from H3', + icon : 'fas fa-dice-three', + gen : FooterGen.createFooterFunc(3) + }, + { + name : 'Footer from H4', + icon : 'fas fa-dice-four', + gen : FooterGen.createFooterFunc(4) + }, + { + name : 'Footer from H5', + icon : 'fas fa-dice-five', + gen : FooterGen.createFooterFunc(5) + }, + { + name : 'Footer from H6', + icon : 'fas fa-dice-six', + gen : FooterGen.createFooterFunc(6) + } + ] + }, { name : 'Vertical Spacing', icon : 'fas fa-arrows-alt-v', diff --git a/themes/V3/Blank/snippets/footer.gen.js b/themes/V3/Blank/snippets/footer.gen.js new file mode 100644 index 00000000..6583cd06 --- /dev/null +++ b/themes/V3/Blank/snippets/footer.gen.js @@ -0,0 +1,17 @@ +const Markdown = require('../../../../shared/naturalcrit/markdown.js'); + +module.exports = { + createFooterFunc : function(headerSize=1){ + return (props)=>{ + const cursorPos = props.cursorPos; + + const markdownText = props.brew.text.split('\n').slice(0, cursorPos.line).join('\n'); + const markdownTokens = Markdown.marked.lexer(markdownText); + const headerToken = markdownTokens.findLast((lexerToken)=>{ return lexerToken.type === 'heading' && lexerToken.depth === headerSize; }); + const headerText = headerToken?.tokens.map((token)=>{ return token.text; }).join(''); + const outputText = headerText || 'PART 1 | SECTION NAME'; + + return `\n{{footnote ${outputText}}}\n`; + }; + } +}; \ No newline at end of file