“Focus On What Matters”
When working in our IDE, at times it’s easy to become overwhelmed with all the code on the screen. To better focus on what’s most important, it can be useful to hide non-essential blocks of code from our editor window.
The Code Folding shortcuts in Android Studio help us do just that.
The allow us to fold Code Blocks & Region Blocks so we can have more fine grained control over what code we are looking at in any given moment.
collapse shortcuts allow us to quickly show or hide code blocks or code regions.
expand all or
collapse all by adding
shift to the shortcuts above.
We can take an expanded block of code like this anonymous inner class
and collapse it within the IDE, using the
collapse shortcut, so it visually looks like this.
We lose the immediate view of the code, but if that code is not relevant to us in this moment, then it can actually help reduce the visual noise in our IDE.
To collapse a specific block of code, place your cursor within the block and execute the shortcut.
If you run the shortcut multiple times, the IDE may continue to collapse blocks of code in increasing scope until everything in the current file is collapse. The same logic applies when expanding code as well.
We can define custom region blocks using comments. These regions can be helpful for documenting & group related sections of code; such as the implementation of an interface.
collapse command, we can collapse the entire region so only the region label is visible within our editor.
For more on code folding, check out my latest video on YouTube