Last active
May 11, 2017 17:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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