atom/bookmarks

Copying a bookmarked line creates fake bookmarks

Closed this issue ยท 14 comments

Copying and pasting a bookmarked line sometimes (I wasn't able to determine what's making it happen) creates a fake bookmark on the pasted line.
Then, pressing F2 (jump key) from anywhere in the file selects both lines.

capture du 2016-06-13 10-53-19

And pressing F1 (toggle bookmark key) on one of the lines sometimes removes both bookmarks, and sometimes doesn't do anything (it might depend on which one is the "fake" bookmark).

Details:
OS: Ubuntu 4.2.0-38-generic
Atom version: 1.8.0
bookmarks version: 0.39.0

Just wanted to say that the blue symbols in the left gutter can be misleading: a bookmark is not just a line, it's a text selection, that can span multiple lines. You can create a multi-line bookmark which will behave the way you describe (F2 selects both lines, F2 on one of these lines removes both, etc...)

What you describe about the copy/paste creating a second bookmark seems to be a bug, though. But I couldn't reproduce it.

Here's a recreation of the fake bookmarks:

fake_bookmarks_upon_pasting

It's enough just to paste multiple rows onto a bookmarked line. At least multiple bookmarks are not real, it's enough to toggle the bookmark and they go away. What's annoying is bug #69 โ€” jump to bookmark.

I'm on Bookmarks 0.42@Atom 1.11.2@Mac.

You don't even have to paste to create the bookmarks. Just keep typing after a bookmarked line creates them for me.

bookmarked lines

@Ben3eeE Yes that too, and it has something to do with the beginning of the line. Check this out:

false_bookmarks

Actually it only creates the bookmark when adding newlines in the beginning of the line if you had the cursor in the beginning of the line when adding the bookmark.

For longer lines this is what happens:

bookmarked lines v2

Also, thank you for the gifs to help reproduce @revelt. Much appreciated ๐Ÿ™‡โ€โ™‚๏ธ

@Ben3eeE I don't seem to have the exact same behaviour here:

atombug

@pdonias Like Linus said, it's dependent where you created the original bookmark.
Here I create bookmark after "1", and only there it duplicates:

location_dependent

Looks like bookmarks are based on certain invisible character which gets messed up on editing its vicinity.

@revelt OK, my bad. I have the same behaviour.

Actually there is a small difference in the gif by @pdonias ๐Ÿ˜‰. If you add characters after adding the bookmark all of these characters creates the duplicated bookmark on newline.

bookmarked lines v3

+1 I was able to reproduce it. Adding characters on the same line after bookmarking is also a bug factor.

As @solendil said, a bookmark is a range.

@markerLayer.markBufferRange(range, {invalidate: 'surround'})

So it has a head and a tail (head and tail can be at the same position) and when we add content in between those 2 bounds (head and tail included), it will make the bookmarked range bigger.
Every line containing a part of the range will have the blue icon.

Wouldn't it make more sense if a bookmark was just a line?

  • inserting a carriage return in the middle of the line would keep the bookmark on the first half
  • deleting the line (all the characters and the carriage return) would destroy the bookmark
  • copying the line would not copy the bookmark
  • jumping to a bookmark would always place the cursor to the beginning of the line

jumping to a bookmark would always place the cursor to the beginning of the line

But Sublime manages to jump exactly where the bookmark was placed! Often code spans multiple lines, and jumping to exact spot would be enormously helpful.

OK, I understand. So if you want to match Sublime's behaviour, some changes need to be done:

  • only the first line of the range should have the icon
  • allow multiple bookmarks on the same line (which means a bookmark should be destroyed only if the cursor is inside the range when pressing the toggle key, not just on the same line)
  • if a bookmark is at a single position (ie head = tail), adding content at this position should not make it a "ranged" bookmark. The bookmark should follow the cursor instead.

There are probably more, but I think this would be enough to fix the weird behaviour we have right now :)