Add current line highlight
This commit is contained in:
+13
-9
@@ -77,15 +77,16 @@ class Config:
|
|||||||
"fmtSQuoteOpen", "focusWidth", "guiFont", "guiLocale", "hasEnchant", "hideFocusFooter",
|
"fmtSQuoteOpen", "focusWidth", "guiFont", "guiLocale", "hasEnchant", "hideFocusFooter",
|
||||||
"hideHScroll", "hideVScroll", "highlightEmph", "hostName", "iconColDocs", "iconColTree",
|
"hideHScroll", "hideVScroll", "highlightEmph", "hostName", "iconColDocs", "iconColTree",
|
||||||
"iconTheme", "incNotesWCount", "isDebug", "kernelVer", "lastNotes", "lightTheme",
|
"iconTheme", "incNotesWCount", "isDebug", "kernelVer", "lastNotes", "lightTheme",
|
||||||
"mainPanePos", "mainWinSize", "memInfo", "narratorBreak", "narratorDialog", "nativeFont",
|
"lineHighlight", "mainPanePos", "mainWinSize", "memInfo", "narratorBreak",
|
||||||
"osDarwin", "osLinux", "osType", "osUnknown", "osWindows", "outlinePanePos",
|
"narratorDialog", "nativeFont", "osDarwin", "osLinux", "osType", "osUnknown", "osWindows",
|
||||||
"prefsWinSize", "scrollPastEnd", "searchCase", "searchLoop", "searchMatchCap",
|
"outlinePanePos", "prefsWinSize", "scrollPastEnd", "searchCase", "searchLoop",
|
||||||
"searchNextFile", "searchProjCase", "searchProjRegEx", "searchProjWord", "searchRegEx",
|
"searchMatchCap", "searchNextFile", "searchProjCase", "searchProjRegEx", "searchProjWord",
|
||||||
"searchWord", "showEditToolBar", "showFullPath", "showLineEndings", "showMultiSpaces",
|
"searchRegEx", "searchWord", "showEditToolBar", "showFullPath", "showLineEndings",
|
||||||
"showSessionTime", "showTabsNSpaces", "showViewerPanel", "spellLanguage", "stopWhenIdle",
|
"showMultiSpaces", "showSessionTime", "showTabsNSpaces", "showViewerPanel",
|
||||||
"tabWidth", "textFont", "textMargin", "textWidth", "themeMode", "useCharCount",
|
"spellLanguage", "stopWhenIdle", "tabWidth", "textFont", "textMargin", "textWidth",
|
||||||
"userIdleTime", "verPyQtString", "verPyQtValue", "verPyString", "verQtString",
|
"themeMode", "useCharCount", "userIdleTime", "verPyQtString", "verPyQtValue",
|
||||||
"verQtValue", "viewComments", "viewPanePos", "viewSynopsis", "welcomeWinSize",
|
"verPyString", "verQtString", "verQtValue", "viewComments", "viewPanePos", "viewSynopsis",
|
||||||
|
"welcomeWinSize",
|
||||||
)
|
)
|
||||||
|
|
||||||
LANG_NW = 1
|
LANG_NW = 1
|
||||||
@@ -191,6 +192,7 @@ class Config:
|
|||||||
self.textMargin = 40 # Editor/viewer text margin
|
self.textMargin = 40 # Editor/viewer text margin
|
||||||
self.tabWidth = 40 # Editor tabulator width
|
self.tabWidth = 40 # Editor tabulator width
|
||||||
self.cursorWidth = 1 # Editor cursor width
|
self.cursorWidth = 1 # Editor cursor width
|
||||||
|
self.lineHighlight = False # Highlight current line in editor
|
||||||
|
|
||||||
self.focusWidth = 800 # Focus Mode text width
|
self.focusWidth = 800 # Focus Mode text width
|
||||||
self.hideFocusFooter = False # Hide document footer in Focus Mode
|
self.hideFocusFooter = False # Hide document footer in Focus Mode
|
||||||
@@ -667,6 +669,7 @@ class Config:
|
|||||||
self.textMargin = conf.rdInt(sec, "margin", self.textMargin)
|
self.textMargin = conf.rdInt(sec, "margin", self.textMargin)
|
||||||
self.tabWidth = conf.rdInt(sec, "tabwidth", self.tabWidth)
|
self.tabWidth = conf.rdInt(sec, "tabwidth", self.tabWidth)
|
||||||
self.cursorWidth = conf.rdInt(sec, "cursorwidth", self.cursorWidth)
|
self.cursorWidth = conf.rdInt(sec, "cursorwidth", self.cursorWidth)
|
||||||
|
self.lineHighlight = conf.rdBool(sec, "linehighlight", self.lineHighlight)
|
||||||
self.focusWidth = conf.rdInt(sec, "focuswidth", self.focusWidth)
|
self.focusWidth = conf.rdInt(sec, "focuswidth", self.focusWidth)
|
||||||
self.hideFocusFooter = conf.rdBool(sec, "hidefocusfooter", self.hideFocusFooter)
|
self.hideFocusFooter = conf.rdBool(sec, "hidefocusfooter", self.hideFocusFooter)
|
||||||
self.doJustify = conf.rdBool(sec, "justify", self.doJustify)
|
self.doJustify = conf.rdBool(sec, "justify", self.doJustify)
|
||||||
@@ -793,6 +796,7 @@ class Config:
|
|||||||
"margin": str(self.textMargin),
|
"margin": str(self.textMargin),
|
||||||
"tabwidth": str(self.tabWidth),
|
"tabwidth": str(self.tabWidth),
|
||||||
"cursorwidth": str(self.cursorWidth),
|
"cursorwidth": str(self.cursorWidth),
|
||||||
|
"lineHighlight": str(self.lineHighlight),
|
||||||
"focuswidth": str(self.focusWidth),
|
"focuswidth": str(self.focusWidth),
|
||||||
"hidefocusfooter": str(self.hideFocusFooter),
|
"hidefocusfooter": str(self.hideFocusFooter),
|
||||||
"justify": str(self.doJustify),
|
"justify": str(self.doJustify),
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ from PyQt6.QtCore import (
|
|||||||
from PyQt6.QtGui import (
|
from PyQt6.QtGui import (
|
||||||
QAction, QCursor, QDragEnterEvent, QDragMoveEvent, QDropEvent, QKeyEvent,
|
QAction, QCursor, QDragEnterEvent, QDragMoveEvent, QDropEvent, QKeyEvent,
|
||||||
QKeySequence, QMouseEvent, QPalette, QPixmap, QResizeEvent, QShortcut,
|
QKeySequence, QMouseEvent, QPalette, QPixmap, QResizeEvent, QShortcut,
|
||||||
QTextBlock, QTextCursor, QTextDocument, QTextOption
|
QTextBlock, QTextCursor, QTextDocument, QTextFormat, QTextOption
|
||||||
)
|
)
|
||||||
from PyQt6.QtWidgets import (
|
from PyQt6.QtWidgets import (
|
||||||
QApplication, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit, QMenu,
|
QApplication, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit, QMenu,
|
||||||
QPlainTextEdit, QToolBar, QVBoxLayout, QWidget
|
QPlainTextEdit, QTextEdit, QToolBar, QVBoxLayout, QWidget
|
||||||
)
|
)
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
@@ -75,7 +75,8 @@ from novelwriter.tools.lipsum import GuiLipsum
|
|||||||
from novelwriter.types import (
|
from novelwriter.types import (
|
||||||
QtAlignCenterTop, QtAlignJustify, QtAlignLeft, QtAlignLeftTop,
|
QtAlignCenterTop, QtAlignJustify, QtAlignLeft, QtAlignLeftTop,
|
||||||
QtAlignRight, QtKeepAnchor, QtModCtrl, QtModNone, QtModShift, QtMouseLeft,
|
QtAlignRight, QtKeepAnchor, QtModCtrl, QtModNone, QtModShift, QtMouseLeft,
|
||||||
QtMoveAnchor, QtMoveLeft, QtMoveRight, QtScrollAlwaysOff, QtScrollAsNeeded
|
QtMoveAnchor, QtMoveLeft, QtMoveRight, QtScrollAlwaysOff, QtScrollAsNeeded,
|
||||||
|
QtTransparent
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -145,6 +146,7 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
self._lastActive = 0.0 # Timestamp of last activity
|
self._lastActive = 0.0 # Timestamp of last activity
|
||||||
self._lastFind = None # Position of the last found search word
|
self._lastFind = None # Position of the last found search word
|
||||||
self._doReplace = False # Switch to temporarily disable auto-replace
|
self._doReplace = False # Switch to temporarily disable auto-replace
|
||||||
|
self._lineColor = QtTransparent
|
||||||
|
|
||||||
# Auto-Replace
|
# Auto-Replace
|
||||||
self._autoReplace = TextAutoReplace()
|
self._autoReplace = TextAutoReplace()
|
||||||
@@ -231,6 +233,9 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
self.updateSyntaxColors()
|
self.updateSyntaxColors()
|
||||||
self.initEditor()
|
self.initEditor()
|
||||||
|
|
||||||
|
# Connect Additional Signal
|
||||||
|
self.cursorPositionChanged.connect(self._highlightCurrentLine)
|
||||||
|
|
||||||
logger.debug("Ready: GuiDocEditor")
|
logger.debug("Ready: GuiDocEditor")
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -315,6 +320,9 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
self.docHeader.matchColors()
|
self.docHeader.matchColors()
|
||||||
self.docFooter.matchColors()
|
self.docFooter.matchColors()
|
||||||
|
|
||||||
|
self._lineColor = self.palette().alternateBase().color()
|
||||||
|
self._lineColor.setAlpha(160)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def initEditor(self) -> None:
|
def initEditor(self) -> None:
|
||||||
@@ -372,6 +380,8 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
# Refresh sizes
|
# Refresh sizes
|
||||||
self.setTabStopDistance(CONFIG.tabWidth)
|
self.setTabStopDistance(CONFIG.tabWidth)
|
||||||
self.setCursorWidth(CONFIG.cursorWidth)
|
self.setCursorWidth(CONFIG.cursorWidth)
|
||||||
|
self.setExtraSelections([])
|
||||||
|
self._highlightCurrentLine()
|
||||||
|
|
||||||
# If we have a document open, we should refresh it in case the
|
# If we have a document open, we should refresh it in case the
|
||||||
# font changed, otherwise we just clear the editor entirely,
|
# font changed, otherwise we just clear the editor entirely,
|
||||||
@@ -1301,6 +1311,18 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
CONFIG.showEditToolBar = state
|
CONFIG.showEditToolBar = state
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def _highlightCurrentLine(self) -> None:
|
||||||
|
"""Highlight the cursor line if setting is enabled."""
|
||||||
|
if CONFIG.lineHighlight:
|
||||||
|
selection = QTextEdit.ExtraSelection()
|
||||||
|
selection.format.setBackground(self._lineColor)
|
||||||
|
selection.format.setProperty(QTextFormat.Property.FullWidthSelection, True)
|
||||||
|
selection.cursor = self.textCursor()
|
||||||
|
selection.cursor.clearSelection()
|
||||||
|
self.setExtraSelections([selection])
|
||||||
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Search & Replace
|
# Search & Replace
|
||||||
##
|
##
|
||||||
|
|||||||
Reference in New Issue
Block a user