microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.48k stars 29.36k forks source link

[folding] Don't expand when clicking on space after collapsed line #53886

Closed tommai78101 closed 4 years ago

tommai78101 commented 6 years ago

Steps to Reproduce:

  1. Do either one of these steps:
    • Copy the following code in a blank document that VS Code supports code folding in.
    • Create a JavaScript document, and save it as "foo.js" anywhere.
  2. Copy the following code in (or create whatever code you can be syntactically correct in, and it has to have at least 5 lines of codes):
    function foo() {
    var create1 = document.querySelector("div");
    var create2 = document.querySelector("div");
    var create3 = document.querySelector("div");
    var create4 = document.querySelector("div");
    var create5 = document.querySelector("div");
    var create6 = document.querySelector("div");
    var create7 = document.querySelector("div");
    var create8 = document.querySelector("div");
    var create9 = document.querySelector("div");
    var create10 = document.querySelector("div");
    var create11 = document.querySelector("div");
    var create12 = document.querySelector("div");
    var create13 = document.querySelector("div");
    var create14 = document.querySelector("div");
    var create15 = document.querySelector("div");
    var create16 = document.querySelector("div");
    var create17 = document.querySelector("div");
    var create18 = document.querySelector("div");
    //... 
    }
  3. Fold the code function, foo, so it is folded like so: image
  4. Click outside of Visual Studio Code, so Visual Studio Code is inactive (out-of-focus).
  5. Click on the right side of the left bracket on the line, foo() {, in Visual Studio Code. (Basically, clicking on the empty space, so the line indicator is highlighting the beginning of the code-folded line and the text cursor is at the end of the line).
  6. Observe that foo gets expanded upon first click, when the correct behavior should be the operating system switching context to Visual Studio Code, and consume the mouse click event without doing anything else.

Here's a GIF in action:

gif

If we have a list of code-folded functions, and all the user wanted to do was to go back to Visual Studio Code and scroll the document up/down, the user may inadvertently unfold the code, and it would annoy the user to re-fold the code back before continuing to scroll.

Does this issue occur when all extensions are disabled?: Yes

tommai78101 commented 6 years ago

What?

aeschli commented 6 years ago

The current implemented behavior is that when you click after collapsed line, it's range is expanded (regardless whether the VSCode window was inactive or active).

Keeping the issue open to see if others have the same request. If not I'd rather stick with the current behavior. When you activate a window, yo always have to check where you click, as the action below is executed.

tommai78101 commented 6 years ago

@aeschli I see, so it's an intended design choice. I thought it was a bug, because I didn't see this occurring in Visual Studio 2017, and I am pretty used to the behavior where collapsed codes aren't expanding as is in Visual Studio 2017.

Just curious. Was there ever the intention for Visual Studio Code to stay consistent with Visual Studio 2017 in some/most of the places?

aeschli commented 6 years ago

Just curious. Was there ever the intention for Visual Studio Code to stay consistent with Visual Studio 2017 in some/most of the places?

VSCode is free to evolve and innovate and also takes inspiration from other editors. In the end, we listen to the user feedback. If more users feel as you do (by adding 👍 to the description), we're happy to change to current behavior.

tommai78101 commented 6 years ago

@aeschli Would it be possible to keep the behavior of this feature, but don't let VS Code listen to the mouse click event when inactive?

aeschli commented 6 years ago

@tommai78101 I looked into that but it's not so easy to detect and I believe it would be the only place where we have such a special treatment.

tommai78101 commented 6 years ago

Ah ok. The way you edited the title of the issue, made me want to ask if not doing the behavior while VS Code is inactive is possible. But I guess it's a lot harder.

Thanks.

filipgoc commented 6 years ago

This also bothers me. I would definitely prefer a toggle to disable this behavior!

rebornix commented 6 years ago

@aeschli not sure if it will help but just FYI, I restricted the drag and drop event to only be triggered when clicking on text but not whitespace area after the line https://github.com/microsoft/vscode/blob/master/src/vs/editor/browser/controller/mouseHandler.ts#L356 . The problem ppl described here is somewhat the same.

Lovecircle commented 6 years ago

Please change this or give an option to "unfold code on double-click" for example. I cannot say how many times I accidentally unfolded blocks of code by simply clicking on what appeared to be just an empty space in the editor - very annoying.

footurist commented 6 years ago

Does anyone have a work-around for this? This is a little annoying if you want to keep your hands on the keyboard as much as possible while coding. Not possible with this setting, because folds will expand if I move across them with the cursorMove command.

aeschli commented 6 years ago

@Footurist Cursor move is not related to clicking. Please file a issue and explain what command exactly you are using.

p8128n commented 6 years ago

This also frustrates me. I would prefer to explicitly unfold or click the little +/- button. I don't want it to unfold when I click at the end of a folded line.

Rawalanche commented 5 years ago

Hi, another vote from me. This behavior is extremely frustrating. When you fold any function in MSVS, then everything still feels solid and comfortable. But when you fold anything in VSCode, you immediately start to feel like a EOD unit member, having to be very, VERY careful where you click. It's never a good thing to introduce any behavior that requires user to feel uneasy and careful.

simonvomeyser commented 5 years ago

It's also a reason for me to not use folding that much because i mostly move my cursor up and down with the keyboard... moving it over a folded region expands that region

An option flag for that would be awesome! Keep up the good work tough 👍

4ekki commented 5 years ago

Another vote from me for keeping the block folded when clicking on the empty space in the end of the line and unfold only on explicitly clicking 'plus' or '...' icons. When you have something like this and you want to focus the window, big chances that you occasionally expand something folded. image

HanggiAnggono commented 5 years ago

Another vote from me, also the folded region will open if text search found a match inside the folded region.

Actually i found out that, if you use vscode vim, you can use vim.foldfix in your settings and set it to true and it worked for me

robomalo commented 4 years ago

+1 Auto expanding drives me nutty.

JOJ0 commented 4 years ago

It's also a reason for me to not use folding that much because i mostly move my cursor up and down with the keyboard... moving it over a folded region expands that region

An option flag for that would be awesome! Keep up the good work tough 👍

Exactely my problem. Why unfold when I just want to move my cursor up in the code. I had the thing collapsed for a reason ;-) Making this configurable would be perfect.

Thanks for a great editor though!!!

aeschli commented 4 years ago

Due to many requests I've change the behaviour that clicking in the empty space no longer expands.

gkarapeev commented 4 years ago

Due to many requests I've change the behaviour that clicking in the empty space no longer expands.

NOOOOO.

gkarapeev commented 4 years ago

Is there a way to opt out of that change? I find it frustrating having to click such a small target with my mouse. It's a well explained situation in UX (Fitt's Law)!

tommai78101 commented 4 years ago

@gkarapeev In VSCode 1.42.1, there's a feature where you're able to auto-fold / auto-expand code blocks using Shift + Mouse Click. You can click on the highlighted code line with this mouse shortcut, and the code blocks will fold / unfold. Not sure if left mouse button or right mouse button, but it's definitely Primary Mouse Click button.

This new feature supersedes the "empty space code folding".

aeschli commented 4 years ago

I will make it configurable: #88522