Skip to content

Commit d3b2c69

Browse files
committed
webenginepreview: Cache zoom factor between tabs and runs
Fixes #383.
1 parent 4e639e1 commit d3b2c69

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

ReText/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def getBundledIcon(iconName):
9494
'lastTabIndex': 0,
9595
'recentFileList': [],
9696
'splitterState': QByteArray(),
97+
'webEngineZoomFactor': 1.0,
9798
'windowGeometry': QByteArray(),
9899
}
99100

ReText/webenginepreview.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from PyQt6.QtWebEngineWidgets import QWebEngineView
3636
from PyQt6.QtWidgets import QApplication, QLabel
3737

38-
from ReText import globalSettings
38+
from ReText import globalCache, globalSettings
3939
from ReText.editor import getColor
4040
from ReText.syncscroll import SyncScroll
4141

@@ -236,7 +236,12 @@ def _handleEditorResized(self, rect):
236236

237237
def wheelEvent(self, event):
238238
if QGuiApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier:
239-
zoomFactor = self.zoomFactor()
240-
zoomFactor *= 1.001 ** event.angleDelta().y()
241-
self.setZoomFactor(zoomFactor)
239+
newZoomFactor = globalCache.webEngineZoomFactor * (1.001 ** event.angleDelta().y())
240+
# Valid values are within the range from 0.25 to 5.0.
241+
globalCache.webEngineZoomFactor = max(min(newZoomFactor, 5.0), 0.25)
242+
self.setZoomFactor(globalCache.webEngineZoomFactor)
242243
return super().wheelEvent(event)
244+
245+
def showEvent(self, event):
246+
self.setZoomFactor(globalCache.webEngineZoomFactor)
247+
return super().showEvent(event)

configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ that are set internally by ReText and should never be set manually:
6262
- `lastTabIndex`
6363
- `recentFileList`
6464
- `splitterState`
65+
- `webEngineZoomFactor`
6566
- `windowGeometry`
6667

6768
Icon themes

0 commit comments

Comments
 (0)