Skip to content

Expand Selection in function and arrow function skips body block #37030

@alexilyaev

Description

@alexilyaev

TS Template added by @mjbvz

TypeScript Version: 3.8.2

Search Terms

  • expand selection
  • selectionRange

Issue Type: Feature Request (maybe Bug)

Reproduce

Given these code examples (javascript or javascriptreact), run Expand Selection a few times:

const func = () => {
  |<-- put caret here
};
// or...
const func = () => {|<-- put caret here

};
// or...
function func(params) {
  |<-- put caret here
}

Actual

Expand Selection skips the body of the function and goes straight to selecting the whole function.

exapnd-selection-arrow-func

Expected

Should be able to select the function body when using Expand Selection, regardless of where I started inside the function.

In WebStorm it works as expected:

webstorm-expand-func

I find myself updating the body of an arrow function dozens of times a day, usually to inline the return expression as an implicit return.
Of course there are extensions and ESLint rules that can help with that, but Expand Selection should respect the function body block regardless.

Update: More examples

const func = () => {
  // some comment
  const one = 1;
};
  1. Placing caret to the left of // some:
    • Expand Selection just once will select the whole arrow function (from () to the closing }).
  2. Placing caret to the left of const:
    • Expand Selection actually works as expected, after 4 times, only the body of the arrow function is selected (although it doesn't select it including the {}, but that's not so bad).

Here's the example where I first encountered this issue:

const func = () => {
  return someFunc();
};
  1. Select and Cut someFunc(); (caret will be to the right of return at this point)
  2. Expand Selection > results in selecting the whole function (from () to the closing })
  3. If I first move the caret to the left of return, then Expand Selection works as expected.

System Details

VS Code version: Code - Insiders 1.40.0-insider (c58aaab, 2019-10-22T05:25:41.549Z)
VS Code version: Code 1.42.1 (c47d83b293181d9be64f27ff093689e8e7aed054, 2020-02-11T14:44:27.652Z)
OS version: Darwin x64 18.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions