mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Do not change the current selected text when right clicking on a mis-spelled word
This commit is contained in:
parent
26f188c574
commit
9229cdc402
@ -247,8 +247,8 @@ class TextEdit(PlainTextEdit):
|
|||||||
self.setTextCursor(c)
|
self.setTextCursor(c)
|
||||||
self.ensureCursorVisible()
|
self.ensureCursorVisible()
|
||||||
|
|
||||||
def simple_replace(self, text):
|
def simple_replace(self, text, cursor=None):
|
||||||
c = self.textCursor()
|
c = cursor or self.textCursor()
|
||||||
c.insertText(unicodedata.normalize('NFC', text))
|
c.insertText(unicodedata.normalize('NFC', text))
|
||||||
self.setTextCursor(c)
|
self.setTextCursor(c)
|
||||||
|
|
||||||
|
@ -443,8 +443,9 @@ class Editor(QMainWindow):
|
|||||||
a = m.addAction
|
a = m.addAction
|
||||||
c = self.editor.cursorForPosition(pos)
|
c = self.editor.cursorForPosition(pos)
|
||||||
origc = QTextCursor(c)
|
origc = QTextCursor(c)
|
||||||
|
current_cursor = self.editor.textCursor()
|
||||||
r = origr = self.editor.syntax_range_for_cursor(c)
|
r = origr = self.editor.syntax_range_for_cursor(c)
|
||||||
if (r is None or not r.format.property(SPELL_PROPERTY)) and c.positionInBlock() > 0:
|
if (r is None or not r.format.property(SPELL_PROPERTY)) and c.positionInBlock() > 0 and not current_cursor.hasSelection():
|
||||||
c.setPosition(c.position() - 1)
|
c.setPosition(c.position() - 1)
|
||||||
r = self.editor.syntax_range_for_cursor(c)
|
r = self.editor.syntax_range_for_cursor(c)
|
||||||
|
|
||||||
@ -460,11 +461,16 @@ class Editor(QMainWindow):
|
|||||||
fc = self.editor.textCursor()
|
fc = self.editor.textCursor()
|
||||||
if fc.position() < c.position():
|
if fc.position() < c.position():
|
||||||
self.editor.find_spell_word([word], locale.langcode, center_on_cursor=False)
|
self.editor.find_spell_word([word], locale.langcode, center_on_cursor=False)
|
||||||
|
spell_cursor = self.editor.textCursor()
|
||||||
|
if current_cursor.hasSelection():
|
||||||
|
# Restore the current cursor so that any selection is preserved
|
||||||
|
# for the change case actions
|
||||||
|
self.editor.setTextCursor(current_cursor)
|
||||||
if found:
|
if found:
|
||||||
suggestions = dictionaries.suggestions(word, locale)[:7]
|
suggestions = dictionaries.suggestions(word, locale)[:7]
|
||||||
if suggestions:
|
if suggestions:
|
||||||
for suggestion in suggestions:
|
for suggestion in suggestions:
|
||||||
ac = m.addAction(suggestion, partial(self.editor.simple_replace, suggestion))
|
ac = m.addAction(suggestion, partial(self.editor.simple_replace, suggestion, cursor=spell_cursor))
|
||||||
f = ac.font()
|
f = ac.font()
|
||||||
f.setBold(True), ac.setFont(f)
|
f.setBold(True), ac.setFont(f)
|
||||||
m.addSeparator()
|
m.addSeparator()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user