From a495d09c2255073b087d3147c992ce77521bf8f5 Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Mon, 14 Jun 2021 15:11:15 +0200 Subject: [PATCH] * Fixed search term highlighting in result. * Improved whole expression matching rule. --- jiten-pai.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/jiten-pai.py b/jiten-pai.py index 41d8b55..5f8267e 100755 --- a/jiten-pai.py +++ b/jiten-pai.py @@ -213,9 +213,8 @@ class jpMainWindow(QMainWindow): else: print('apply engopt') if self.engopt_expr.isChecked(): - term = '\W ' + term - if term[-1] != ';': - term = term + ';' + term = '\W( to)? ' + term + term = term + '(\s+\(.*\))?;' if self.engopt_word.isChecked(): term = '\W' + term + '\W' if self.engopt_any.isChecked(): @@ -235,19 +234,17 @@ class jpMainWindow(QMainWindow): lfmt = '' % (cfg['lfont'], cfg['lfont_sz']) hl = '' % cfg['hl_col'] html = [nfmt] + def hl_repl(match): + return hl + match.group(0) + '' for res in result: # highlight matches for i in range(len(res)): - match = re_term.search(res[i]) - if match: - res[i] = res[i][:match.start()] + hl \ - + res[i][match.start():match.end()] \ - + '' + res[i][match.end():] + res[i] = re_term.sub(hl_repl, res[i]) # construct display line html.append('%s%s' % (lfmt, res[0])) if len(res[1]) > 0: html.append(' (%s)' % res[1]) - html.append(' %s
' % res[2]) + html.append(' %s
\n' % res[2]) html.append('') self.result_pane.setHtml(''.join(html)) self.matches_label.setText("Matches found: %d" % len(result)) -- 2.30.2