0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 20:42:43 +00:00

Add code folding feature for all content within a single page

Added the gutter definitions and css for code folding. Enabling code folding in the editor was
tricky due to how CodeMirror loads its files. At the moment, the CodeMirror code-folding code has
been copied into the fold-code.js file. Additionally, that file contains the helper registration
for the Homebrewery-specific code folding function.

#629
This commit is contained in:
Charlie Humphreys
2021-11-02 22:40:17 -05:00
parent 09ca2a4fd9
commit c0b9f4488f
3 changed files with 356 additions and 2 deletions

View File

@@ -13,6 +13,10 @@ if(typeof navigator !== 'undefined'){
require('codemirror/mode/gfm/gfm.js'); //Github flavoured markdown
require('codemirror/mode/css/css.js');
require('codemirror/mode/javascript/javascript.js');
const foldCode = require('./fold-code');
foldCode.enableCodeFolding(CodeMirror);
foldCode.registerHomebreweryHelper(CodeMirror);
}
const CodeEditor = createClass({
@@ -74,8 +78,15 @@ const CodeEditor = createClass({
'Ctrl-M' : this.makeSpan,
'Cmd-M' : this.makeSpan,
'Ctrl-/' : this.makeComment,
'Cmd-/' : this.makeComment
}
'Cmd-/' : this.makeComment,
'Ctrl-,' : this.toggleCodeFolded,
'Cmd-,' : this.toggleCodeFolded
},
foldGutter : true,
foldOptions : {
rangeFinder : CodeMirror.fold.homebrewery,
},
gutters : ['CodeMirror-linenumbers', 'CodeMirror-foldgutter']
});
// Note: codeMirror passes a copy of itself in this callback. cm === this.codeMirror. Either one works.
@@ -119,6 +130,10 @@ const CodeEditor = createClass({
}
},
toggleCodeFolded : function() {
this.codeMirror.foldCode(this.codeMirror.getCursor());
},
//=-- Externally used -==//
setCursorPosition : function(line, char){
setTimeout(()=>{