Home Download Buy Blog Forum Support

[ST3] Bug: toggle_bookmark does not work sometimes

[ST3] Bug: toggle_bookmark does not work sometimes

Postby robertcollier4 on Sat Mar 02, 2013 1:07 pm

When there are a large number of bookmarks - toggle_bookmark does not work on some of the bookmarks. On others it does.

Steps to reproduce:
1. Load a large file such as "Key Bindings - Default"
2. In the console enter (this will result in many matches which is what we want):
RegionsResult = sublime.active_window().active_view().find_all("{", sublime.IGNORECASE | sublime.LITERAL)
3. In the console enter (this will add bookmarks to all the matches):
sublime.active_window().active_view().add_regions("bookmarks", RegionsResult, "bookmarks", "bookmark", sublime.HIDDEN | sublime.PERSISTENT)
4. Try to do "toggle_bookmark" on the lines with bookmarks - as you will see on some of them will work, on some of them will not.

However, if I do the same thing with a smaller file in which it doesn't have that many results, it works fine. So it seems to be a problem when there are a large number of bookmarks set - then "toggle_bookmark" stops working on some of the lines.
robertcollier4
 
Posts: 153
Joined: Sun Feb 24, 2013 5:37 pm

Re: [ST3] Bug: toggle_bookmark does not work sometimes

Postby planet on Thu Mar 07, 2013 2:01 pm

I don't think there is a bug, i think it's by design. You can have multiple bookmarks per line. You have to jump to each individual bookmark and toggle it off at that position. Personally I would prefer to have only one bookmark per line, because I can't see the exact bookmark positions. I would like to delete that bookmark with the cursor somewhere in that line (without having to jump to the exact bookmark position in that line).
planet
 
Posts: 24
Joined: Fri Feb 17, 2012 12:30 pm

Re: [ST3] Bug: toggle_bookmark does not work sometimes

Postby bizoo on Thu Mar 07, 2013 3:17 pm

planet wrote:I don't think there is a bug, i think it's by design. You can have multiple bookmarks per line. You have to jump to each individual bookmark and toggle it off at that position. Personally I would prefer to have only one bookmark per line, because I can't see the exact bookmark positions. I would like to delete that bookmark with the cursor somewhere in that line (without having to jump to the exact bookmark position in that line).

I think that it's relatively easy to write a plugin that replace the current behavior with the one you want.
Something like this plugin: https://github.com/artkorsun/DelphiStyleBookmarks
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: [ST3] Bug: toggle_bookmark does not work sometimes

Postby planet on Thu Mar 07, 2013 3:56 pm

Thanks bizoo!

It can even be done by a macro:

Bookmark Line.sublime-macro

Code: Select all
[
   {
      "args": null,
      "command": "set_mark"
   },
   {
      "args":
      {
         "to": "line"
      },
      "command": "expand_selection"
   },
   {
      "args": null,
      "command": "toggle_bookmark"
   },
   {
      "args":
      {
         "by": "characters",
         "forward": false
      },
      "command": "move"
   },
   {
      "args": null,
      "command": "select_to_mark"
   },
   {
      "args":
      {
         "by": "characters",
         "forward": true
      },
      "command": "move"
   },
   {
      "args":
      {
         "name": "mark"
      },
      "command": "clear_bookmarks"
   }
]


Update: Macro keeps Cursor Position.
planet
 
Posts: 24
Joined: Fri Feb 17, 2012 12:30 pm

Re: [ST3] Bug: toggle_bookmark does not work sometimes

Postby bizoo on Thu Mar 07, 2013 4:19 pm

Clever, I never think to use macro instead of plugin.
But Python is so fun in ST :D
bizoo
 
Posts: 859
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: [ST3] Bug: toggle_bookmark does not work sometimes

Postby robertcollier4 on Thu Mar 07, 2013 5:20 pm

planet wrote:I don't think there is a bug, i think it's by design. You can have multiple bookmarks per line. You have to jump to each individual bookmark and toggle it off at that position. Personally I would prefer to have only one bookmark per line, because I can't see the exact bookmark positions. I would like to delete that bookmark with the cursor somewhere in that line (without having to jump to the exact bookmark position in that line).

Oh! Thank you for the explanation for why this is happening. You are right it is because there is more than one bookmark on that line. Here is a command called toggle_bookmark_wholeline that gives desired functionality. It will find and remove all bookmarks that intersect with the line contained by the keyboard caret/first selection. This command is now included in mark_from_findpanel as a complete solution for processing (marking/unmarking) search results one-by-one via bookmarks.

Code: Select all
class ToggleBookmarkWholelineCommand(sublime_plugin.TextCommand):
   def run(self, edit):
      caretLine = self.view.line(self.view.sel()[0])
      oldBookmarks = self.view.get_regions("bookmarks")

      newBookmarks = []
      bookmarkFoundOnCaretLine = False

      for thisbookmark in oldBookmarks:
         # if thisbookmark.intersects(caretLine):
         if ( (thisbookmark.begin() >= caretLine.begin()) and (thisbookmark.begin() <= caretLine.end()) or
              (thisbookmark.end() >= caretLine.begin()) and (thisbookmark.end() <= caretLine.end()) ):
            bookmarkFoundOnCaretLine = True
         else:
            newBookmarks.append(thisbookmark)

      if not bookmarkFoundOnCaretLine:
            newBookmarks.append(self.view.sel()[0])

      sublime.active_window().active_view().add_regions("bookmarks", newBookmarks, "bookmarks", "bookmark", sublime.HIDDEN | sublime.PERSISTENT)
robertcollier4
 
Posts: 153
Joined: Sun Feb 24, 2013 5:37 pm

Re: [ST3] Bug: toggle_bookmark does not work sometimes

Postby planet on Thu Mar 07, 2013 6:17 pm

Very nice!

While I was testing you changed it to exactly what I wanted (add cursor position instead of line to bookmark selection) :)

You just need to put "import sublime, sublime_plugin" back in (if this code is used as a stand-alone plugin).

Thank you very much!!
planet
 
Posts: 24
Joined: Fri Feb 17, 2012 12:30 pm


Return to Technical Support

Who is online

Users browsing this forum: DAVe3283, Exabot [Bot] and 22 guests