Edit Book: Fix live link syntax highlighting not being updated correctly after renaming an open file

This commit is contained in:
Kovid Goyal 2014-07-11 17:07:49 +05:30
parent 40e2807604
commit 2b06cffa0d
4 changed files with 12 additions and 1 deletions

View File

@ -552,7 +552,8 @@ class Boss(QObject):
self.set_modified()
for oldname, newname in name_map.iteritems():
if oldname in editors:
editors[newname] = editors.pop(oldname)
editors[newname] = ed = editors.pop(oldname)
ed.change_document_name(newname)
self.gui.central.rename_editor(editors[newname], newname)
if self.gui.preview.current_name == oldname:
self.gui.preview.current_name = newname

View File

@ -139,6 +139,9 @@ class Editor(QMainWindow):
def pretty_print(self, name):
return False
def change_document_name(self, newname):
pass
def get_raw_data(self):
return self.canvas.get_image_data(quality=self.quality)

View File

@ -222,6 +222,10 @@ class TextEdit(PlainTextEdit):
c = self.textCursor()
c.insertText('')
def change_document_name(self, newname):
self.highlighter.doc_name = newname
self.highlighter.rehighlight() # Ensure links are checked w.r.t. to the new name correctly
def replace_text(self, text):
c = self.textCursor()
pos = c.position()

View File

@ -159,6 +159,9 @@ class Editor(QMainWindow):
def init_from_template(self, template):
self.editor.load_text(template, syntax=self.syntax, process_template=True, doc_name=editor_name(self))
def change_document_name(self, newname):
self.editor.change_document_name(newname)
def get_raw_data(self):
# The EPUB spec requires NFC normalization, see section 1.3.6 of
# http://www.idpf.org/epub/20/spec/OPS_2.0.1_draft.htm