diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx
index 82435cacb..3794ac7c8 100644
--- a/client/homebrew/editor/editor.jsx
+++ b/client/homebrew/editor/editor.jsx
@@ -60,6 +60,10 @@ const Editor = createClass({
window.removeEventListener('resize', this.updateEditorSize);
},
+ componentDidUpdate : function() {
+ this.highlightCustomMarkdown();
+ },
+
updateEditorSize : function() {
if(this.refs.codeEditor) {
let paneHeight = this.refs.main.parentNode.clientHeight;
@@ -177,25 +181,44 @@ const Editor = createClass({
this.refs.codeEditor?.updateSize();
},
+ //Called by CodeEditor after document switch, so Snippetbar can refresh UndoHistory
+ rerenderParent : function (){
+ this.forceUpdate();
+ },
+
renderEditor : function(){
if(this.isText()){
- return ;
+ return <>
+
+ >;
}
if(this.isStyle()){
- return ;
+ return <>
+
+ >;
}
if(this.isMeta()){
- return ;
+ return <>
+
+
+ >;
}
},
@@ -212,7 +235,6 @@ const Editor = createClass({
},
render : function(){
- this.highlightCustomMarkdown();
return (
+ historySize={this.historySize()} />
{this.renderEditor()}
diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx
index 84888b3d0..a294bbb26 100644
--- a/client/homebrew/editor/snippetbar/snippetbar.jsx
+++ b/client/homebrew/editor/snippetbar/snippetbar.jsx
@@ -63,11 +63,11 @@ const Snippetbar = createClass({
if(!this.props.showEditButtons) return;
return
-
-
diff --git a/shared/naturalcrit/codeEditor/codeEditor.jsx b/shared/naturalcrit/codeEditor/codeEditor.jsx
index 6fe189890..7a0b70fde 100644
--- a/shared/naturalcrit/codeEditor/codeEditor.jsx
+++ b/shared/naturalcrit/codeEditor/codeEditor.jsx
@@ -25,25 +25,44 @@ const CodeEditor = createClass({
};
},
+ getInitialState : function() {
+ return {
+ docs : {}
+ };
+ },
+
componentDidMount : function() {
this.buildEditor();
+ this.codeMirror.setValue(this.props.value);
+ this.codeMirror.clearHistory();
},
componentDidUpdate : function(prevProps) {
- if(prevProps.language !== this.props.language){ //rebuild editor when switching tabs
- this.buildEditor();
- }
- if(this.codeMirror && this.codeMirror.getValue() != this.props.value) { //update editor contents if brew.text is changed from outside
+ if(prevProps.view !== this.props.view){ //view changed; swap documents
+ let newDoc;
+
+ if(!this.state.docs[this.props.view]) {
+ newDoc = CodeMirror.Doc(this.props.value, this.props.language);
+ } else {
+ newDoc = this.state.docs[this.props.view];
+ }
+
+ const oldDoc = { [prevProps.view]: this.codeMirror.swapDoc(newDoc) };
+
+ this.setState((prevState)=>({
+ docs : _.merge({}, prevState.docs, oldDoc)
+ }));
+
+ this.props.rerenderParent();
+ } else if(this.codeMirror?.getValue() != this.props.value) { //update editor contents if brew.text is changed from outside
this.codeMirror.setValue(this.props.value);
}
},
buildEditor : function() {
this.codeMirror = CodeMirror(this.refs.editor, {
- value : this.props.value,
lineNumbers : true,
lineWrapping : this.props.wrap,
- mode : this.props.language, //TODO: CSS MODE DOESN'T SEEM TO LOAD PROPERLY
indentWithTabs : true,
tabSize : 2,
historyEventDelay : 250,
@@ -125,7 +144,7 @@ const CodeEditor = createClass({
//----------------------//
render : function(){
- return
;
+ return
;
}
});