Extract Method

Extract code to a new method

Highlight the code you want to extract to a method and press ⌥⌘M (macOS), or Ctrl+Alt+M (Windows/Linux), to extract it.

Extracting code into a new method can be useful in improving the readability of your code.