Skip to content

Commit d289937

Browse files
committed
Update Find in Files to anchor workbox_name
1 parent f0af677 commit d289937

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

preditor/gui/find_files.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,26 @@ def find(self):
7979
editor,
8080
group_name,
8181
tab_name,
82-
group_index,
83-
tab_index,
82+
_group_index,
83+
_tab_index,
8484
) in manager.all_widgets():
8585
path = "/".join((group_name, tab_name))
86-
workbox_id = '{},{}'.format(group_index, tab_index)
87-
self.find_in_editor(editor, path, workbox_id)
86+
self.find_in_editor(editor, path)
8887

8988
self.insert_text(
9089
'\n{} matches in {} workboxes\n'.format(
9190
self.finder.match_count, self.match_files_count
9291
)
9392
)
9493

95-
def find_in_editor(self, editor, path, workbox_id):
94+
def find_in_editor(self, editor, path):
9695
# Ensure the editor text is loaded and get its raw text
9796
editor.__show__()
9897
text = editor.__text__()
98+
workbox_name = editor.__workbox_name__()
9999

100100
# Use the finder to check for matches
101-
found = self.finder.search_text(text, path, workbox_id)
101+
found = self.finder.search_text(text, path, workbox_name)
102102
if found:
103103
self.match_files_count += 1
104104

preditor/utils/text_search.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def indicate_line(self, line):
7070
"""
7171

7272
def indicate_results(
73-
self, line, line_num, path="undefined", workbox_id="undefined"
73+
self, line, line_num, path="undefined", workbox_name="undefined"
7474
):
7575
"""Writes a single line adding markup for any matches on the line."""
7676
tool_tip = "Open {} at line number {}".format(path, line_num)
@@ -82,7 +82,7 @@ def indicate_results(
8282

8383
# Otherwise print the next section of the line text
8484
if indicate:
85-
self.callback_matching(text, workbox_id, line_num, tool_tip)
85+
self.callback_matching(text, workbox_name, line_num, tool_tip)
8686
else:
8787
self.callback_non_matching(text)
8888

@@ -121,21 +121,19 @@ def margin(self, line_num, match_found):
121121
def matches(self, line):
122122
"""Returns bool for if find_text is contained in this line."""
123123

124-
def print_matching(self, text, workbox_id, line_num, tool_tip):
124+
def print_matching(self, text, workbox_name, line_num, tool_tip):
125125
"""Simple callback for `callback_matching` that prints text.
126126
127127
The print does not insert an newline character.
128128
129129
Args:
130130
text (str): The matching text to display. This will be inserted
131131
into a markdown link as the link text.
132-
workbox_id (str): From `GroupTabWidget.all_widgets`, the group_tab_index
133-
and widget_tab_index joined by a comma without a space. Used as
134-
the url of the link. Example: `3,1`.
132+
workbox_name (str): From editor.__workbox_name__()
135133
line_number (int): The line number the url should navigate to.
136134
tool_tip (str): Added as a title to the link to show up as a tool tip.
137135
"""
138-
href = ', {}, {}'.format(workbox_id, line_num)
136+
href = ', {}, {}'.format(workbox_name, line_num)
139137
print('[{}]({} "{}")'.format(text, href, tool_tip), end="")
140138

141139
def print_non_matching(self, text):
@@ -145,17 +143,15 @@ def print_non_matching(self, text):
145143
"""
146144
print(text, end="")
147145

148-
def search_text(self, text, path, workbox_id):
146+
def search_text(self, text, path, workbox_name):
149147
"""Search each line of text for matching text and write the the matches
150148
including context lines.
151149
152150
Args:
153151
text (str): The text to search.
154152
path (str): The workbox name this text represents. Should be the
155153
Group_name and tab_name separated by a `/`.
156-
workbox_id (str): From `GroupTabWidget.all_widgets`, the group_tab_index
157-
and widget_tab_index joined by a comma without a space. Used as
158-
the url of the link. Example: `3,1`.
154+
workbox_name (str): From editor.__workbox_name__()
159155
"""
160156
# NOTE: splitlines discards the "newline at end of file" so it doesn't
161157
# show up in the final search results.
@@ -177,14 +173,14 @@ def search_text(self, text, path, workbox_id):
177173
found = False
178174

179175
for i, line in enumerate(lines):
180-
info = dict(path=path, workbox_id=workbox_id)
176+
info = dict(path=path, workbox_name=workbox_name)
181177
if self.matches(line):
182178
len_pre_history = len(pre_history)
183179
if not found:
184180
# Print the path on the first find
185181
self.callback_non_matching("# File: ")
186182
tool_tip = "Open {}".format(path)
187-
self.callback_matching(path, workbox_id, 0, tool_tip)
183+
self.callback_matching(path, workbox_name, 0, tool_tip)
188184
self.callback_non_matching("\n")
189185
found = True
190186
elif i - last_insert - 1 - len_pre_history > 0:

0 commit comments

Comments
 (0)