-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-130693: Add options of the tkinter.Text.search method: -nolinestop -all -overlap -strictlimits #130848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
gh-130693: Add options of the tkinter.Text.search method: -nolinestop -all -overlap -strictlimits #130848
Changes from all commits
8b27bcb
18d5005
e2a76c2
753da3a
1ca30c6
548e36a
6ce83e3
39f5875
ba0c98a
754a124
ffd95fa
72e70fc
6229bdf
1843da6
7196a88
2601ddf
6d18d2f
b672353
bb9a840
cc80963
8c8409c
980a5e3
fb30d25
d58a291
d3621e2
dfe46c0
efc1685
a286199
9cf844a
834d6d4
e4c7bef
7cb79b9
026ded8
430773c
2f5ad84
71d2a60
77831d4
1daff0f
422aa6f
1328308
6e3d0c9
6c6520b
2852ee2
9604fcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,7 @@ production systems where traditional profiling approaches would be too intrusive | |
|
||
(Contributed by Pablo Galindo and László Kiss Kollár in :gh:`135953`.) | ||
|
||
======= | ||
|
||
Improved error messages | ||
----------------------- | ||
|
@@ -207,7 +208,6 @@ Improved error messages | |
^^^^^^^^^^^^^^ | ||
AttributeError: 'Container' object has no attribute 'area'. Did you mean: 'inner.area'? | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated change. |
||
Other language changes | ||
====================== | ||
|
||
|
@@ -455,6 +455,19 @@ tarfile | |
(Contributed by Matt Prodani and Petr Viktorin in :gh:`112887` | ||
and :cve:`2025-4435`.) | ||
|
||
tkinter | ||
------- | ||
|
||
* The :meth:`!tkinter.Text.search` method now supports two additional | ||
arguments: *nolinestop* which allows the search to | ||
continue across line boundaries; | ||
and *strictlimits* which restricts the search to within the specified range. | ||
(Contributed by Rihaan Meher in :gh:`130848`) | ||
|
||
* A new method :meth:`!tkinter.Text.search_all` has been introduced. | ||
This method allows for searching for all matches of a pattern | ||
using Tcl's ``-all`` and ``-overlap`` options. | ||
(Contributed by Rihaan Meher in :gh:`130848`) | ||
|
||
types | ||
------ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,47 @@ def test_search(self): | |
self.assertEqual(text.search('-test', '1.0', 'end'), '1.2') | ||
self.assertEqual(text.search('test', '1.0', 'end'), '1.3') | ||
|
||
text.delete('1.0', 'end') | ||
text.insert('1.0', | ||
'This is a test. This is only a test.\n' | ||
'Another line.\n' | ||
'Yet another line.') | ||
|
||
result = text.search('line', '1.0', 'end', nolinestop=True, regexp=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why It would be nice for each option to call |
||
self.assertEqual(result, '2.8') | ||
|
||
strict_res = text.search('test', '1.0', '1.20', strictlimits=True) | ||
self.assertEqual(strict_res, '1.10') | ||
|
||
def test_search_all(self): | ||
text = self.text | ||
text.insert('1.0', | ||
'ababa ababa\n' | ||
'ababababa\n' | ||
'aba aba') | ||
|
||
all_res = text.search_all('aba', '1.0', 'end') | ||
all_res_strs = [str(i) for i in all_res] | ||
self.assertIsInstance(all_res, tuple) | ||
self.assertGreaterEqual(len(all_res), 3) | ||
self.assertEqual(str(all_res[0]), '1.0') | ||
self.assertEqual(str(all_res[1]), '1.6') | ||
|
||
overlap_res = text.search_all('aba', '1.0', 'end', overlap=True) | ||
overlap_res_strs = [str(i) for i in overlap_res] | ||
self.assertIsInstance(overlap_res, tuple) | ||
self.assertGreater(len(overlap_res), len(all_res)) | ||
|
||
# Check that overlap actually finds overlapping matches | ||
self.assertIn('2.0', overlap_res_strs) | ||
self.assertIn('2.2', overlap_res_strs) | ||
self.assertIn('2.4', overlap_res_strs) | ||
self.assertNotIn('2.2', all_res_strs) | ||
|
||
# Ensure all results are valid text indices | ||
for i in overlap_res: | ||
self.assertRegex(str(i), r'^\d+\.\d+$') | ||
Comment on lines
+73
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we simply test |
||
|
||
def test_count(self): | ||
text = self.text | ||
text.insert('1.0', | ||
|
@@ -94,6 +135,5 @@ def test_count(self): | |
self.assertEqual(text.count('1.3', '1.3', 'update', return_ints=True), 0) | ||
self.assertEqual(text.count('1.3', '1.3', 'update'), None) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add support for ``-nolinestop``, and ``-strictlimits`` options to :meth:`!tkinter.Text.search`. Also add the :meth:`!tkinter.Text.search_all` method for ``-all`` and ``-overlap`` options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated change.