Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Merged branch newDev into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Ray committed Nov 30, 2016
2 parents 8de1d2d + 808a96d commit 01d973f
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions BetterBookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ def Marks(create=False):

return Variable(directory + '/${file_base_name}-${file_extension}.bb_cache')


# Converts the marks-as-tuples back into sublime.Regions
def UnhashMarks(marks):
newMarks = []
for mark in marks:
newMarks.append(sublime.Region(mark[0], mark[1]))

return newMarks

# In order to use some list functions, python needs to be able to see a sublime.Region as something simpler;
# in this case a tuple.
def HashMarks(marks):
newMarks = []
for mark in marks:
newMarks.append((mark.a, mark.b))

return newMarks

# This class allows the conversion from a sublime.Region to a string (json)
class RegionJSONCoder(json.JSONEncoder):
def default(self, obj):
Expand Down Expand Up @@ -59,9 +77,6 @@ def __init__(self, edit):
self.marks = {}
for layer in Settings().get('layer_icons'):
self.marks[layer] = []
# Unused
# def _should_bookmark(self, layer, line):
# return self._unhash_marks in not self.marks[layer]

def _is_empty(self):
for layer in self.layers:
Expand All @@ -72,29 +87,12 @@ def _is_empty(self):

# Renders the current layers marks to the view
def _render(self):
marks = self._unhash_marks(self.marks[self.layer])
marks = UnhashMarks(self.marks[self.layer])
icon = Settings().get('layer_icons')[self.layer]['icon']
scope = Settings().get('layer_icons')[self.layer]['scope']

self.view.add_regions('bookmarks', marks, scope, icon, sublime.PERSISTENT | sublime.HIDDEN)

# Converts the marks-as-tuples back into sublime.Regions
def _unhash_marks(self, marks):
newMarks = []
for mark in marks:
newMarks.append(sublime.Region(mark[0], mark[1]))

return newMarks

# In order to use some list functions, python needs to be able to see a sublime.Region as something simpler;
# in this case a tuple.
def _hash_marks(self, marks):
newMarks = []
for mark in marks:
newMarks.append((mark.a, mark.b))

return newMarks

# Internal function for adding a list of marks to the existing ones.
# Any marks that exist in both lists will be removed as this case is when the user is
# attempting to remove a mark.
Expand All @@ -103,8 +101,6 @@ def _add_marks(self, newMarks, layer=None):
marks = []

if newMarks:
newMarks = self._hash_marks(newMarks)

if not layer in self.marks:
self.marks[layer] = []

Expand All @@ -118,7 +114,7 @@ def _add_marks(self, newMarks, layer=None):

self.marks[layer] = marks

if layer is self.layer:
if layer == self.layer:
self._render()

# Changes the layer to the given one and updates any and all of the status indicators.
Expand Down Expand Up @@ -147,10 +143,10 @@ def run(self, edit, **args):
subcommand = args['subcommand']

if subcommand == 'mark_line':
line = args['line'] if 'line' in args else view.sel()[0]
line = args['line'] if 'line' in args else HashMarks(view.sel())
layer = args['layer'] if 'layer' in args else self.layer

self._add_marks([line], layer)
self._add_marks(line, layer)
elif subcommand == 'clear_marks':
layer = args['layer'] if 'layer' in args else self.layer
self._add_marks([], layer)
Expand Down

0 comments on commit 01d973f

Please sign in to comment.