Skip to content

Instantly share code, notes, and snippets.

@matomesc
Last active May 11, 2017 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matomesc/d5a5302ddcbf61e849a8fa3bf7dc0f97 to your computer and use it in GitHub Desktop.
Save matomesc/d5a5302ddcbf61e849a8fa3bf7dc0f97 to your computer and use it in GitHub Desktop.
Folds/unfolds all Firebase rules that are direct children of the "rules" node in the rules editor
// Sometimes the rules editor lags when many rules are expanded.
// This snippet collapses all the rules that are direct children of the root "rules" node.
// Rules editor can be found at: https://console.firebase.google.com/project/{PROJECT_ID}/database/rules.
// Get CodeMirror instance
const editor = $('.CodeMirror')[0].CodeMirror;
// Find direct children of "rules" node and fold them.
editor.eachLine((l) => {
// Perhaps a better way is to check the parent of `l` to handle different indentations.
const isDirectChild = l.text.indexOf(' "') === 0 && l.text.indexOf('{') !== -1;
if (!isDirectChild) return;
const num = editor.getLineNumber(l);
editor.foldCode(num);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment