mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Comments editor: Fix a regression when switching between normal and source view
This commit is contained in:
parent
7a59f3a024
commit
3e238e8ba7
@ -25,6 +25,7 @@ from calibre.ebooks.chardet import xml_to_unicode
|
|||||||
from calibre.gui2 import NO_URL_FORMATTING, choose_files, error_dialog, gprefs
|
from calibre.gui2 import NO_URL_FORMATTING, choose_files, error_dialog, gprefs
|
||||||
from calibre.gui2.book_details import css
|
from calibre.gui2.book_details import css
|
||||||
from calibre.gui2.widgets import LineEditECM
|
from calibre.gui2.widgets import LineEditECM
|
||||||
|
from calibre.gui2.widgets2 import to_plain_text
|
||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
from polyglot.builtins import filter, iteritems, itervalues, unicode_type
|
from polyglot.builtins import filter, iteritems, itervalues, unicode_type
|
||||||
@ -1138,8 +1139,7 @@ class Editor(QWidget): # {{{
|
|||||||
self.wyswyg_dirty = False
|
self.wyswyg_dirty = False
|
||||||
elif index == 0: # changing to wyswyg
|
elif index == 0: # changing to wyswyg
|
||||||
if self.source_dirty:
|
if self.source_dirty:
|
||||||
from calibre.gui2.tweak_book.widgets import PlainTextEdit
|
self.editor.html = to_plain_text(self.code_edit)
|
||||||
self.editor.html = PlainTextEdit.toPlainText(self.code_edit)
|
|
||||||
self.source_dirty = False
|
self.source_dirty = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -22,14 +22,13 @@ from calibre.ebooks.oeb.polish.cover import get_raster_cover_name
|
|||||||
from calibre.ebooks.oeb.polish.utils import lead_text, guess_type
|
from calibre.ebooks.oeb.polish.utils import lead_text, guess_type
|
||||||
from calibre.gui2 import error_dialog, choose_files, choose_save_file, info_dialog, choose_images
|
from calibre.gui2 import error_dialog, choose_files, choose_save_file, info_dialog, choose_images
|
||||||
from calibre.gui2.tweak_book import tprefs, current_container
|
from calibre.gui2.tweak_book import tprefs, current_container
|
||||||
from calibre.gui2.widgets2 import Dialog as BaseDialog, HistoryComboBox
|
from calibre.gui2.widgets2 import Dialog as BaseDialog, HistoryComboBox, to_plain_text, PARAGRAPH_SEPARATOR
|
||||||
from calibre.utils.icu import primary_sort_key, sort_key, primary_contains, numeric_sort_key
|
from calibre.utils.icu import primary_sort_key, sort_key, primary_contains, numeric_sort_key
|
||||||
from calibre.utils.matcher import get_char, Matcher
|
from calibre.utils.matcher import get_char, Matcher
|
||||||
from calibre.gui2.complete2 import EditWithComplete
|
from calibre.gui2.complete2 import EditWithComplete
|
||||||
from polyglot.builtins import iteritems, unicode_type, zip, getcwd, filter as ignore_me
|
from polyglot.builtins import iteritems, unicode_type, zip, getcwd, filter as ignore_me
|
||||||
|
|
||||||
ROOT = QModelIndex()
|
ROOT = QModelIndex()
|
||||||
PARAGRAPH_SEPARATOR = '\u2029'
|
|
||||||
ignore_me
|
ignore_me
|
||||||
|
|
||||||
|
|
||||||
@ -1199,17 +1198,7 @@ class PlainTextEdit(QPlainTextEdit): # {{{
|
|||||||
self.syntax = None
|
self.syntax = None
|
||||||
|
|
||||||
def toPlainText(self):
|
def toPlainText(self):
|
||||||
# QPlainTextEdit's toPlainText implementation replaces nbsp with normal
|
return to_plain_text(self)
|
||||||
# space, so we re-implement it using QTextCursor, which does not do
|
|
||||||
# that
|
|
||||||
c = self.textCursor()
|
|
||||||
c.clearSelection()
|
|
||||||
c.movePosition(c.Start)
|
|
||||||
c.movePosition(c.End, c.KeepAnchor)
|
|
||||||
ans = c.selectedText().replace(PARAGRAPH_SEPARATOR, '\n')
|
|
||||||
# QTextCursor pads the return value of selectedText with null bytes if
|
|
||||||
# non BMP characters such as 0x1f431 are present.
|
|
||||||
return ans.rstrip('\0')
|
|
||||||
|
|
||||||
def selected_text_from_cursor(self, cursor):
|
def selected_text_from_cursor(self, cursor):
|
||||||
return unicodedata.normalize('NFC', unicode_type(cursor.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0'))
|
return unicodedata.normalize('NFC', unicode_type(cursor.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0'))
|
||||||
|
@ -511,6 +511,23 @@ class ScrollingTabWidget(QTabWidget):
|
|||||||
return QTabWidget.addTab(self, self.wrap_widget(page), *args)
|
return QTabWidget.addTab(self, self.wrap_widget(page), *args)
|
||||||
|
|
||||||
|
|
||||||
|
PARAGRAPH_SEPARATOR = '\u2029'
|
||||||
|
|
||||||
|
|
||||||
|
def to_plain_text(self):
|
||||||
|
# QPlainTextEdit's toPlainText implementation replaces nbsp with normal
|
||||||
|
# space, so we re-implement it using QTextCursor, which does not do
|
||||||
|
# that
|
||||||
|
c = self.textCursor()
|
||||||
|
c.clearSelection()
|
||||||
|
c.movePosition(c.Start)
|
||||||
|
c.movePosition(c.End, c.KeepAnchor)
|
||||||
|
ans = c.selectedText().replace(PARAGRAPH_SEPARATOR, '\n')
|
||||||
|
# QTextCursor pads the return value of selectedText with null bytes if
|
||||||
|
# non BMP characters such as 0x1f431 are present.
|
||||||
|
return ans.rstrip('\0')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from calibre.gui2 import Application
|
from calibre.gui2 import Application
|
||||||
app = Application([])
|
app = Application([])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user