Update editor and highlight, and update tests

This commit is contained in:
Veronica Berglyd Olsen
2024-04-28 18:05:53 +02:00
parent e9596e1bbc
commit e01e14075c
4 changed files with 829 additions and 706 deletions
+25 -28
View File
@@ -39,8 +39,8 @@ from time import time
from typing import TYPE_CHECKING
from PyQt5.QtCore import (
pyqtSignal, pyqtSlot, QObject, QPoint, QRegularExpression, QRunnable, Qt,
QTimer
QObject, QPoint, QRegularExpression, QRunnable, Qt, QTimer, pyqtSignal,
pyqtSlot
)
from PyQt5.QtGui import (
QColor, QCursor, QFont, QKeyEvent, QKeySequence, QMouseEvent, QPalette,
@@ -65,7 +65,7 @@ from novelwriter.text.counting import standardCounter
from novelwriter.tools.lipsum import GuiLipsum
from novelwriter.types import (
QtAlignCenterTop, QtAlignJustify, QtAlignLeft, QtAlignLeftTop,
QtAlignRight, QtKeepAnchor, QtModCtrl, QtMouseLeft, QtModeNone, QtModShift,
QtAlignRight, QtKeepAnchor, QtModCtrl, QtModeNone, QtModShift, QtMouseLeft,
QtMoveAnchor, QtMoveLeft, QtMoveRight
)
@@ -840,14 +840,15 @@ class GuiDocEditor(QPlainTextEdit):
)
return
def insertText(self, insert: str | nwDocInsert) -> bool:
def insertText(self, insert: str | nwDocInsert) -> None:
"""Insert a specific type of text at the cursor position."""
if self._docHandle is None:
logger.error("No document open")
return False
return
newBlock = False
goAfter = False
text = ""
block = False
after = False
if isinstance(insert, str):
text = insert
@@ -862,46 +863,41 @@ class GuiDocEditor(QPlainTextEdit):
text = self._typDQuoteC
elif insert == nwDocInsert.SYNOPSIS:
text = "%Synopsis: "
newBlock = True
goAfter = True
block = True
after = True
elif insert == nwDocInsert.SHORT:
text = "%Short: "
newBlock = True
goAfter = True
block = True
after = True
elif insert == nwDocInsert.NEW_PAGE:
text = "[newpage]"
newBlock = True
goAfter = False
block = True
after = False
elif insert == nwDocInsert.VSPACE_S:
text = "[vspace]"
newBlock = True
goAfter = False
block = True
after = False
elif insert == nwDocInsert.VSPACE_M:
text = "[vspace:2]"
newBlock = True
goAfter = False
block = True
after = False
elif insert == nwDocInsert.LIPSUM:
text = GuiLipsum.getLipsum(self)
newBlock = True
goAfter = False
block = True
after = False
elif insert == nwDocInsert.FOOTNOTE:
text = ""
self._insertCommentStructure(nwComment.FOOTNOTE)
else:
return False
else:
return False
if text:
if newBlock:
self.insertNewBlock(text, defaultAfter=goAfter)
if block:
self.insertNewBlock(text, defaultAfter=after)
else:
cursor = self.textCursor()
cursor.beginEditBlock()
cursor.insertText(text)
cursor.endEditBlock()
return True
return
def insertNewBlock(self, text: str, defaultAfter: bool = True) -> bool:
"""Insert a piece of text on a blank line."""
@@ -1167,7 +1163,8 @@ class GuiDocEditor(QPlainTextEdit):
lambda _, option=option: self._correctWord(sCursor, option)
)
else:
ctxMenu.addAction("%s %s" % (nwUnicode.U_ENDASH, self.tr("No Suggestions")))
trNone = self.tr("No Suggestions")
ctxMenu.addAction(f"{nwUnicode.U_ENDASH} {trNone}")
ctxMenu.addSeparator()
action = ctxMenu.addAction(self.tr("Add Word to Dictionary"))