Top => IntelliJ IDEA on Mac OS X
The extract variable refactoring assigns an expression to a variable, typically to improve readability.
- ⌃⇥ (Ctrl + Tab) - navigate from the project view pane to an editor pane
- ⌘↖︎ (Command + Home) or fn⌘← (Fn + Command + Left Arrow) or fn↑ (Fn + Up Arrow) - navigate to the top of the file (in editor)
- ⌥→ (Option + Right Arrow) - move forward by token while selecting
- ⌥⇧→ (Option + Shift + Right Arrow) - move forward by token
- ⌘L (Command + L) - go to line number
- ⌘F (Command + F) - find in file
- ⌘G (Command + G) - repeat the last find operation
- ⎋ (Escape) - dismiss "find" dialog
- ⌘⌥V (Command + Option + V) - open the "extract variable" dialog
- ⏎ (Return/Enter) - complete action
Keystrokes without explanations
⌃⇥
⌘↖︎ (or fn⌘←)
⌘L
11
⏎
hold ⌥
→
→
→
→
release ⌥
⌘V
↓
↓
isInternetExplorer
⏎
⌥⏎
⏎
↓
↓
↓
hold ⌥
→
→
→
release ⌥
⌘V
↓
↓
isChrome
⏎
⌥⏎
⏎
⌘X
↑
↑
↑
↑
⌘V
Walkthrough of steps with explanations
- Open the Java source file, BrowserMadness.java.
- If focus is not already in the editor pane for LongConditional.java, press ⌃⇥ (Ctrl + Tab) and select the editor pane for LongConditional.java.
- Press ⌘↖︎ (Command + Home) or fn⌘← (Fn + Command + Left Arrow) or fn↑ (Fn + Up Arrow) to navigate to the top of the file (depends on the keyboard).
- Press ⌘L (Command + L) to open the "go to line number" dialog.
- Enter line number 9.
- Press ⏎ (Return/Enter) to move the caret to the specified line number.
- Hold ⌥ (Option) and press → (Right Arrow) four times to advance to the token, browser.
- Press ⌘V to open the "extract variable" dialog.
- Press ↓ (Down Arrow) twice to select the expression that includes the contains method call.
- Overtype the default variable name, msie, with isInternetExplorer.
- Press ⏎ (Return/Enter) to complete the refactoring.
- Press ⌥⏎ (Option + Return/Enter) to open the intentions drop-down.
- Press ⏎ (Return/Enter) to accept the suggestion to "extract if".
- Press ↓ (Down Arrow) to move to the next line that contains an expression to be extracted.
- Hold ⌥ (Option) and press → (Right Arrow) three times to position the caret at the token, browser.
- Press ⌘V (Command + V) to open the "extract variable" dialog.
- Press ↓ (Down Arrow) twice to select the expression that includes the contains method call.
- Overtype the default variable name, msie, with isChrome.
- Press ⏎ (Return/Enter) to complete the refactoring.
- Press ⌘X to cut the line containing the extracted variable.
- Press ↑ (Up Arrow) to position the caret at the start of the line just below the first extracted variable declaration.
- Press ⌘V to paste the cut line at that position in the file.
To reverse the changes:
- Press ⌘Z (Command + Z) repeatedly until the changes have been reversed. Should be 30 times.