From 2e6a58fb1571dce23063a01f18da1aa3682a7e1f Mon Sep 17 00:00:00 2001
From: Pierre Ossman <ossman@cendio.se>
Date: Fri, 3 Feb 2017 12:00:13 +0100
Subject: [PATCH] Avoid changing scale unless necessary

It causes the browser to redo the layout needlessly otherwise,
having annoying effects like moving the scroll position.
---
 core/display.js | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/core/display.js b/core/display.js
index 5eab796..8da8031 100644
--- a/core/display.js
+++ b/core/display.js
@@ -602,8 +602,14 @@
             //                   style width to a number, the canvas is cleared.
             //                   However, if you set the style width to a string
             //                   ('NNNpx'), the canvas is scaled without clearing.
-            this._target.style.width = Math.round(factor * vp.w) + 'px';
-            this._target.style.height = Math.round(factor * vp.h) + 'px';
+            var width = Math.round(factor * vp.w) + 'px';
+            var height = Math.round(factor * vp.h) + 'px';
+
+            if ((this._target.style.width !== width) ||
+                (this._target.style.height !== height)) {
+                this._target.style.width = width;
+                this._target.style.height = height;
+            }
         },
 
         _setFillColor: function (color) {
-- 
GitLab