Skip to content

Commit

Permalink
Add settings for closing the previous "Find Results" and to open the …
Browse files Browse the repository at this point in the history
…new "Find Results" in a new view instead of reusing the old one
  • Loading branch information
titoBouzout committed May 12, 2019
1 parent 3dd1a22 commit 9ae2147
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Side Bar.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@

"copy_path_absolute_from_project_includes_line_number": false,

"keep_only_one_tab_with_search_results": false,
"find_and_replace_discards_previous_search": false,
"find_and_replace_opens_in_new_view": true,

// if you donated set this value to "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DD4SL2AHYJGBW"
// to remove the menuitem "Donate 20$" from the sidebar context menu.
Expand Down
30 changes: 29 additions & 1 deletion SideBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,14 +594,42 @@ def is_visible(self, paths=[], application="", extensions="", args=[]):

class SideBarFindInSelectedCommand(sublime_plugin.WindowCommand):
def run(self, paths=[]):
if s.get("keep_only_one_tab_with_search_results", False):
if s.get("find_and_replace_discards_previous_search", False):
window = Window()
views = []
for view in window.views():
if view.name() == "Find Results":
views.append(view)
for view in views:
view.close()

if s.get("find_and_replace_opens_in_new_view", True):
window = Window()
views = []
for view in window.views():
if view.name() == "Find Results":

Window().focus_view(view)

content = view.substr(sublime.Region(0, view.size()))

_view = Window().new_file()
with Edit(_view) as edit:
edit.replace(sublime.Region(0, _view.size()), content)
# the space at the end of the name prevents it from being reused by Sublime Text
# it looks like instead of keeping an internal refrence they just look at the view name -__-
_view.set_name("Find Results ")
_view.set_syntax_file(
"Packages/Default/Find Results.hidden-tmLanguage"
)
_view.sel().clear()
for sel in view.sel():
_view.sel().add(sel)
_view.set_scratch(True)
views.append(view)

for view in views:
view.close()
items = []
for item in SideBarSelection(paths).getSelectedItemsWithoutChildItems():
items.append(item.path())
Expand Down

0 comments on commit 9ae2147

Please sign in to comment.