Add some more type constants

This commit is contained in:
Veronica Berglyd Olsen
2025-10-04 18:42:20 +02:00
parent 100aad1256
commit 42352e9500
6 changed files with 39 additions and 41 deletions
+6 -5
View File
@@ -42,7 +42,8 @@ from novelwriter.gui.dochighlight import TextBlockData
from novelwriter.text.counting import standardCounter
from novelwriter.types import (
QtAlignJustify, QtAlignLeft, QtKeepAnchor, QtModCtrl, QtModNone,
QtMouseLeft, QtMoveAnchor, QtMoveRight, QtScrollAlwaysOff, QtScrollAsNeeded
QtMouseLeft, QtMoveAnchor, QtMoveRight, QtScrollAlwaysOff,
QtScrollAsNeeded, QtSelectDocument, QtSelectWord
)
from tests.mocked import causeOSError
@@ -58,7 +59,7 @@ def getMenuForPos(editor: GuiDocEditor, pos: int, select: bool = False) -> QMenu
cursor = editor.textCursor()
cursor.setPosition(pos)
if select:
cursor.select(QTextCursor.SelectionType.WordUnderCursor)
cursor.select(QtSelectWord)
editor.setTextCursor(cursor)
editor._openContextFromCursor()
for obj in editor.children():
@@ -1239,7 +1240,7 @@ def testGuiEditor_TextManipulation(qtbot, nwGUI, projPath, ipsumText, mockRnd):
docEditor.setCursorPosition(45)
assert len(docEditor._selectedBlocks(cursor)) == 0
cursor.select(QTextCursor.SelectionType.Document)
cursor.select(QtSelectDocument)
assert len(docEditor._selectedBlocks(cursor)) == 15
# Remove All
@@ -2093,7 +2094,7 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
# Select the Word "est"
docEditor.setCursorPosition(663)
docEditor._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
docEditor._makeSelection(QtSelectWord)
cursor = docEditor.textCursor()
assert cursor.selectedText() == "est"
@@ -2223,7 +2224,7 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, prjLipsum):
# Close search and select "est" again
docSearch.cancelSearch.activate(QAction.ActionEvent.Trigger)
docEditor.setCursorPosition(663)
docEditor._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
docEditor._makeSelection(QtSelectWord)
cursor = docEditor.textCursor()
assert cursor.selectedText() == "est"
+6 -8
View File
@@ -27,7 +27,7 @@ import pytest
from PyQt6.QtCore import QEvent, QMimeData, QPointF, Qt, QUrl
from PyQt6.QtGui import (
QAction, QDesktopServices, QDragEnterEvent, QDragMoveEvent, QDropEvent,
QMouseEvent, QTextCursor
QMouseEvent
)
from PyQt6.QtWidgets import QApplication, QMenu, QTextBrowser
@@ -35,7 +35,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.common import decodeMimeHandles
from novelwriter.enum import nwChange, nwDocAction
from novelwriter.formats.toqdoc import ToQTextDocument
from novelwriter.types import QtModNone, QtMouseLeft, QtMouseMiddle
from novelwriter.types import QtModNone, QtMouseLeft, QtMouseMiddle, QtSelectBlock, QtSelectWord
from tests.mocked import causeException
from tests.tools import C, buildTestProject
@@ -89,7 +89,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
cursor = docViewer.textCursor()
cursor.setPosition(100)
docViewer.setTextCursor(cursor)
docViewer._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
docViewer._makeSelection(QtSelectWord)
clipboard = QApplication.clipboard()
assert clipboard is not None
@@ -117,9 +117,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
cursor.clearSelection()
docViewer.setTextCursor(cursor)
docViewer._makePosSelection(
QTextCursor.SelectionType.BlockUnderCursor, docViewer.cursorRect().center()
)
docViewer._makePosSelection(QtSelectBlock, docViewer.cursorRect().center())
cursor = docViewer.textCursor()
assert cursor.selectedText() == (
"Synopsis: Aenean ut placerat velit. Etiam laoreet ullamcorper risus, "
@@ -159,7 +157,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
cursor = docViewer.textCursor()
cursor.setPosition(27)
docViewer.setTextCursor(cursor)
docViewer._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
docViewer._makeSelection(QtSelectWord)
with monkeypatch.context() as mp:
mp.setattr(QMenu, "exec", mockExec)
docViewer._openContextMenu(docViewer.cursorRect().center())
@@ -169,7 +167,7 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
cursor = docViewer.textCursor()
cursor.setPosition(27)
docViewer.setTextCursor(cursor)
docViewer._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
docViewer._makeSelection(QtSelectWord)
rect = docViewer.cursorRect()
docViewer._linkClicked(QUrl("#tag_bod"))
assert docViewer.docHandle == "4c4f28287af27"
+4 -4
View File
@@ -24,14 +24,14 @@ from unittest.mock import MagicMock
import pytest
from PyQt6.QtGui import QAction, QDesktopServices, QTextBlock, QTextCursor
from PyQt6.QtGui import QAction, QDesktopServices, QTextBlock
from PyQt6.QtWidgets import QFileDialog, QMessageBox
from novelwriter import CONFIG, SHARED
from novelwriter.constants import nwKeyWords, nwShortcode, nwStats, nwUnicode
from novelwriter.enum import nwDocAction, nwDocInsert
from novelwriter.gui.doceditor import GuiDocEditor
from novelwriter.types import QtKeepAnchor, QtMoveRight
from novelwriter.types import QtKeepAnchor, QtMoveRight, QtSelectWord
from tests.tools import C, buildTestProject, writeFile
@@ -188,7 +188,7 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
# Cut, Copy and Paste
docEditor.setCursorPosition(x)
docEditor._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
docEditor._makeSelection(QtSelectWord)
mainMenu.aEditCut.activate(QAction.ActionEvent.Trigger)
assert docEditor.getText()[x:x+50] == (
@@ -201,7 +201,7 @@ def testGuiMainMenu_EditFormat(qtbot, monkeypatch, nwGUI, prjLipsum):
)
docEditor.setCursorPosition(x)
docEditor._makeSelection(QTextCursor.SelectionType.WordUnderCursor)
docEditor._makeSelection(QtSelectWord)
mainMenu.aEditCopy.activate(QAction.ActionEvent.Trigger)
assert docEditor.getText()[x:x+50] == (