Skip to content
This repository was archived by the owner on Jan 27, 2023. It is now read-only.

Commit 964de16

Browse files
committed
add next/prev result navigation
1 parent 2cfc81a commit 964de16

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Default.sublime-commands

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
"caption": "SearchInProject: Clear results",
88
"command": "search_in_project", "args": {"type": "clear"},
99
},
10+
{
11+
"caption": "SearchInProject: Next result",
12+
"command": "search_in_project", "args": {"type": "next"},
13+
},
14+
{
15+
"caption": "SearchInProject: Previous result",
16+
"command": "search_in_project", "args": {"type": "prev"},
17+
},
1018
{
1119
"caption": "Preferences: Search in Project Settings – Default",
1220
"command": "open_file", "args":

search_in_project.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SearchInProjectCommand(sublime_plugin.WindowCommand):
3535

3636
def __init__(self, window):
3737
sublime_plugin.WindowCommand.__init__(self, window)
38+
self.results = []
3839
self.last_search_string = ''
3940
self.last_selected_result_index = 0
4041

@@ -56,6 +57,10 @@ def run(self, type="search"):
5657
panel_view.run_command("select_all")
5758
elif type == "clear":
5859
self.clear_markup()
60+
elif type == "next":
61+
self.goto_relative_result(1)
62+
elif type == "prev":
63+
self.goto_relative_result(-1)
5964
else:
6065
raise Exception("unrecognized type \"%s\""%type)
6166

@@ -104,6 +109,13 @@ def goto_result(self, file_no):
104109
regions = view.find_all(self.last_search_string, sublime.IGNORECASE)
105110
view.add_regions("search_in_project", regions, "entity.name.filename.find-in-files", "circle", sublime.DRAW_OUTLINED)
106111

112+
def goto_relative_result(self, offset):
113+
if self.last_search_string:
114+
new_index = self.last_selected_result_index + offset
115+
if 0 <= new_index < len(self.results) - 1: # last result is "list in view"
116+
self.last_selected_result_index = new_index
117+
self.goto_result(new_index)
118+
107119
def clear_markup(self):
108120
for result in self.results[:-1]: # every result except the last one (the "list in view")
109121
file_name_and_col = self.common_path.replace('\"', '') + result[0]

0 commit comments

Comments
 (0)