mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-22 16:03:39 +01:00
Merge pull request #771 from n00o/feature/Tree-View
Add better CodeMirror folding options
This commit is contained in:
commit
c40f8e654c
@ -70,6 +70,35 @@ export default class CodeEditor extends React.Component {
|
||||
'Ctrl-F': 'findPersistent',
|
||||
Tab: function (cm) {
|
||||
cm.replaceSelection(' ', 'end');
|
||||
},
|
||||
'Ctrl-Y': 'foldAll',
|
||||
'Cmd-Y': 'foldAll',
|
||||
'Ctrl-I': 'unfoldAll',
|
||||
'Cmd-I': 'unfoldAll'
|
||||
},
|
||||
foldOptions: {
|
||||
widget: (from, to) => {
|
||||
var count = undefined;
|
||||
var internal = this.editor.getRange(from, to);
|
||||
if (this.props.mode == 'application/ld+json') {
|
||||
if (this.editor.getLine(from.line).endsWith('[')) {
|
||||
var toParse = '[' + internal + ']';
|
||||
} else var toParse = '{' + internal + '}';
|
||||
try {
|
||||
count = Object.keys(JSON.parse(toParse)).length;
|
||||
} catch (e) {}
|
||||
} else if (this.props.mode == 'application/xml') {
|
||||
var doc = new DOMParser();
|
||||
try {
|
||||
//add header element and remove prefix namespaces for DOMParser
|
||||
var dcm = doc.parseFromString(
|
||||
'<a> ' + internal.replace(/(?<=\<|<\/)\w+:/g, '') + '</a>',
|
||||
'application/xml'
|
||||
);
|
||||
count = dcm.documentElement.children.length;
|
||||
} catch (e) {}
|
||||
}
|
||||
return count ? `\u21A4${count}\u21A6` : '\u2194';
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
@ -21,6 +21,7 @@ if (!SERVER_RENDERED) {
|
||||
require('codemirror/addon/edit/matchbrackets');
|
||||
require('codemirror/addon/fold/brace-fold');
|
||||
require('codemirror/addon/fold/foldgutter');
|
||||
require('codemirror/addon/fold/xml-fold');
|
||||
require('codemirror/addon/hint/show-hint');
|
||||
require('codemirror/addon/lint/lint');
|
||||
require('codemirror/addon/mode/overlay');
|
||||
|
Loading…
Reference in New Issue
Block a user