0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-08 20:23:39 +00:00

Merge pull request #1913 from jeddai/codemirror-tweak-updates

Revert some codemirror tweaks, disable code folding in style tab
This commit is contained in:
Trevor Buckner
2021-12-21 22:48:37 -05:00
committed by GitHub
3 changed files with 59 additions and 47 deletions

View File

@@ -208,6 +208,7 @@ const Editor = createClass({
view={this.state.view} view={this.state.view}
value={this.props.brew.style ?? DEFAULT_STYLE_TEXT} value={this.props.brew.style ?? DEFAULT_STYLE_TEXT}
onChange={this.props.onStyleChange} onChange={this.props.onStyleChange}
enableFolding={false}
rerenderParent={this.rerenderParent} /> rerenderParent={this.rerenderParent} />
</>; </>;
} }

View File

@@ -27,9 +27,9 @@ if(typeof navigator !== 'undefined'){
require('codemirror/addon/search/matchesonscrollbar.js'); require('codemirror/addon/search/matchesonscrollbar.js');
require('codemirror/addon/dialog/dialog.js'); require('codemirror/addon/dialog/dialog.js');
//Trailing space highlighting //Trailing space highlighting
require('codemirror/addon/edit/trailingspace.js'); // require('codemirror/addon/edit/trailingspace.js');
//Active line highlighting //Active line highlighting
require('codemirror/addon/selection/active-line.js'); // require('codemirror/addon/selection/active-line.js');
//Auto-closing //Auto-closing
//XML code folding is a requirement of the auto-closing tag feature and is not enabled //XML code folding is a requirement of the auto-closing tag feature and is not enabled
require('codemirror/addon/fold/xml-fold.js'); require('codemirror/addon/fold/xml-fold.js');
@@ -42,10 +42,11 @@ if(typeof navigator !== 'undefined'){
const CodeEditor = createClass({ const CodeEditor = createClass({
getDefaultProps : function() { getDefaultProps : function() {
return { return {
language : '', language : '',
value : '', value : '',
wrap : true, wrap : true,
onChange : ()=>{} onChange : ()=>{},
enableFolding : true
}; };
}, },
@@ -81,6 +82,12 @@ const CodeEditor = createClass({
} else if(this.codeMirror?.getValue() != this.props.value) { //update editor contents if brew.text is changed from outside } else if(this.codeMirror?.getValue() != this.props.value) { //update editor contents if brew.text is changed from outside
this.codeMirror.setValue(this.props.value); this.codeMirror.setValue(this.props.value);
} }
if(this.props.enableFolding) {
this.codeMirror.setOption('foldOptions', this.foldOptions(this.codeMirror));
} else {
this.codeMirror.setOption('foldOptions', false);
}
}, },
buildEditor : function() { buildEditor : function() {
@@ -139,39 +146,19 @@ const CodeEditor = createClass({
'Ctrl-]' : this.unfoldAllCode, 'Ctrl-]' : this.unfoldAllCode,
'Cmd-]' : this.unfoldAllCode 'Cmd-]' : this.unfoldAllCode
}, },
foldGutter : true, foldGutter : true,
foldOptions : { foldOptions : this.foldOptions(this.codeMirror),
scanUp : true, gutters : ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
rangeFinder : CodeMirror.fold.homebrewery, autoCloseTags : true,
widget : (from, to)=>{ styleActiveLine : true,
let text = ''; showTrailingSpace : false,
let currentLine = from.line; // specialChars : / /,
const maxLength = 50; // specialCharPlaceholder : function(char) {
while (currentLine <= to.line && text.length <= maxLength) { // const el = document.createElement('span');
text += this.codeMirror.getLine(currentLine); // el.className = 'cm-space';
if(currentLine < to.line) // el.innerHTML = ' ';
text += ' '; // return el;
currentLine += 1; // }
}
text = text.trim();
if(text.length > maxLength)
text = `${text.substr(0, maxLength)}...`;
return `\u21A4 ${text} \u21A6`;
}
},
gutters : ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
autoCloseTags : true,
styleActiveLine : true,
showTrailingSpace : true,
specialChars : / /,
specialCharPlaceholder : function(char) {
const el = document.createElement('span');
el.className = 'cm-space';
el.innerHTML = ' ';
return el;
}
}); });
closeTag.autoCloseCurlyBraces(CodeMirror, this.codeMirror); closeTag.autoCloseCurlyBraces(CodeMirror, this.codeMirror);
@@ -355,6 +342,30 @@ const CodeEditor = createClass({
historySize : function(){ historySize : function(){
return this.codeMirror.doc.historySize(); return this.codeMirror.doc.historySize();
}, },
foldOptions : function(cm){
return {
scanUp : true,
rangeFinder : CodeMirror.fold.homebrewery,
widget : (from, to)=>{
let text = '';
let currentLine = from.line;
const maxLength = 50;
while (currentLine <= to.line && text.length <= maxLength) {
text += this.codeMirror.getLine(currentLine);
if(currentLine < to.line)
text += ' ';
currentLine += 1;
}
text = text.trim();
if(text.length > maxLength)
text = `${text.substr(0, maxLength)}...`;
return `\u21A4 ${text} \u21A6`;
}
};
},
//----------------------// //----------------------//
render : function(){ render : function(){

View File

@@ -10,13 +10,13 @@
font-weight: 600; font-weight: 600;
} }
.cm-tab { //.cm-tab {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAMCAQAAACOs/baAAAARUlEQVR4nGJgIAG8JkXxUAcCtDWemcGR1lY4MvgzCEKY7jSBjgxBDAG09UEQzAe0AMwMHrSOAwEGRtpaMIwAAAAA//8DAG4ID9EKs6YqAAAAAElFTkSuQmCC) no-repeat right; // background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAMCAQAAACOs/baAAAARUlEQVR4nGJgIAG8JkXxUAcCtDWemcGR1lY4MvgzCEKY7jSBjgxBDAG09UEQzAe0AMwMHrSOAwEGRtpaMIwAAAAA//8DAG4ID9EKs6YqAAAAAElFTkSuQmCC) no-repeat right;
} //}
.cm-trailingspace { //.cm-trailingspace {
.cm-space { // .cm-space {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAQAgMAAABW5NbuAAAACVBMVEVHcEwAAAAAAAAWawmTAAAAA3RSTlMAPBJ6PMxpAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAFUlEQVQI12NgwACcCQysASAEZGAAACMuAX06aCQUAAAAAElFTkSuQmCC) no-repeat right; // background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAQAgMAAABW5NbuAAAACVBMVEVHcEwAAAAAAAAWawmTAAAAA3RSTlMAPBJ6PMxpAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAFUlEQVQI12NgwACcCQysASAEZGAAACMuAX06aCQUAAAAAElFTkSuQmCC) no-repeat right;
} // }
} //}
} }