* Fixed search term highlighting in result.
authorUrban Wallasch <urban.wallasch@freenet.de>
Mon, 14 Jun 2021 13:11:15 +0000 (15:11 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Mon, 14 Jun 2021 13:11:15 +0000 (15:11 +0200)
* Improved whole expression matching rule.

jiten-pai.py

index 41d8b550de59280cceb68120598e738f8ddf029f..5f8267ecf5c098a5c7acf7def636addccb3a94e0 100755 (executable)
@@ -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 = '<span style="font-family: %s; font-size: %dpt;">' % (cfg['lfont'], cfg['lfont_sz'])
         hl = '<span style="color: %s;">' % cfg['hl_col']
         html = [nfmt]
+        def hl_repl(match):
+            return hl + match.group(0) + '</span>'
         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()] \
-                           + '</span>' + res[i][match.end():]
+                res[i] = re_term.sub(hl_repl, res[i])
             # construct display line
             html.append('%s%s</span>' % (lfmt, res[0]))
             if len(res[1]) > 0:
                 html.append(' (%s)' % res[1])
-            html.append(' %s<br>' % res[2])
+            html.append(' %s<br>\n' % res[2])
         html.append('</div>')
         self.result_pane.setHtml(''.join(html))
         self.matches_label.setText("Matches found: %d" % len(result))