Make the editor a plain text editor again
This commit is contained in:
@@ -42,11 +42,13 @@ from PyQt5.QtCore import (
|
||||
)
|
||||
from PyQt5.QtGui import (
|
||||
QColor, QCursor, QFont, QFontMetrics, QKeyEvent, QKeySequence, QMouseEvent,
|
||||
QPalette, QPixmap, QResizeEvent, QTextBlock, QTextCursor, QTextDocument, QTextOption
|
||||
QPalette, QPixmap, QResizeEvent, QTextBlock, QTextCursor, QTextDocument,
|
||||
QTextOption
|
||||
)
|
||||
from PyQt5.QtWidgets import (
|
||||
QAction, qApp, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit, QMenu,
|
||||
QPushButton, QShortcut, QTextEdit, QToolBar, QToolButton, QWidget
|
||||
QAction, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit, QMenu,
|
||||
QPlainTextEdit, QPushButton, QShortcut, QToolBar, QToolButton, QWidget,
|
||||
qApp
|
||||
)
|
||||
|
||||
from novelwriter import CONFIG, SHARED
|
||||
@@ -63,7 +65,7 @@ if TYPE_CHECKING: # pragma: no cover
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GuiDocEditor(QTextEdit):
|
||||
class GuiDocEditor(QPlainTextEdit):
|
||||
"""Gui Widget: Main Document Editor"""
|
||||
|
||||
MOVE_KEYS = (
|
||||
@@ -141,7 +143,6 @@ class GuiDocEditor(QTextEdit):
|
||||
|
||||
# Editor Settings
|
||||
self.setMinimumWidth(CONFIG.pxInt(300))
|
||||
self.setAcceptRichText(False)
|
||||
self.setAutoFillBackground(True)
|
||||
self.setFrameStyle(QFrame.NoFrame)
|
||||
|
||||
@@ -678,9 +679,9 @@ class GuiDocEditor(QTextEdit):
|
||||
|
||||
lineIdx = line - 1 # Block index is 0 offset, lineNo is 1 offset
|
||||
if lineIdx >= 0:
|
||||
theBlock = self.document().findBlockByLineNumber(lineIdx)
|
||||
if theBlock:
|
||||
self.setCursorPosition(theBlock.position())
|
||||
block = self.document().findBlockByNumber(lineIdx)
|
||||
if block:
|
||||
self.setCursorPosition(block.position())
|
||||
logger.debug("Cursor moved to line %d", line)
|
||||
|
||||
return True
|
||||
|
||||
@@ -44,7 +44,7 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
|
||||
buildTestProject(nwGUI, projPath)
|
||||
assert nwGUI.openDocument(C.hSceneDoc)
|
||||
|
||||
nwGUI.docEditor.setText("### Lorem Ipsum\n\n%s" % ipsumText[0])
|
||||
nwGUI.docEditor.setPlainText("### Lorem Ipsum\n\n%s" % ipsumText[0])
|
||||
assert nwGUI.saveDocument()
|
||||
|
||||
# Check Defaults
|
||||
|
||||
@@ -212,7 +212,7 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
# ==================
|
||||
|
||||
cleanText = "A single, short paragraph.\n\n"
|
||||
nwGUI.docEditor.setText(cleanText)
|
||||
nwGUI.docEditor.setPlainText(cleanText)
|
||||
assert nwGUI.docEditor.setCursorPosition(0)
|
||||
|
||||
# Left Align
|
||||
@@ -247,7 +247,7 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
# Other Checks
|
||||
|
||||
# Replace Quotes
|
||||
nwGUI.docEditor.setText((
|
||||
nwGUI.docEditor.setPlainText((
|
||||
"### New Text\n\n"
|
||||
"Text with 'single' quotes and 'tricky stuff's'.\n\n"
|
||||
"Also text with \"double\" quotes which are \"less tricky\".\n\n"
|
||||
@@ -270,7 +270,7 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
)
|
||||
|
||||
# Remove in-paragraph line breaks
|
||||
nwGUI.docEditor.setText((
|
||||
nwGUI.docEditor.setPlainText((
|
||||
"### New Text\n\n"
|
||||
"@char: Someone\n"
|
||||
"@location: Somewhere\n\n"
|
||||
@@ -288,7 +288,7 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
"With another paragraph here.\n"
|
||||
)
|
||||
|
||||
nwGUI.docEditor.setText((
|
||||
nwGUI.docEditor.setPlainText((
|
||||
"### New Text\n\n"
|
||||
"@char: Someone\n"
|
||||
"@location: Somewhere\n\n"
|
||||
@@ -314,7 +314,7 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
|
||||
assert not nwGUI.docEditor.docAction(nwDocAction.NO_ACTION)
|
||||
|
||||
# Test Invalid Formats
|
||||
nwGUI.docEditor.setText((
|
||||
nwGUI.docEditor.setPlainText((
|
||||
"### New Text\n\n"
|
||||
"@tag: Bod\n\n"
|
||||
"Text with 'single' quotes and 'tricky stuff's'.\n\n"
|
||||
@@ -541,43 +541,43 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd):
|
||||
# Insert Keywords
|
||||
# ===============
|
||||
|
||||
nwGUI.docEditor.setText("Stuff")
|
||||
nwGUI.docEditor.setPlainText("Stuff")
|
||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.TAG_KEY][0].activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.TAG_KEY
|
||||
|
||||
nwGUI.docEditor.setText("Stuff")
|
||||
nwGUI.docEditor.setPlainText("Stuff")
|
||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.POV_KEY][0].activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.POV_KEY
|
||||
|
||||
nwGUI.docEditor.setText("Stuff")
|
||||
nwGUI.docEditor.setPlainText("Stuff")
|
||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.FOCUS_KEY][0].activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.FOCUS_KEY
|
||||
|
||||
nwGUI.docEditor.setText("Stuff")
|
||||
nwGUI.docEditor.setPlainText("Stuff")
|
||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.CHAR_KEY][0].activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.CHAR_KEY
|
||||
|
||||
nwGUI.docEditor.setText("Stuff")
|
||||
nwGUI.docEditor.setPlainText("Stuff")
|
||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.PLOT_KEY][0].activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.PLOT_KEY
|
||||
|
||||
nwGUI.docEditor.setText("Stuff")
|
||||
nwGUI.docEditor.setPlainText("Stuff")
|
||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.TIME_KEY][0].activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.TIME_KEY
|
||||
|
||||
nwGUI.docEditor.setText("Stuff")
|
||||
nwGUI.docEditor.setPlainText("Stuff")
|
||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.WORLD_KEY][0].activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.WORLD_KEY
|
||||
|
||||
nwGUI.docEditor.setText("Stuff")
|
||||
nwGUI.docEditor.setPlainText("Stuff")
|
||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.OBJECT_KEY][0].activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.OBJECT_KEY
|
||||
|
||||
nwGUI.docEditor.setText("Stuff")
|
||||
nwGUI.docEditor.setPlainText("Stuff")
|
||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.ENTITY_KEY][0].activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.ENTITY_KEY
|
||||
|
||||
nwGUI.docEditor.setText("Stuff")
|
||||
nwGUI.docEditor.setPlainText("Stuff")
|
||||
nwGUI.mainMenu.mInsKWItems[nwKeyWords.CUSTOM_KEY][0].activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n%s: " % nwKeyWords.CUSTOM_KEY
|
||||
|
||||
@@ -592,22 +592,22 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd):
|
||||
# Insert Special Comments
|
||||
# =======================
|
||||
|
||||
nwGUI.docEditor.setText("Stuff\n")
|
||||
nwGUI.docEditor.setPlainText("Stuff\n")
|
||||
nwGUI.mainMenu.aInsSynopsis.activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "Stuff\n% Synopsis: \n"
|
||||
|
||||
# Insert Break or Space
|
||||
# =====================
|
||||
|
||||
nwGUI.docEditor.setText("### Stuff\n")
|
||||
nwGUI.docEditor.setPlainText("### Stuff\n")
|
||||
nwGUI.mainMenu.aInsNewPage.activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "[NEW PAGE]\n### Stuff\n"
|
||||
|
||||
nwGUI.docEditor.setText("### Stuff\n")
|
||||
nwGUI.docEditor.setPlainText("### Stuff\n")
|
||||
nwGUI.mainMenu.aInsVSpaceS.activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "[VSPACE]\n### Stuff\n"
|
||||
|
||||
nwGUI.docEditor.setText("### Stuff\n")
|
||||
nwGUI.docEditor.setPlainText("### Stuff\n")
|
||||
nwGUI.mainMenu.aInsVSpaceM.activate(QAction.Trigger)
|
||||
assert nwGUI.docEditor.getText() == "[VSPACE:2]\n### Stuff\n"
|
||||
|
||||
@@ -637,7 +637,7 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd):
|
||||
|
||||
# Open the document from before, and add some text to it
|
||||
nwGUI.openDocument(C.hSceneDoc)
|
||||
nwGUI.docEditor.setText("Bar")
|
||||
nwGUI.docEditor.setPlainText("Bar")
|
||||
assert nwGUI.docEditor.getText() == "Bar"
|
||||
|
||||
# The document isn't empty, so the message box should pop
|
||||
|
||||
Reference in New Issue
Block a user