ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Expand Selection to Function (Java​Script)

by gillibrand ST2/ST3

Expands the current selection to the enclosing JavaScript function.

Details

  • 2015.01.04.08.08.01
  • github.​com
  • github.​com
  • 3 years ago
  • 1 hour ago
  • 6 years ago

Installs

  • Total 9K
  • Win 5K
  • OS X 2K
  • Linux 1K
Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7 Mar 6
Windows 2 3 2 2 0 1 2 2 3 2 1 5 2 0 3 1 3 1 6 0 2 3 3 1 3 2 0 1 2 0 4 1 0 0 0 2 3 3 1 4 2 2 2 2 1 4
OS X 0 1 0 0 1 0 0 1 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 2 0 0 0 0 0 0 1 1 2 0 1 0 0 0 0 0 0 0 1 0 0 1
Linux 1 0 0 0 0 0 0 1 2 3 0 1 2 1 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 2 0 0 1 0 0 0 1 0

Readme

Source
raw.​githubusercontent.​com

Expand Selection to Function (JavaScript)

A command to expand the current selection to the enclosing JavaScript function. This works with named and anonymous functions.

Each time this command runs it will expand farther out. For anonymous functions, the local variable or property name that refers to the function can also be selected. For example, expanding from the alert line below will first select the anonymous function (as represented with the «angle quotes»):

var foobar = «function() {
    alert('Example!')
}»;

Running it again will then select the variable and trailing semicolon:

«var foobar = function() {
    alert('Example!')
};»

After expanding, you can restore the last selection, which will contract the selection back to what it was before. You can expand several times then restore several times to return to your original selection, which is useful for quickly visualizing the scope of deeply nested functions.

Usage

Both commands are available in the Selection menu and bound to the following keyboard shortcuts on Windows and Linux:

Expand Selection to Function (JavaScript)   Alt+Up
Restore Last Selection                      Alt+Down

Or similarly, on OS X:

Expand Selection to Function (JavaScript)   ⌥↑ (Option+Up)
Restore Last Selection                      ⌥↓ (Option+Down)

Compatibility

Compatible with both Sublime Text 2 and Sublime Text 3.

Version History

1/3/2015

  • Support for ES 6 fat arrow functions (with braces) courtesy of Cheng Lou.
  • Fixed typos in the keyboard shortcuts in this README.

The Past

  • Initial version.