Skip to content

Commit f155f9f

Browse files
devvaannshabose
authored andcommitted
feat: horizontall scrolling on shift + mouse wheel scroll
1 parent d45757e commit f155f9f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/editor/Editor.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,30 @@ define(function (require, exports, module) {
443443
// this became a problem after we added the custom line height feature causing jumping scrolls esp in safari
444444
// and mac if we dont do this scroll scaling.
445445
const lineHeight = parseFloat(getComputedStyle($editor[0]).lineHeight);
446-
const scrollDelta = event.deltaY;
447446
const defaultHeight = 14, scrollScaleFactor = lineHeight/defaultHeight;
448-
$editor[0].scrollTop += (scrollDelta/scrollScaleFactor);
449-
event.preventDefault();
447+
448+
// when user is pressing the 'Shift' key or deltaX is present, we should handle horizontal scrolling
449+
if (event.shiftKey || event.deltaX !== 0) {
450+
let horizontalDelta = event.deltaX;
451+
452+
if (event.shiftKey && event.deltaY !== 0) {
453+
horizontalDelta = event.deltaY;
454+
}
455+
456+
// apply the horizontal scrolling
457+
if (horizontalDelta !== 0) {
458+
$editor[0].scrollLeft += horizontalDelta;
459+
event.preventDefault();
460+
return;
461+
}
462+
}
463+
464+
// apply the vertical scrolling normally
465+
if (event.deltaY !== 0) {
466+
const scrollDelta = event.deltaY;
467+
$editor[0].scrollTop += (scrollDelta/scrollScaleFactor);
468+
event.preventDefault();
469+
}
450470
});
451471
}
452472

0 commit comments

Comments
 (0)