comparison mercurial/crecord.py @ 51383:880740426a34

crecord: add a showsearch function This function takes a regex and searches either forward or backward, moving the current item to the found item, if any, and unfolding the relevant context.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Wed, 14 Feb 2024 22:48:09 -0500
parents ed0b78b2a3aa
children 6fb4d2dfa8e4
comparison
equal deleted inserted replaced
51382:ed0b78b2a3aa 51383:880740426a34
1886 return True 1886 return True
1887 for header in item: 1887 for header in item:
1888 if header.hunks: 1888 if header.hunks:
1889 return False 1889 return False
1890 return True 1890 return True
1891
1892 def showsearch(self, regex, forward=True):
1893 if not regex:
1894 return
1895
1896 moveattr = 'nextitem' if forward else 'previtem'
1897 currentitem = getattr(self.currentselecteditem, moveattr)(
1898 skipfolded=False
1899 )
1900
1901 matches = None
1902 regex = re.compile(regex)
1903 while currentitem:
1904 matches = regex.search(currentitem.content)
1905 if matches:
1906 self.currentselecteditem = currentitem
1907 break
1908 currentitem = getattr(currentitem, moveattr)(skipfolded=False)
1909
1910 # Whatever is selected should now be visible
1911 unfolded = self.currentselecteditem
1912 while matches and unfolded:
1913 unfolded.folded = False
1914 unfolded = unfolded.parentitem()
1915
1916 return matches
1891 1917
1892 def handlekeypressed(self, keypressed, test=False): 1918 def handlekeypressed(self, keypressed, test=False):
1893 """ 1919 """
1894 Perform actions based on pressed keys. 1920 Perform actions based on pressed keys.
1895 1921