mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 20:03:03 +00:00
Shift Footer generation to snippet
This commit is contained in:
@@ -323,7 +323,8 @@ const Editor = createClass({
|
|||||||
theme={this.props.brew.theme}
|
theme={this.props.brew.theme}
|
||||||
undo={this.undo}
|
undo={this.undo}
|
||||||
redo={this.redo}
|
redo={this.redo}
|
||||||
historySize={this.historySize()} />
|
historySize={this.historySize()}
|
||||||
|
cursorPos={this.refs.codeEditor?.getCursorPosition() || {}} />
|
||||||
|
|
||||||
{this.renderEditor()}
|
{this.renderEditor()}
|
||||||
</div>
|
</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_Journal'] = require('themes/V3/Journal/snippets.js');
|
||||||
ThemeSnippets['V3_Blank'] = require('themes/V3/Blank/snippets.js');
|
ThemeSnippets['V3_Blank'] = require('themes/V3/Blank/snippets.js');
|
||||||
|
|
||||||
const execute = function(val, brew){
|
const execute = function(val, brew, params){
|
||||||
if(_.isFunction(val)) return val(brew);
|
if(_.isFunction(val)) return val(brew, params);
|
||||||
return val;
|
return val;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,7 +33,8 @@ const Snippetbar = createClass({
|
|||||||
renderer : 'legacy',
|
renderer : 'legacy',
|
||||||
undo : ()=>{},
|
undo : ()=>{},
|
||||||
redo : ()=>{},
|
redo : ()=>{},
|
||||||
historySize : ()=>{}
|
historySize : ()=>{},
|
||||||
|
cursorPos : {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -105,6 +106,7 @@ const Snippetbar = createClass({
|
|||||||
snippets={snippetGroup.snippets}
|
snippets={snippetGroup.snippets}
|
||||||
key={snippetGroup.groupName}
|
key={snippetGroup.groupName}
|
||||||
onSnippetClick={this.handleSnippetClick}
|
onSnippetClick={this.handleSnippetClick}
|
||||||
|
cursorPos={this.props.cursorPos}
|
||||||
/>;
|
/>;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -165,7 +167,7 @@ const SnippetGroup = createClass({
|
|||||||
},
|
},
|
||||||
handleSnippetClick : function(e, snippet){
|
handleSnippetClick : function(e, snippet){
|
||||||
e.stopPropagation();
|
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){
|
renderSnippets : function(snippets){
|
||||||
return _.map(snippets, (snippet)=>{
|
return _.map(snippets, (snippet)=>{
|
||||||
|
|||||||
@@ -145,20 +145,6 @@ const CodeEditor = createClass({
|
|||||||
'Shift-Cmd-Enter' : this.newColumn,
|
'Shift-Cmd-Enter' : this.newColumn,
|
||||||
'Ctrl-Enter' : this.newPage,
|
'Ctrl-Enter' : this.newPage,
|
||||||
'Cmd-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',
|
'Ctrl-F' : 'findPersistent',
|
||||||
'Cmd-F' : 'findPersistent',
|
'Cmd-F' : 'findPersistent',
|
||||||
'Shift-Enter' : 'findPersistentPrevious',
|
'Shift-Enter' : 'findPersistentPrevious',
|
||||||
@@ -259,23 +245,6 @@ const CodeEditor = createClass({
|
|||||||
this.codeMirror.replaceSelection('\n\\page\n\n', 'end');
|
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) {
|
injectText : function(injectText, overwrite=true) {
|
||||||
const cm = this.codeMirror;
|
const cm = this.codeMirror;
|
||||||
if(!overwrite) {
|
if(!overwrite) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const ClassFeatureGen = require('./snippets/classfeature.gen.js');
|
|||||||
const CoverPageGen = require('./snippets/coverpage.gen.js');
|
const CoverPageGen = require('./snippets/coverpage.gen.js');
|
||||||
const TableOfContentsGen = require('./snippets/tableOfContents.gen.js');
|
const TableOfContentsGen = require('./snippets/tableOfContents.gen.js');
|
||||||
const indexGen = require('./snippets/index.gen.js');
|
const indexGen = require('./snippets/index.gen.js');
|
||||||
|
const FooterGen = require('./snippets/footer.gen.js');
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,6 +30,11 @@ module.exports = [
|
|||||||
icon : 'fas fa-sort-numeric-down',
|
icon : 'fas fa-sort-numeric-down',
|
||||||
gen : '{{pageNumber,auto}}\n{{footnote PART 1 | SECTION NAME}}\n\n'
|
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',
|
name : 'Table of Contents',
|
||||||
icon : 'fas fa-book',
|
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