mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-18 09:35:20 +02:00
20 lines
604 B
TypeScript
20 lines
604 B
TypeScript
// Helper functions to sync up scrolling
|
|
export default function useScrollUtils(CodeMirror: any) {
|
|
function getScrollHeight(cm: any) {
|
|
const info = cm.getScrollInfo();
|
|
const overdraw = cm.state.scrollPastEndPadding ? cm.state.scrollPastEndPadding : '0px';
|
|
return info.height - info.clientHeight - parseInt(overdraw);
|
|
}
|
|
|
|
CodeMirror.defineExtension('getScrollPercent', function() {
|
|
const info = this.getScrollInfo();
|
|
|
|
return info.top / getScrollHeight(this);
|
|
});
|
|
|
|
CodeMirror.defineExtension('setScrollPercent', function(p: number) {
|
|
this.scrollTo(null, p * getScrollHeight(this));
|
|
});
|
|
|
|
}
|