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:
|
else:
|
||||||
pass # TODO: Find the first name with a match and open its editor
|
pass # TODO: Find the first name with a match and open its editor
|
||||||
else:
|
else:
|
||||||
|
files = [name]
|
||||||
pass # marked text TODO: Implement this
|
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)
|
pat = sp.get_regex(state)
|
||||||
if action == 'find':
|
|
||||||
|
def do_find():
|
||||||
found = editor.find(pat)
|
found = editor.find(pat)
|
||||||
if found:
|
if found:
|
||||||
return
|
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):
|
def save_book(self):
|
||||||
c = current_container()
|
c = current_container()
|
||||||
|
@ -154,11 +154,14 @@ class TextEdit(QPlainTextEdit):
|
|||||||
self.current_search_mark = None
|
self.current_search_mark = None
|
||||||
self.update_extra_selections()
|
self.update_extra_selections()
|
||||||
|
|
||||||
def find(self, pat):
|
def find(self, pat, wrap=False):
|
||||||
reverse = pat.flags & regex.REVERSE
|
reverse = pat.flags & regex.REVERSE
|
||||||
c = self.textCursor()
|
c = self.textCursor()
|
||||||
c.clearSelection()
|
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')
|
raw = unicode(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n')
|
||||||
m = pat.search(raw)
|
m = pat.search(raw)
|
||||||
if m is None:
|
if m is None:
|
||||||
@ -166,6 +169,11 @@ class TextEdit(QPlainTextEdit):
|
|||||||
start, end = m.span()
|
start, end = m.span()
|
||||||
if start == end:
|
if start == end:
|
||||||
return False
|
return False
|
||||||
|
if wrap:
|
||||||
|
if reverse:
|
||||||
|
textpos = c.anchor()
|
||||||
|
start, end = textpos + end, textpos + start
|
||||||
|
else:
|
||||||
if reverse:
|
if reverse:
|
||||||
# Put the cursor at the start of the match
|
# Put the cursor at the start of the match
|
||||||
start, end = end, start
|
start, end = end, start
|
||||||
|
Loading…
x
Reference in New Issue
Block a user