Skip to content

Commit

Permalink
show number of selected results when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-hall committed Dec 28, 2015
1 parent f52ea1d commit 8d490ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions sublime_lxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ def get_regions_of_nodes(view, nodes, position_type):
yield sublime.Region(open_pos.begin(), close_pos.end())

def move_cursors_to_nodes(view, nodes, position_type):
nodes = list(nodes)
cursors = list(get_regions_of_nodes(view, nodes, position_type))
if len(cursors) > 0:
view.sel().clear()
view.sel().add_all(cursors)

view.show(cursors[0]) # scroll to show the first selection, if it is not already visible

return (len(cursors) == len(nodes), len(cursors))

def getElementXMLPreview(view, node, maxlen):
"""Generate the xml string for the given node, up to the specified number of characters."""
Expand Down
11 changes: 9 additions & 2 deletions xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,13 @@ def process_results_for_query(self, query):

self.show_results_for_query()
else:
self.goto_results_for_query()
all_success = self.goto_results_for_query()
if not all_success[0]:
status_text += ' (' + str(all_success[1])
status_text += ' selected'
if not all_success[0]:
status_text += ')'

if not self.show_query_results:
sublime.status_message(status_text or '')
else:
Expand Down Expand Up @@ -893,10 +898,12 @@ def goto_results_for_query(self, specific_index = None):
if specific_index is not None and specific_index > -1:
results = [results[specific_index]]

move_cursors_to_nodes(self.view, results, 'open')
all_success = move_cursors_to_nodes(self.view, results, 'open')

if specific_index is None or specific_index == -1:
self.results = None

return all_success

def is_enabled(self, **args):
return isCursorInsideSGML(self.view)
Expand Down

0 comments on commit 8d490ea

Please sign in to comment.