diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index fce116fcc..5586e9391 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -248,6 +248,7 @@ const Editor = createClass({ onInject={this.handleInject} showEditButtons={this.props.showEditButtons} renderer={this.props.renderer} + theme={this.props.brew.theme} undo={this.undo} redo={this.redo} historySize={this.historySize()} /> diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index 33687b528..8538c28a2 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -6,12 +6,12 @@ const cx = require('classnames'); //Import all themes -const ThemesSettings = require('themes/themes.json'); +const Themes = require('themes/themes.json'); -const Themes = {}; -Themes['Legacy_5ePHB'] = require('themes/Legacy/5ePHB/snippets.js'); -Themes['V3_5ePHB'] = require('themes/V3/5ePHB/snippets.js'); -Themes['V3_5eDMG'] = require('themes/V3/5eDMG/snippets.js'); +const ThemeSnippets = {}; +ThemeSnippets['Legacy_5ePHB'] = require('themes/Legacy/5ePHB/snippets.js'); +ThemeSnippets['V3_5ePHB'] = require('themes/V3/5ePHB/snippets.js'); +ThemeSnippets['V3_5eDMG'] = require('themes/V3/5eDMG/snippets.js'); const execute = function(val, brew){ if(_.isFunction(val)) return val(brew); @@ -45,7 +45,7 @@ const Snippetbar = createClass({ componentDidMount : async function() { const rendererPath = this.props.renderer == 'V3' ? 'V3' : 'Legacy'; const themePath = this.props.theme ?? '5ePHB'; - let snippets = Themes[`${rendererPath}_${themePath}`]; + let snippets = ThemeSnippets[`${rendererPath}_${themePath}`]; snippets = this.compileSnippets(rendererPath, themePath, snippets); this.setState({ snippets : snippets @@ -53,10 +53,11 @@ const Snippetbar = createClass({ }, componentDidUpdate : async function(prevProps) { - if(prevProps.renderer != this.props.renderer) { + if(prevProps.renderer != this.props.renderer || prevProps.theme != this.props.theme) { const rendererPath = this.props.renderer == 'V3' ? 'V3' : 'Legacy'; const themePath = this.props.theme ?? '5ePHB'; - let snippets = Themes[`${rendererPath}_${themePath}`]; + console.log({ThemeSnippets:ThemeSnippets}); + let snippets = ThemeSnippets[`${rendererPath}_${themePath}`]; snippets = this.compileSnippets(rendererPath, themePath, snippets); this.setState({ snippets : snippets @@ -64,17 +65,23 @@ const Snippetbar = createClass({ } }, + mergeCustomizer : function(objValue, srcValue) { +   if (_.isArray(objValue)) { + let result = _.unionBy(srcValue, objValue, 'name'); // Join snippets together, with preference for the current theme over the base theme + return _.filter(result, 'gen'); //Only keep snippets with a 'gen' property. +   } + }, + compileSnippets : function(rendererPath, themePath, snippets) { let compiledSnippets = snippets; - console.log(ThemesSettings); - console.log("rendererpath:"); - console.log(rendererPath); - console.log("themepath"); - console.log(themePath); - const baseThemePath = ThemesSettings[rendererPath][themePath].baseTheme; + const baseThemePath = Themes[rendererPath][themePath].baseTheme; + console.log({baseSnippets:ThemeSnippets[`${rendererPath}_${baseThemePath}`]}); + console.log({themeSnippets:compiledSnippets}); + if(baseThemePath) { - compiledSnippets = _.merge(compiledSnippets, Themes[`${rendererPath}_${baseThemePath}`]); - this.compileSnippets(rendererPath, themePath, compiledSnippets); + compiledSnippets = _.mergeWith([], ThemeSnippets[`${rendererPath}_${baseThemePath}`], compiledSnippets, this.mergeCustomizer); + console.log({compiledSnippets:compiledSnippets}); + //this.compileSnippets(rendererPath, themePath, compiledSnippets); (for nested baseThemes) } return compiledSnippets; }, diff --git a/themes/V3/5eDMG/snippets.js b/themes/V3/5eDMG/snippets.js index cd0911c1b..9640928e9 100644 --- a/themes/V3/5eDMG/snippets.js +++ b/themes/V3/5eDMG/snippets.js @@ -21,7 +21,7 @@ module.exports = [ { name : 'Column Break', icon : 'fas fa-columns', - gen : '\n\\column\n' + gen : false }, { name : 'New Page',