mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Search wrapping for current file searches
This commit is contained in:
parent
dfb16c58a6
commit
527c33bb0d
@ -311,14 +311,31 @@ class Boss(QObject):
|
||||
else:
|
||||
pass # TODO: Find the first name with a match and open its editor
|
||||
else:
|
||||
files = [name]
|
||||
pass # marked text TODO: Implement this
|
||||
|
||||
def no_match():
|
||||
return error_dialog(
|
||||
self.gui, _('Not found'), _(
|
||||
'No matches were found for %s') % state['find'], show=True)
|
||||
|
||||
pat = sp.get_regex(state)
|
||||
if action == 'find':
|
||||
|
||||
def do_find():
|
||||
found = editor.find(pat)
|
||||
if found:
|
||||
return
|
||||
# TODO: Handle wrapping, depending on state['where']
|
||||
if len(files) == 1:
|
||||
if not state['wrap']:
|
||||
return no_match()
|
||||
found = editor.find(pat, wrap=True)
|
||||
if not found:
|
||||
return no_match()
|
||||
else:
|
||||
pass # TODO: handle multiple file search
|
||||
|
||||
if action == 'find':
|
||||
return do_find()
|
||||
|
||||
def save_book(self):
|
||||
c = current_container()
|
||||
|
@ -154,11 +154,14 @@ class TextEdit(QPlainTextEdit):
|
||||
self.current_search_mark = None
|
||||
self.update_extra_selections()
|
||||
|
||||
def find(self, pat):
|
||||
def find(self, pat, wrap=False):
|
||||
reverse = pat.flags & regex.REVERSE
|
||||
c = self.textCursor()
|
||||
c.clearSelection()
|
||||
c.movePosition(c.Start if reverse else c.End, c.KeepAnchor)
|
||||
pos = c.Start if reverse else c.End
|
||||
if wrap:
|
||||
pos = c.End if reverse else c.Start
|
||||
c.movePosition(pos, c.KeepAnchor)
|
||||
raw = unicode(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n')
|
||||
m = pat.search(raw)
|
||||
if m is None:
|
||||
@ -166,12 +169,17 @@ class TextEdit(QPlainTextEdit):
|
||||
start, end = m.span()
|
||||
if start == end:
|
||||
return False
|
||||
if reverse:
|
||||
# Put the cursor at the start of the match
|
||||
start, end = end, start
|
||||
if wrap:
|
||||
if reverse:
|
||||
textpos = c.anchor()
|
||||
start, end = textpos + end, textpos + start
|
||||
else:
|
||||
textpos = c.anchor()
|
||||
start, end = textpos + start, textpos + end
|
||||
if reverse:
|
||||
# Put the cursor at the start of the match
|
||||
start, end = end, start
|
||||
else:
|
||||
textpos = c.anchor()
|
||||
start, end = textpos + start, textpos + end
|
||||
c.clearSelection()
|
||||
c.setPosition(start)
|
||||
c.setPosition(end, c.KeepAnchor)
|
||||
|
Loading…
x
Reference in New Issue
Block a user