mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-12-16 09:40:07 +01:00
Merge pull request #2769 from komoto48g/enh-search
Enable whole-word search in the Shell
This commit is contained in:
@@ -251,34 +251,30 @@ class EditWindow(stc.StyledTextCtrl):
|
|||||||
|
|
||||||
def ShowPosition(self, pos):
|
def ShowPosition(self, pos):
|
||||||
line = self.LineFromPosition(pos)
|
line = self.LineFromPosition(pos)
|
||||||
#self.EnsureVisible(line)
|
self.EnsureVisible(line) # Expand the line if folded.
|
||||||
self.GotoLine(line)
|
self.GotoLine(line)
|
||||||
|
|
||||||
def DoFindNext(self, findData, findDlg=None):
|
def DoFindNext(self, findData, findDlg=None):
|
||||||
backward = not (findData.GetFlags() & wx.FR_DOWN)
|
backward = not (findData.GetFlags() & wx.FR_DOWN)
|
||||||
matchcase = (findData.GetFlags() & wx.FR_MATCHCASE) != 0
|
matchcase = findData.GetFlags() & wx.FR_MATCHCASE
|
||||||
end = self.GetLastPosition()
|
wholeword = findData.GetFlags() & wx.FR_WHOLEWORD
|
||||||
# Changed to reflect the fact that StyledTextControl is in UTF-8 encoding
|
findstring = findData.GetFindString().encode()
|
||||||
textstring = self.GetRange(0, end).encode('utf-8')
|
self.SetSearchFlags(0
|
||||||
findstring = findData.GetFindString().encode('utf-8')
|
| (wx.stc.STC_FIND_MATCHCASE if matchcase else 0)
|
||||||
if not matchcase:
|
| (wx.stc.STC_FIND_WHOLEWORD if wholeword else 0)
|
||||||
textstring = textstring.lower()
|
)
|
||||||
findstring = findstring.lower()
|
|
||||||
if backward:
|
if backward:
|
||||||
start = self.GetSelection()[0]
|
self.TargetStart = self.GetAnchor() # backward anchor
|
||||||
loc = textstring.rfind(findstring, 0, start)
|
self.TargetEnd = 0
|
||||||
else:
|
else:
|
||||||
start = self.GetSelection()[1]
|
self.TargetStart = self.GetCurrentPos() # forward anchor
|
||||||
loc = textstring.find(findstring, start)
|
self.TargetEnd = self.TextLength
|
||||||
|
loc = self.SearchInTarget(findstring)
|
||||||
|
|
||||||
# if it wasn't found then restart at beginning
|
# if it wasn't found then restart at beginning
|
||||||
if loc == -1 and start != 0:
|
if loc == -1:
|
||||||
if backward:
|
self.TargetStart = self.TextLength if backward else 0
|
||||||
start = end
|
loc = self.SearchInTarget(findstring)
|
||||||
loc = textstring.rfind(findstring, 0, start)
|
|
||||||
else:
|
|
||||||
start = 0
|
|
||||||
loc = textstring.find(findstring, start)
|
|
||||||
|
|
||||||
# was it still not found?
|
# was it still not found?
|
||||||
if loc == -1:
|
if loc == -1:
|
||||||
|
|||||||
@@ -536,11 +536,10 @@ class Frame(wx.Frame):
|
|||||||
return
|
return
|
||||||
win = wx.Window.FindFocus()
|
win = wx.Window.FindFocus()
|
||||||
if self.shellName == 'PyCrust':
|
if self.shellName == 'PyCrust':
|
||||||
self.findDlg = wx.FindReplaceDialog(win, self.findData,
|
self.findDlg = wx.FindReplaceDialog(win, self.findData, "Find")
|
||||||
"Find",wx.FR_NOWHOLEWORD)
|
|
||||||
else:
|
else:
|
||||||
self.findDlg = wx.FindReplaceDialog(win, self.findData,
|
self.findDlg = wx.FindReplaceDialog(win, self.findData, "Find & Replace",
|
||||||
"Find & Replace", wx.FR_NOWHOLEWORD|wx.FR_REPLACEDIALOG)
|
wx.FR_REPLACEDIALOG)
|
||||||
self.findDlg.Show()
|
self.findDlg.Show()
|
||||||
|
|
||||||
def OnFindNext(self, event, backward=False):
|
def OnFindNext(self, event, backward=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user