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
  • 45 minutes ago
  • 5 years ago

Installs

  • Total 9K
  • Win 5K
  • OS X 2K
  • Linux 1K
Jan 23 Jan 22 Jan 21 Jan 20 Jan 19 Jan 18 Jan 17 Jan 16 Jan 15 Jan 14 Jan 13 Jan 12 Jan 11 Jan 10 Jan 9 Jan 8 Jan 7 Jan 6 Jan 5 Jan 4 Jan 3 Jan 2 Jan 1 Dec 31 Dec 30 Dec 29 Dec 28 Dec 27 Dec 26 Dec 25 Dec 24 Dec 23 Dec 22 Dec 21 Dec 20 Dec 19 Dec 18 Dec 17 Dec 16 Dec 15 Dec 14 Dec 13 Dec 12 Dec 11 Dec 10 Dec 9
Windows 4 2 1 1 1 4 0 2 1 1 3 0 2 2 2 2 1 1 3 3 4 3 0 2 0 1 1 0 1 3 1 1 1 1 5 4 1 0 1 3 3 2 0 1 2 3
OS X 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 2 0 0 0 1 1 1 0 0 0 0 2 0 1 1 0 0 0 0 1 0 2 0 0
Linux 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 2 0 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.