vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Expand selection and shrink selection in HTML

Open oliverjanik opened this issue 10 years ago • 26 comments

Continuing from here: #495

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

oliverjanik avatar Jan 06 '16 04:01 oliverjanik

@jrieken ping

joaomoreno avatar Jan 06 '16 09:01 joaomoreno

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

esko avatar Jan 26 '16 12:01 esko

And extending selection hierarchically up the element tree.

oliverjanik avatar Jan 27 '16 03:01 oliverjanik

+1

sergi-io avatar Feb 26 '16 22:02 sergi-io

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.

JimNewkirk avatar Apr 14 '16 21:04 JimNewkirk

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

oliverjanik avatar Apr 15 '16 02:04 oliverjanik

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.

bodiam avatar Dec 19 '16 12:12 bodiam

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.

kaiwood avatar Dec 19 '16 12:12 kaiwood

Very helpful, kaiwood - thanks.

JimNewkirk avatar Dec 21 '16 20:12 JimNewkirk

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

mtunad avatar Jun 04 '17 13:06 mtunad

+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.

Maxhodges avatar Nov 11 '17 18:11 Maxhodges

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.

scottbickell avatar Mar 29 '18 15:03 scottbickell

nice!

tientm-lumin avatar May 08 '18 03:05 tientm-lumin

can I pay money to someone to make this happen?

Maxhodges avatar May 08 '18 04:05 Maxhodges

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 avatar May 08 '18 04:05 Maxhodges

@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 avatar May 13 '18 10:05 anantoghosh

@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

Maxhodges avatar May 14 '18 05:05 Maxhodges

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.

anantoghosh avatar May 14 '18 09:05 anantoghosh

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

octref avatar Jan 02 '19 21:01 octref

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

Maxhodges avatar Jan 03 '19 02:01 Maxhodges