Skip to content
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

gh-130693: Add options of the tkinter.Text.search method: -nolinestop -all -overlap -strictlimits #130848

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sharktide
Copy link

@sharktide sharktide commented Mar 4, 2025

Add options -nolinestop, -all, -overlap, and -strictlimits to the search function of the text class of tkinter.

Fixes #130693
Closes #130693

Tested against

.\PCbuild\amd64\python_d.exe -m test -ugui test_tkinter

And test passed. Result:

0:00:00 [1/1] test_tkinter
0:00:27 load avg: 3.93 [1/1] test_tkinter passed

== Tests result: SUCCESS ==

1 test OK.

Total duration: 27.6 sec
Total tests: run=787 skipped=11
Total test files: run=1/1
Result: SUCCESS

Also tested against a custom test file:

import tkinter as tk

root = tk.Tk()
text = tk.Text(root)
text.pack()

text.insert('1.0', 'This is a test. This is only a test.\nAnother line.\nYet another line.')

# Test without options
result = text.search('test', '1.0', 'end')
print('Without options:', result)

# Test with -nolinestop
result = text.search('line', '1.0', 'end', nolinestop=True, regexp=True)
print('With -nolinestop:', result)

# Test with -all
result = text.search('test', '1.0', 'end', all=True)
print('With -all:', result)

# Test with -overlap
result = text.search('test', '1.0', 'end', overlap=True, all=True)
print('With -overlap:', result)

# Test with -strictlimits
result = text.search('test', '1.0', 'end', strictlimits=True)
print('With -strictlimits:', result)

root.mainloop()

Which returns:

Without options: 1.10
With -nolinestop: 2.8
With -all: (<textindex object: '1.10'>, <textindex object: '1.31'>)
With -overlap: (<textindex object: '1.10'>, <textindex object: '1.31'>)
With -strictlimits: 1.10

Indicating that the new features are functioning correctly

@bedevere-app
Copy link

bedevere-app bot commented Mar 4, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Comment on lines 1 to 13
================
Type: Enhancement
Title: Add support for ``-nolinestop``, ``-all``, ``-overlap``, and ``-strictlimits`` options to ``tkinter.Text.search``
Issue: :gh:`130693`

Detailed changes:
- Enhanced the ``tkinter.Text.search`` method by adding support for the following options:
- ``-nolinestop``: Allows searching across lines without stopping.
- ``-all``: Finds all matches instead of just the first match.
- ``-overlap``: Finds matches that overlap with each other.
- ``-strictlimits``: Ensures strict boundaries for the search.

These improvements align the ``tkinter.Text.search`` method with the underlying Tcl/Tk library, providing more flexibility and functionality for users.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete the first few lines and summarize them in only a few sentences

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@sharktide sharktide requested a review from Wulian233 March 5, 2025 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tkinter missing -nolinestop on tk.Text
2 participants