mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-02 10:42:44 +00:00
Merge branch 'code-folding' into codemirror-tweaks
This commit is contained in:
@@ -108,7 +108,7 @@ const Editor = createClass({
|
|||||||
const codeMirror = this.refs.codeEditor.codeMirror;
|
const codeMirror = this.refs.codeEditor.codeMirror;
|
||||||
|
|
||||||
//reset custom text styles
|
//reset custom text styles
|
||||||
const customHighlights = codeMirror.getAllMarks().filter((mark)=>!mark.__isFold);
|
const customHighlights = codeMirror.getAllMarks().filter((mark)=>!mark.__isFold); //Don't undo code folding
|
||||||
for (let i=0;i<customHighlights.length;i++) customHighlights[i].clear();
|
for (let i=0;i<customHighlights.length;i++) customHighlights[i].clear();
|
||||||
|
|
||||||
const lineNumbers = _.reduce(this.props.brew.text.split('\n'), (r, line, lineNumber)=>{
|
const lineNumbers = _.reduce(this.props.brew.text.split('\n'), (r, line, lineNumber)=>{
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ const CodeEditor = createClass({
|
|||||||
},
|
},
|
||||||
foldGutter : true,
|
foldGutter : true,
|
||||||
foldOptions : {
|
foldOptions : {
|
||||||
|
scanUp : true,
|
||||||
rangeFinder : CodeMirror.fold.homebrewery,
|
rangeFinder : CodeMirror.fold.homebrewery,
|
||||||
widget : (from, to)=>{
|
widget : (from, to)=>{
|
||||||
let text = '';
|
let text = '';
|
||||||
@@ -110,13 +111,16 @@ const CodeEditor = createClass({
|
|||||||
const maxLength = 50;
|
const maxLength = 50;
|
||||||
while (currentLine <= to.line && text.length <= maxLength) {
|
while (currentLine <= to.line && text.length <= maxLength) {
|
||||||
text += this.codeMirror.getLine(currentLine);
|
text += this.codeMirror.getLine(currentLine);
|
||||||
if(currentLine < to.line) {
|
if(currentLine < to.line)
|
||||||
text += ' ';
|
text += ' ';
|
||||||
}
|
|
||||||
currentLine += 1;
|
currentLine += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `\u21A4${text.substr(0, maxLength)}\u21A6`;
|
text = text.trim();
|
||||||
|
if(text.length > maxLength)
|
||||||
|
text = `${text.substr(0, maxLength)}...`;
|
||||||
|
|
||||||
|
return `\u21A4 ${text} \u21A6`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
gutters : ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
|
gutters : ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
.codeEditor{
|
.codeEditor{
|
||||||
.CodeMirror-foldmarker {
|
.CodeMirror-foldmarker {
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
|
text-shadow: none;
|
||||||
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cm-trailingspace {
|
.cm-trailingspace {
|
||||||
|
|||||||
@@ -9,12 +9,8 @@ module.exports = {
|
|||||||
let end = start.line, nextLine = cm.getLine(start.line + 1);
|
let end = start.line, nextLine = cm.getLine(start.line + 1);
|
||||||
|
|
||||||
while (end < lastLineNo) {
|
while (end < lastLineNo) {
|
||||||
if(nextLine.match(matcher)) {
|
if(nextLine.match(matcher))
|
||||||
return {
|
break;
|
||||||
from : CodeMirror.Pos(start.line, 0),
|
|
||||||
to : CodeMirror.Pos(end, cm.getLine(end).length)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
++end;
|
++end;
|
||||||
nextLine = cm.getLine(end + 1);
|
nextLine = cm.getLine(end + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user