Skip to content

Commit

Permalink
webenginepreview: Cache zoom factor between tabs and runs
Browse files Browse the repository at this point in the history
Fixes #383.
  • Loading branch information
mitya57 committed Jan 4, 2025
1 parent 4e639e1 commit d3b2c69
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions ReText/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def getBundledIcon(iconName):
'lastTabIndex': 0,
'recentFileList': [],
'splitterState': QByteArray(),
'webEngineZoomFactor': 1.0,
'windowGeometry': QByteArray(),
}

Expand Down
13 changes: 9 additions & 4 deletions ReText/webenginepreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWidgets import QApplication, QLabel

from ReText import globalSettings
from ReText import globalCache, globalSettings
from ReText.editor import getColor
from ReText.syncscroll import SyncScroll

Expand Down Expand Up @@ -236,7 +236,12 @@ def _handleEditorResized(self, rect):

def wheelEvent(self, event):
if QGuiApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier:
zoomFactor = self.zoomFactor()
zoomFactor *= 1.001 ** event.angleDelta().y()
self.setZoomFactor(zoomFactor)
newZoomFactor = globalCache.webEngineZoomFactor * (1.001 ** event.angleDelta().y())
# Valid values are within the range from 0.25 to 5.0.
globalCache.webEngineZoomFactor = max(min(newZoomFactor, 5.0), 0.25)
self.setZoomFactor(globalCache.webEngineZoomFactor)
return super().wheelEvent(event)

def showEvent(self, event):
self.setZoomFactor(globalCache.webEngineZoomFactor)
return super().showEvent(event)
1 change: 1 addition & 0 deletions configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ that are set internally by ReText and should never be set manually:
- `lastTabIndex`
- `recentFileList`
- `splitterState`
- `webEngineZoomFactor`
- `windowGeometry`

Icon themes
Expand Down

0 comments on commit d3b2c69

Please sign in to comment.