Skip to content

Commit 8b61539

Browse files
NickKhalowphilc
authored andcommitted
fix scrolling gets stuck on keyup event of a different key + fix typo
1 parent 09bf520 commit 8b61539

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

content_scripts/scroller.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ const CoreScroller = {
188188
init() {
189189
this.time = 0;
190190
this.lastEvent = this.keyIsDown = null;
191-
this.installCanceEventListener();
191+
this.installCancelEventListener();
192192
},
193193

194194
// This installs listeners for events which should cancel smooth scrolling.
195-
installCanceEventListener() {
195+
installCancelEventListener() {
196196
// NOTE(smblott) With extreme keyboard configurations, Chrome sometimes does not get a keyup
197197
// event for every keydown, in which case tapping "j" scrolls indefinitely. This appears to be a
198198
// Chrome/OS/XOrg bug of some kind. See #1549.
@@ -201,15 +201,17 @@ const CoreScroller = {
201201
_name: "scroller/track-key-status",
202202
keydown: (event) => {
203203
return handlerStack.alwaysContinueBubbling(() => {
204-
this.keyIsDown = true;
204+
this.keyIsDown = event.code;
205205
if (!event.repeat) this.time += 1;
206206
this.lastEvent = event;
207207
});
208208
},
209-
keyup: (_event) => {
209+
keyup: (event) => {
210210
return handlerStack.alwaysContinueBubbling(() => {
211-
this.keyIsDown = false;
212-
this.time += 1;
211+
if (event.code === this.keyIsDown) {
212+
this.keyIsDown = null;
213+
this.time += 1;
214+
}
213215
});
214216
},
215217
blur: (event) => {
@@ -272,7 +274,7 @@ const CoreScroller = {
272274
let totalElapsed = 0.0;
273275
let calibration = 1.0;
274276
let previousTimestamp = null;
275-
const cancelEventListener = this.installCanceEventListener();
277+
const cancelEventListener = this.installCancelEventListener();
276278

277279
const animate = (timestamp) => {
278280
if (previousTimestamp == null) {

0 commit comments

Comments
 (0)