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

Expand Selection to Function (Java​Script)

by gillibrand ALL

Expands the current selection to the enclosing JavaScript function.

Details

Installs

  • Total 11K
  • Win 7K
  • Mac 3K
  • Linux 2K
Nov 21 Nov 20 Nov 19 Nov 18 Nov 17 Nov 16 Nov 15 Nov 14 Nov 13 Nov 12 Nov 11 Nov 10 Nov 9 Nov 8 Nov 7 Nov 6 Nov 5 Nov 4 Nov 3 Nov 2 Nov 1 Oct 31 Oct 30 Oct 29 Oct 28 Oct 27 Oct 26 Oct 25 Oct 24 Oct 23 Oct 22 Oct 21 Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7
Windows 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0 1 0 1
Mac 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 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.0.4 (6/4/2024)

  • Support comment between function name and opening brace.
  • Switched to semantic version numbers for future updates.

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.