Skip to content

Commit 429db5a

Browse files
committed
chore: scaled scrolling with line height working but not smooth
1 parent c353621 commit 429db5a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/editor/Editor.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,19 @@ define(function (require, exports, module) {
435435
return $(this.getRootElement());
436436
}
437437
});
438+
439+
const $cmElement = this.$el;
440+
$cmElement[0].addEventListener("wheel", (event) => {
441+
const $editor = $cmElement.find(".CodeMirror-scroll");
442+
// we need to slow down the scroll by the factor of line height. else the scrolling is too fast.
443+
// this became a problem after we added the custom line height feature causing jumping scrolls esp in safari
444+
// and mac if we dont do this scroll scaling.
445+
const lineHeight = parseFloat(getComputedStyle($editor[0]).lineHeight);
446+
const scrollDelta = event.deltaY;
447+
const defaultHeight = 14, scrollScaleFactor = lineHeight/defaultHeight;
448+
$editor[0].scrollTop += (scrollDelta/scrollScaleFactor/2);
449+
event.preventDefault();
450+
});
438451
}
439452

440453
EventDispatcher.makeEventDispatcher(Editor.prototype);

0 commit comments

Comments
 (0)