Vscode: Expand selection and shrink selection in HTML

Created on 6 Jan 2016  路  26Comments  路  Source: microsoft/vscode

Continuing from here: #495

Expand Select and shrink select work OK in typescript, json and JS. It seems it's not implemented for HTML.

feature-request

Most helpful comment

+1 two years on and this feature still sucks. it skips many levels of hierarchy in HTML, going from current link to entire file instead of climbing nested levels of tags. IntelliJ (Webstorm) does this right.

All 26 comments

@jrieken ping

Seconding this. It would be useful for both selecting content inside HTML element and selecting attribute values/names.

And extending selection hierarchically up the element tree.

+1

Let me upvote this as strongly as possible. HTML is so highly structured, and in such a variety of ways, that selection of specific tags and strings is really crucial to working quickly and well. Without this feature, editing becomes not just unhandy, but too error-prone for my purposes. It would transform the utility of the editor if the same selection abilities were present in HTML as in other languages.

If anyone is looking for a reference Resharper for Visual Studio does this really well.

IntelliJ is also quite at this, but Visual Studio code is quite lacking in this. I'm commenting on this because expand selection is my most used shortcut in IntelliJ, and I tried the same in Visual Studio Code, just to find out it's basically not working. I'm hoping someone might find the time to improve this feature.

Just in case it helps someone, I link to my answer to this topic from Stackoverflow a while ago: http://stackoverflow.com/questions/40949929/how-do-i-select-the-insides-of-div-in-visual-studio-code/40971959#40971959

It's not perfect, but with this keybinding setup, you basically use Emmet's selection / balancing commands in HTML files and standard shrink / grow for everything else. Works for me, the only caveat is that you can't "shrink back" to the selected attributes.

Very helpful, kaiwood - thanks.

In case if anyone out there is still looking for this feature, see expand-region extension. It might help at the moment.

+1 two years on and this feature still sucks. it skips many levels of hierarchy in HTML, going from current link to entire file instead of climbing nested levels of tags. IntelliJ (Webstorm) does this right.

Any updates on this? Expand selection is terrible. In an HTML doc, the selection goes from one word, one line, to entire document. As @Maxhodges said, IntelliJ IDEs do this right and it is one of the main reasons I continue to use their products instead of VS Code. Come on people, figure it out.

nice!

can I pay money to someone to make this happen?

I documented the difference between webstorm and vscode expand select here in animated gifs

https://github.com/Microsoft/vscode/issues/4795#issuecomment-346622659
seems comment maybe be folded (expand hidden comments)

@Maxhodges @scottbickell use emmet's balance in/out instead for html/jsx.
as mentioned in https://github.com/Microsoft/vscode/issues/1808#issuecomment-267956024
(balance in is still broken.)

2018-05-13_16-02-43

Try it from the command menu.

You can add shortcut for it as required.

  {
    "key": "shift+alt+right",
    "command": "editor.emmet.action.balanceOut",
    "when": "editorTextFocus && editorLangId == html && editorHasSelection"
  },
  {
    "key": "shift+alt+left",
    "command": "editor.emmet.action.balanceIn",
    "when": "editorTextFocus && editorLangId == html && editorHasSelection"
  },
  {
    "key": "shift+alt+right",
    "command": "editor.emmet.action.balanceOut",
    "when": "editorTextFocus && editorLangId == javascriptreact && editorHasSelection"
  },
  {
    "key": "shift+alt+left",
    "command": "editor.emmet.action.balanceIn",
    "when": "editorTextFocus && editorLangId == javascriptreact && editorHasSelection"
  },
  {
    "key": "shift+alt+right",
    "command": "editor.emmet.action.balanceOut",
    "when": "editorTextFocus && editorLangId == typescriptreact && editorHasSelection"
  },
  {
    "key": "shift+alt+left",
    "command": "editor.emmet.action.balanceIn",
    "when": "editorTextFocus && editorLangId == typescriptreact && editorHasSelection"
  },

@anantoghosh that's kind of rubbish for me. Try on something with quotes. It should do word, the string inside quotes, then string with quotes
and when retracting it resolves to another string entirely

wrnjxhqsdvs9

I have created an issue for this https://github.com/Microsoft/vscode/issues/49777
let's see if we make any progress.
Balance out selection should be improved as well. Maybe create a new issue for that.

Currently, you can run "Emmet: Balance (ourward)" or "Emmet: Balance (inward)" command for this functionality.

There's plan to support Expand Selection for all languages, and we'll do it for HTML/CSS using emmet.

You can track the new feature in: https://github.com/Microsoft/vscode/issues/65925

sorry @octref but you misunderstand. Emmet outward falls very short of a good solution. Can you jump on a conference call so I can demo what you are failing to understand? I've documented this over and over. Emmet only considers tags, not text elements. In Webstorm it will expand to the current word, then words within quotes, then include the quotes, then the tag. Emmet just grabs everything in the tag. Often we use this to grab a word, or a string with or without quotes.

here's how Webstorm does it. (as I've already documented elsewhere over a year ago, but clearly you're not paying attention to specifics.

Users shall be able to successively select expanding logical blocks of code so that you can easily select any expression in the code by placing the caret somewhere inside it and pressing a shortcut.

Extends selection to the next containing node (for example, an expression, a paired tag, an entire conditional block, a method body, a class, a group of vararg arguments, etc.)

In plain text, with the caret anywhere in a word, the selection would extend to to the word, the sentence, the paragraph

Shrink does the opposite.

web33175778-27f4b1a0-d0a0-11e7-9d8f-de9fdf0e7228

@octref try this with Emmet Balance in/out! It fails miserably. Please don't forget to reopen the issue when you are done.
wb33175780-28f81182-d0a0-11e7-96b7-21324684dd7e

Thank you @Maxhodges for investing time into this. I too feel strongly about good syntax aware expand/shrink selection, but it seems mostly ignored brushed off by people who have not experienced the joy of using it.

@Maxhodges JavaScript/TypeScript balance outward will be provided by TypeScript language service. See https://github.com/Microsoft/vscode/issues/4795.

I'll start with Emmet and improve it later to have more granularity.

This will be available in tomorrow's insiders:

html-selection

Feel free to open new issues if something doesn't work as expected.

Fantastic news!

looking forward to it!

Was this page helpful?
0 / 5 - 0 ratings