Edit Book: Fix the Show next occurrence button in the spell check dialog not always working

This commit is contained in:
Kovid Goyal 2014-04-18 22:10:49 +05:30
parent 6c82307975
commit 2d7330d2a9
3 changed files with 7 additions and 7 deletions

View File

@ -378,7 +378,7 @@ class TextEdit(PlainTextEdit):
self.saved_matches[save_match] = (pat, m) self.saved_matches[save_match] = (pat, m)
return True return True
def find_word_in_line(self, word, lang, lnum, from_cursor=True): def find_word_from_line(self, word, lang, lnum, from_cursor=True):
c = self.textCursor() c = self.textCursor()
c.setPosition(c.position()) c.setPosition(c.position())
if not from_cursor or c.blockNumber() != lnum - 1: if not from_cursor or c.blockNumber() != lnum - 1:
@ -386,11 +386,11 @@ class TextEdit(PlainTextEdit):
c.movePosition(c.Start) c.movePosition(c.Start)
c.movePosition(c.NextBlock, n=lnum - 1) c.movePosition(c.NextBlock, n=lnum - 1)
c.movePosition(c.StartOfLine) c.movePosition(c.StartOfLine)
c.movePosition(c.EndOfBlock, c.KeepAnchor)
offset = c.block().position() offset = c.block().position()
c.movePosition(c.End, c.KeepAnchor)
else: else:
offset = c.block().position() + c.positionInBlock() offset = c.block().position() + c.positionInBlock()
c.movePosition(c.EndOfBlock, c.KeepAnchor) c.movePosition(c.End, c.KeepAnchor)
text = unicode(c.selectedText()).rstrip('\0') text = unicode(c.selectedText()).rstrip('\0')
idx = index_of(word, text, lang=lang) idx = index_of(word, text, lang=lang)
if idx == -1: if idx == -1:

View File

@ -189,8 +189,8 @@ class Editor(QMainWindow):
def find(self, *args, **kwargs): def find(self, *args, **kwargs):
return self.editor.find(*args, **kwargs) return self.editor.find(*args, **kwargs)
def find_word_in_line(self, *args, **kwargs): def find_word_from_line(self, *args, **kwargs):
return self.editor.find_word_in_line(*args, **kwargs) return self.editor.find_word_from_line(*args, **kwargs)
def replace(self, *args, **kwargs): def replace(self, *args, **kwargs):
return self.editor.replace(*args, **kwargs) return self.editor.replace(*args, **kwargs)

View File

@ -1046,7 +1046,7 @@ def find_next(word, locations, current_editor, current_editor_name,
idx = lfiles.index(current_editor_name) idx = lfiles.index(current_editor_name)
before, after = lfiles[:idx], lfiles[idx+1:] before, after = lfiles[:idx], lfiles[idx+1:]
lfiles = after + before + [current_editor_name] lfiles = after + before + [current_editor_name]
lnum = current_editor.current_line lnum = current_editor.current_line + 1
start_locations = [l for l in files[current_editor_name] if l.sourceline >= lnum] start_locations = [l for l in files[current_editor_name] if l.sourceline >= lnum]
locations = list(start_locations) locations = list(start_locations)
for fname in lfiles: for fname in lfiles:
@ -1058,7 +1058,7 @@ def find_next(word, locations, current_editor, current_editor_name,
if ed is None: if ed is None:
edit_file(location.file_name) edit_file(location.file_name)
ed = editors[location.file_name] ed = editors[location.file_name]
if ed.find_word_in_line(location.original_word, word[1].langcode, location.sourceline, from_cursor=location in start_locations): if ed.find_word_from_line(location.original_word, word[1].langcode, location.sourceline, from_cursor=location in start_locations):
show_editor(location.file_name) show_editor(location.file_name)
return True return True
return False return False