microsoft / vscode

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

Breakpoint moves with copy line up/down action #75426

Open eyalroth opened 5 years ago

eyalroth commented 5 years ago

Version:

Steps to Reproduce:

  1. Create a new code file (of any supported language).
  2. Write a few lines of code.
  3. Place a break-point on a line.
  4. Copy the line using Copy Line Up or Copy Line Down actions.

Bug: The break-point moves with the copied line. It should stay.

Does this issue occur when all extensions are disabled? Yes

vscodebot[bot] commented 5 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

alexdima commented 4 years ago

This is as designed... The copy line down action is implemented by inserting the line text above it, so that's why the breakpoint moves. We will not reimplement the action just to accommodate this case, and it is IMHO not clearly wrong...

eyalroth commented 4 years ago

@alexandrudima This really doesn't seem to be as designed but rather a clear oversight, and for multiple reasons:

  1. It's a copy action -- not a move action -- and the normal copy+paste action doesn't move any breakpoints around. Even cutting a line doesn't move the breakpoint.
  2. The are more bugs produced by this behavior; for instance, after completing the reproduction steps described in this issue, if one deletes said line the breakpoint will move to the next (non duplicated) line instead of the original one, and if one then tries to undo these steps, the breakpoint will remain on the next line which has nothing to do with the original one.
  3. Both IntelliJ and Eclipse -- two of the most popular IDEs out there -- do not exhibit this behavior.
  4. Copying a line via the Copy Line Up/Down action is intended to create a new line which is similar to the original one. It's a means of creating new content which looks like old content. It is not meant to alter the original content, which goes for its state as well.
  5. This behavior actually goes further than just breakpoints. For instance, the bookmark of a line marked with the bookmarks extension will behave similar to how a breakpoint does, which makes no sense. Duplicating a line definitely shouldn't move the bookmark around, as it belongs to the original line which is not about to be modified (unlike the newly duplicated line).
alefragnani commented 4 years ago

I wouldn't say that keeping the breakpoint, bookmark, or any other decoration/data in the original line is correct either, because the command is Copy Line Up/Down, so users could expect that it should copy the breakpoint/bookmark/etc to the next/previous line, duplicating it.

I'm not sure if copying/cutting the entire line shouldn't bring its breakpoint/bookmarks (sometimes I hoped it should). But to this, the API should be updated to describe the original Line/Range.

IMHO, I prefer the way it works today, even with this naming conflict. The Bookmarks extension, at least, should remain this way.

hediet commented 2 years ago

I think the copy line up/down action really should also copy all break points, bookmarks and other stuff associated to the line.

Unfortunately, as far as I know, there is no generic way to (deep-) copy all the associated data. For example, the bookmark extension might have its own data structure to manage the line-associated bookmarks.


Since copying the associated data is off the table, we can still control if the original or the copy should get all the associated data.

I think there are valid arguments for both the old (original) and the new (copied) line, so this is not clearly a bug, but rather the behavior is open for discussion.

alefragnani commented 2 years ago

Yes, the Bookmarks extension has its own storage, and a custom sticky algorithm to update the Bookmark position (line) when the user changes the file.

Technically speaking, ~I guess (I'm not in front of my computer)~ (confirmed) it works this way because the Copy Line Down command, in fact, doesn't add a copy of the current line, in the next line (down). Instead, it adds the copy in the place of the current line, moving the so called current line, one line below. Doing so, the Bookmark follows the original line, going one line below, just like it does when you hit Return at the beginning of the current line.