Skip to content

Expand selection functionality issues #4795

Closed

Description

@arktas79513
  • VSCode Version: 0.10.11
  • OS Version: Windows 10

Steps to Reproduce:

  1. Create statement which assigns some value to nested property like scope.vm.renderSettings = {};
  2. Put cursor into renderSettings
  3. Execute command editor.action.smartSelect.grow

Expected behavior:
renderSettings part would be selected
exp

Current behavior:
the whole left part of statement selected with tabs.
2

Also would be nice to see the fix with smart grow, when editor.action.smartSelect.grow executed in series.

Activity

  1. added
    bug
    on Mar 30, 2016
  2. jrieken commented on Apr 22, 2016

    @jrieken
    Contributor

    I was too optimistic planning this for April. The current implementation is based of token/scope information in TM grammars. The issue is that each grammar does it different, like scope from above where it seems to include the leading whitespace. We redo this with a implementation that doesn't rely on token information

  3. added
    feature-request
    on Apr 22, 2016
  4. added
    help wanted
    on May 23, 2016
  5. jrieken commented on Jul 5, 2016

    @jrieken
    Contributor

    Patrick Lienau (@rozzzly), Tobias Cudnik (@TobiaszCudnik) Since I am not as familiar with the optimal solution can you guys help out with 'how it should work?'. I guess, selector word, line?, bracket/paran-block? ...

  6. DmytroYeremieiev commented on Jul 5, 2016

    @DmytroYeremieiev

    I like the way it's implemented in https://atom.io/packages/expand-region or at Jetbrain's products like Webstorm

  7. rozzzly commented on Jul 13, 2016

    @rozzzly

    Inner-camelCase expansion would be cool.
    so let's pretend _ is the cursor, and [ ] denotes the selected region.

    ren_derSettings -> [render]Settings -> [renderSettings]

    Would it be best to have people just list out a bunch of examples, using something like the markup I just used to show the behaviour desired? Then, from those. distil the logic in regards to he AST? There's a lot of edgecases I would think, that might be easier

  8. TobiaszCudnik commented on Aug 15, 2016

    @TobiaszCudnik

    Johannes Rieken (@jrieken) The simplest solution I see is to combine the AST and word separators.

    Case-sensitive boundaries could be implemented as a word separator as well. In IntelliJ it works also for CTRL+Left/Right jumps, when active.

    I really count for this feature, as it saves a lot of time when moving code around.

  9. jrieken commented on Aug 15, 2016

    @jrieken
    Contributor

    Thanks all for the input. Note that we do not have access to the AST or any other form of syntax tree. Even token information isn't working well enough. So it's unfortunately entirely word based

  10. townivan commented on Sep 7, 2016

    @townivan

    I think improving smartSelect is a great plan. I agree with the suggestions for making smartSelect even more useful. Might I suggest that #11458 is solving for a different problem? I get the feeling that mixing its requirements in with smartSelect could further bog down smartSelect.

    In my mind, smartSelect is about being able to quickly select something nearby the cursor. Whereas #11458 is about quickly selecting everything within a bounding context.

    If smartSelect were enhanced to achieve this type of eventual selection, it would still have the downside of repeated keystrokes to achieve the "select stuff inside here" functionality.

    So they feel similar because the end result is "intelligent selection" but I suspect in-the-end they would function better as separate features. Thanks for listening. :)

  11. codefoster commented on Oct 13, 2016

    @codefoster

    The value of optimal Expand Select and Shrink Select commands is high in my opinion. I used to use ReSharper in Visual Studio and their implementation was about perfect. When I use this command, I'm usually looking to copy, replace, or delete certain code.
    As an example, if my selection is inside the name of a function definition ([] denotes my cursor location or selection)...

    myFun[]ction(){
      something.do();
    }
    

    ...it should snap first to the function name...

    [myFunction](){
      something.do();
    }
    

    ...and next to the function name with the parentheses...

    [myFunction()]{
      something.do();
    }
    

    ...and next to the entire function block...

    [myFunction(){
      something.do();
    }]
    

    If my selection is inside the function, however, I would expect the progression to look something like...

    myFunction(){
      so[]mething.do();
    }
    
    myFunction(){
      [something].do();
    }
    
    myFunction(){
      [something.do()];
    }
    
    myFunction(){
      [something.do();]
    }
    
    myFunction(){
    [  something.do();
    ]}
    
    myFunction()[{
      something.do();
    }]
    
    [myFunction(){
      something.do();
    }]
    

    Note that my suggestion progression has rather small steps. For instance, after selecting the expression [something.do()]; it then selects the statement [something.do();] (including the semicolon). And, in the next step, it selects the entire line. If there were multiple lines in that block, then I would suggest yet another step where it selects the entire contents of the block (before selecting the entire block including the curly braces). I prefer this more granular stepping because it's not an inconvenience to hit the left/right arrows to grow/shrink and get exactly what you want.

  12. tony-garcia commented on Nov 1, 2016

    @tony-garcia

    Just wanted to add that it would be great for this to work with python code, where code blocks aren't delineated by brackets or parentheses, but tabs (currently, once it you expand the selection beyond the current block in a python file, all of the code is selected). I'll second that I'd like to see it work as in the Jetbrains products. In PyCharm it works great with both python and javascript files.
    I have no problem with the way it currently works in JS files with VSCode.

  13. 32 remaining items

  14. Maxhodges commented on Feb 10, 2019

    @Maxhodges

    yes, that's what I just tested. It was a miserable failure. I think the authors of this feature don't share the same vision. The way Webstorm has implemented this feature it makes it an extremely useful productivity enhancement; in vscode it's a 2-year-running exercise in frustration and disappointment.

  15. KamasamaK commented on Feb 12, 2019

    @KamasamaK

    Max Hodges (@Maxhodges) Can you please be more specific on what is lacking? This is still a work in progress, so specific feedback would probably be helpful in shaping how it ends up. This could especially be the case if, as you say, the vision differs.

  16. ThiefMaster commented on Feb 12, 2019

    @ThiefMaster

    The behavior in the various JetBrains IDEs is excellent in my opinion. As an example, here's the behavior for each selection increment ([] indicating the caret/selection):

    return moment(value[type], 'YYYY-M[]M-DD');
    return moment(value[type], 'YYYY-[MM]-DD');
    return moment(value[type], '[YYYY-MM-DD]');
    return moment(value[type], ['YYYY-MM-DD']);
    return moment([value[type], 'YYYY-MM-DD']);
    return moment[(value[type], 'YYYY-MM-DD')];
    return [moment(value[type], 'YYYY-MM-DD')];
    [return moment(value[type], 'YYYY-MM-DD');]

    Like this I can step through parts I might want to change easily - and even select logical blocks (e.g. dash-separated groups) inside strings easily.

  17. KamasamaK commented on Feb 12, 2019

    @KamasamaK

    Adrian (@ThiefMaster) Thanks! Something like that is not at odds with their vision and would be easily implemented with the new API. There was apparently an issue according to #64004 where the token information was not sufficient for the default provider to work like that for strings (or function calls), but the API can be used per language so it can be smarter. The issue is simply that it has not yet been implemented for that language.

  18. dziamid commented on Feb 14, 2019

    @dziamid

    I find JSX expansion to be too eager:

    2019-02-14 at 16 12
    Notice how it grows from <Foo /> straight to <div />, while I'd expect it to grow <Foo/> > <Link/> > <div/>

    Another frustration for me is attributes selection, there's currently no way to select attribute and/or all attributes of the tag:

    2019-02-14 at 16 16

    Here it grows from href to <Link />, while I'd prefer href > href="/about" > all tag attributes > <Link />

  19. bartocc commented on Feb 14, 2019

    @bartocc

    As far as I'm concerned, I can't expand the selection for text inside javascript quotes.
    It goes beyond the quotes…

    expand 1

  20. kifirkin commented on Feb 14, 2019

    @kifirkin

    I find JSX expansion to be too eager:

    2019-02-14 at 16 12
    Notice how it grows from <Foo /> straight to <div />, while I'd expect it to grow <Foo/> > <Link/> > <div/>

    Another frustration for me is attributes selection, there's currently no way to select attribute and/or all attributes of the tag:

    2019-02-14 at 16 16

    Here it grows from href to <Link />, while I'd prefer href > href="/about" > all tag attributes > <Link />

    Use editor.emmet.action.balanceOut instead.

  21. KamasamaK commented on Feb 14, 2019

    @KamasamaK

    While it might be possible for the default provider to be improved further, it would be best to rely on language-specific selection which will probably be adopted after the API is finalized during the current iteration. Language-specific issues should then have their own Issues so that the maintainers of their respective language extensions can address them.

  22. Frazer commented on Mar 2, 2019

    @Frazer

    It also doesn't work with script tags or style tags in html. It just treats it as an HTML element and selects thewhole tag, rather than the closest block.

  23. anied commented on Mar 9, 2019

    @anied

    Are you looking for contributors on this issue? Also, will the resolution deal specifically with multi-cursor support of the feature? I noted that 40516 was closed as a dupe of this issue, but I don't see anything regarding multi-cursor noted here.

  24. KamasamaK commented on Mar 9, 2019

    @KamasamaK

    Alexander Nied (@anied) The API (which was delayed) does support multiple cursors. It takes a Position[] for this purpose and returns a SelectionRange[][] which are the selection ranges for their respective input positions. I just tested with the default provider and could not reproduce losing the multiple cursors. Perhaps you could provide a more specific example where this happens.

  25. anied commented on Mar 9, 2019

    @anied

    KamasamaK - Certainly, thanks for taking the time to look into this. Here is my VSCode version info:

    VSCode Info

    I just checked for updates and found none.

    Consider the following code selection:

    const username = new MDCTextField(document.querySelector('.username'));
    const password = new MDCTextField(document.querySelector('.password'));
    
    new MDCRipple(document.querySelector('.cancel'));
    new MDCRipple(document.querySelector('.next'));

    Now I can select the '. from ('.username') and leverage Selection > Add Next Occurrence three times to get four cursors, one in each string in the arg to querySelector. However, if I now use Selection > Expand Selection, rather than selecting all four strings in their entirety I lose all additional cursors, and only '.username' is selected.

    So, as far as I understand it, there remains here a bug in which expanding selection loses multi-cursor context, but perhaps I am misunderstanding or trying to execute this incorrectly.

    Thanks for taking the time to review this.

  26. jrieken commented on Apr 3, 2019

    @jrieken
    Contributor

    Closing this as we have finalised the extension API for VS Code 1.33 (planned to ship this week). Remaining work is tracked here: https://github.com/Microsoft/vscode/labels/smart-select. Please file new issues for more feedback. Thanks & Happy Coding!

  27. locked as resolved and limited conversation to collaborators on Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

editor-commandsfeature-requestsmart-select

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions