From d052b114c0efe1409c5ab9f97d22216d26ff6178 Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Thu, 10 Mar 2016 08:45:13 -0800 Subject: [PATCH] Prevent soft keyboard buttons from causing the page to scroll unnecessarily --- modules/pcjs/lib/cpu.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/pcjs/lib/cpu.js b/modules/pcjs/lib/cpu.js index cc0785b97..00ccf5ee5 100644 --- a/modules/pcjs/lib/cpu.js +++ b/modules/pcjs/lib/cpu.js @@ -517,11 +517,15 @@ CPU.prototype.updateVideo = function(fForce) }; /** - * setFocus() + * setFocus(fScroll) + * + * NOTE: When soft keyboard buttons call us to return focus to the machine (and away from the button), + * the scroll feature has annoying effect on iOS, so we no longer do it by default (fScroll must be true). * * @this {CPU} + * @param {boolean} [fScroll] */ -CPU.prototype.setFocus = function() +CPU.prototype.setFocus = function(fScroll) { if (this.aVideo.length) { /* @@ -530,12 +534,12 @@ CPU.prototype.setFocus = function() * is to ensure that keyboard input is fielded properly. */ var x = 0, y = 0; - if (window) { + if (fScroll && window) { x = window.scrollX; y = window.scrollY; } this.aVideo[0].setFocus(); - if (window) { + if (fScroll && window) { window.scrollTo(x, y); } } @@ -1127,7 +1131,7 @@ CPU.prototype.startCPU = function(fSetFocus) var controlRun = this.bindings["run"]; if (controlRun) controlRun.textContent = "Halt"; this.updateStatus(true); - if (fSetFocus) this.setFocus(); + if (fSetFocus) this.setFocus(true); } };