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

Commit ddbc4ed

Browse files
committed
add method to clear gutter markup
1 parent e57a2bf commit ddbc4ed

6 files changed

Lines changed: 41 additions & 24 deletions

Default (Linux).sublime-keymap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[
2-
{ "keys": ["alt+ctrl+shift+f"], "command": "search_in_project" }
2+
{ "keys": ["alt+ctrl+shift+f"], "command": "search_in_project", "args": { "type": "search" } }
33
]

Default (OSX).sublime-keymap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[
2-
{ "keys": ["alt+super+shift+f"], "command": "search_in_project" }
2+
{ "keys": ["alt+super+shift+f"], "command": "search_in_project", "args": { "type": "search" } }
33
]

Default (Windows).sublime-keymap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[
2-
{ "keys": ["alt+ctrl+shift+f"], "command": "search_in_project" }
2+
{ "keys": ["alt+ctrl+shift+f"], "command": "search_in_project", "args": { "type": "search" } }
33
]

Default.sublime-commands

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
[
22
{
3-
"caption": "Search In Project",
4-
"command": "search_in_project"
3+
"caption": "SearchInProject: Search",
4+
"command": "search_in_project", "args": {"type": "search"},
5+
},
6+
{
7+
"caption": "SearchInProject: Clear results",
8+
"command": "search_in_project", "args": {"type": "clear"},
59
},
610
{
711
"caption": "Preferences: Search in Project Settings – Default",

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It opens a quick selection panel to browse results, and highlights matches insid
99
## Usage
1010

1111
* Use the key binding (`⌘⌥⇧F` on OS X, `Ctrl+Alt+Shift+F` on Windows and Linux), or
12-
* Call the "Search in Project" command;
12+
* Call the "SearchInProject: Search" command;
1313
* Enter the search query;
1414
* Hit `Enter` (`Return`). You'll be presented with a "quick select" panel with the search results. Select any file from that panel (it supports fuzzy searching) to go to the match. The search string will be highlighted with an outline and a circle symbol in the gutter area.
1515
* The last item on the quick select panel is "List results in view". Pick it to see results in a regular editor view. (Tip: if you enter three ticks ("`") in the search box - it's going to be to be the first item.)
@@ -32,7 +32,7 @@ My idea is that if you use this plugin it's because you already use one of the s
3232

3333
The supported search engines are:
3434

35-
Name | Description | Search in Project key
35+
Name | Description | Search in Project key
3636
---- | ----------- | ---------------------
3737
**[pt (The Platinum Searcher)](https://github.com/monochromegane/the_platinum_searcher)** | **fast, has binaries for every platform, recommended.** | `the_platinum_searcher`
3838
**[ag (The Silver Searcher)](http://geoff.greer.fm/ag/)** | **equally fast, only 3rd party binaries for Windows, also recommended** | `the_silver_searcher`

search_in_project.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,25 @@ def __init__(self, window):
3838
self.last_search_string = ''
3939
pass
4040

41-
def run(self):
42-
self.settings = sublime.load_settings('SearchInProject.sublime-settings')
43-
self.engine_name = self.settings.get("search_in_project_engine")
44-
pushd = os.getcwd()
45-
os.chdir(basedir)
46-
__import__("searchengines.%s" % self.engine_name)
47-
self.engine = searchengines.__dict__[self.engine_name].engine_class(self.settings)
48-
os.chdir(pushd)
49-
view = self.window.active_view()
50-
selection_text = view.substr(view.sel()[0])
51-
self.window.show_input_panel(
52-
"Search in project:",
53-
not "\n" in selection_text and selection_text or self.last_search_string,
54-
self.perform_search, None, None)
55-
pass
41+
def run(self, type="search"):
42+
if type == "search":
43+
self.settings = sublime.load_settings('SearchInProject.sublime-settings')
44+
self.engine_name = self.settings.get("search_in_project_engine")
45+
pushd = os.getcwd()
46+
os.chdir(basedir)
47+
__import__("searchengines.%s" % self.engine_name)
48+
self.engine = searchengines.__dict__[self.engine_name].engine_class(self.settings)
49+
os.chdir(pushd)
50+
view = self.window.active_view()
51+
selection_text = view.substr(view.sel()[0])
52+
self.window.show_input_panel(
53+
"Search in project:",
54+
not "\n" in selection_text and selection_text or self.last_search_string,
55+
self.perform_search, None, None)
56+
elif type == "clear":
57+
self.clear_markup()
58+
else:
59+
raise Exception("unrecognized type \"%s\""%type)
5660

5761
def perform_search(self, text):
5862
if not text:
@@ -81,11 +85,20 @@ def goto_result(self, file_no):
8185
if file_no == len(self.results) - 1: # last result is "list in view"
8286
self.list_in_view()
8387
else:
84-
file_name = self.common_path.replace('\"', '') + self.results[file_no][0]
85-
view = self.window.open_file(file_name, sublime.ENCODED_POSITION)
88+
file_name_and_col = self.common_path.replace('\"', '') + self.results[file_no][0]
89+
view = self.window.open_file(file_name_and_col, sublime.ENCODED_POSITION)
8690
regions = view.find_all(self.last_search_string, sublime.IGNORECASE)
8791
view.add_regions("search_in_project", regions, "entity.name.filename.find-in-files", "circle", sublime.DRAW_OUTLINED)
8892

93+
def clear_markup(self):
94+
for result in self.results[:-1]: # every result except the last one (the "list in view")
95+
file_name_and_col = self.common_path.replace('\"', '') + result[0]
96+
file_name = file_name_and_col.split(':')[0]
97+
view = self.window.find_open_file(file_name)
98+
if view: # if the view is no longer open, do nothing
99+
view.erase_regions("search_in_project")
100+
self.results = []
101+
89102
def list_in_view(self):
90103
self.results.pop()
91104
view = sublime.active_window().new_file()

0 commit comments

Comments
 (0)