mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-130693: Support more options for search in tkinter.Text (GH-130848)
* Add parameters nolinestop and strictlimits in the tkinter.Text.search() method. * Add the tkinter.Text.search_all() method. * Add more tests for tkinter.Text.search(). * stopindex is now only ignored if it is None.
This commit is contained in:
parent
f6dd9c12a8
commit
3d14805947
4 changed files with 154 additions and 8 deletions
|
|
@ -4049,8 +4049,9 @@ def scan_dragto(self, x, y):
|
|||
self.tk.call(self._w, 'scan', 'dragto', x, y)
|
||||
|
||||
def search(self, pattern, index, stopindex=None,
|
||||
forwards=None, backwards=None, exact=None,
|
||||
regexp=None, nocase=None, count=None, elide=None):
|
||||
forwards=None, backwards=None, exact=None,
|
||||
regexp=None, nocase=None, count=None,
|
||||
elide=None, *, nolinestop=None, strictlimits=None):
|
||||
"""Search PATTERN beginning from INDEX until STOPINDEX.
|
||||
Return the index of the first character of a match or an
|
||||
empty string."""
|
||||
|
|
@ -4062,12 +4063,39 @@ def search(self, pattern, index, stopindex=None,
|
|||
if nocase: args.append('-nocase')
|
||||
if elide: args.append('-elide')
|
||||
if count: args.append('-count'); args.append(count)
|
||||
if nolinestop: args.append('-nolinestop')
|
||||
if strictlimits: args.append('-strictlimits')
|
||||
if pattern and pattern[0] == '-': args.append('--')
|
||||
args.append(pattern)
|
||||
args.append(index)
|
||||
if stopindex: args.append(stopindex)
|
||||
if stopindex is not None: args.append(stopindex)
|
||||
return str(self.tk.call(tuple(args)))
|
||||
|
||||
def search_all(self, pattern, index, stopindex=None, *,
|
||||
forwards=None, backwards=None, exact=None,
|
||||
regexp=None, nocase=None, count=None,
|
||||
elide=None, nolinestop=None, overlap=None,
|
||||
strictlimits=None):
|
||||
"""Search all occurrences of PATTERN from INDEX to STOPINDEX.
|
||||
Return a tuple of indices where matches begin."""
|
||||
args = [self._w, 'search', '-all']
|
||||
if forwards: args.append('-forwards')
|
||||
if backwards: args.append('-backwards')
|
||||
if exact: args.append('-exact')
|
||||
if regexp: args.append('-regexp')
|
||||
if nocase: args.append('-nocase')
|
||||
if elide: args.append('-elide')
|
||||
if count: args.append('-count'); args.append(count)
|
||||
if nolinestop: args.append('-nolinestop')
|
||||
if overlap: args.append('-overlap')
|
||||
if strictlimits: args.append('-strictlimits')
|
||||
if pattern and pattern[0] == '-': args.append('--')
|
||||
args.append(pattern)
|
||||
args.append(index)
|
||||
if stopindex is not None: args.append(stopindex)
|
||||
result = self.tk.call(tuple(args))
|
||||
return self.tk.splitlist(result)
|
||||
|
||||
def see(self, index):
|
||||
"""Scroll such that the character at INDEX is visible."""
|
||||
self.tk.call(self._w, 'see', index)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue