mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 22:52:40 +00:00
Shift Footer generation to snippet
This commit is contained in:
@@ -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()}
|
||||
</div>
|
||||
|
||||
@@ -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)=>{
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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',
|
||||
|
||||
16
themes/V3/5ePHB/snippets/footer.gen.js
Normal file
16
themes/V3/5ePHB/snippets/footer.gen.js
Normal file
@@ -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`;
|
||||
};
|
||||
Reference in New Issue
Block a user