X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/63d62722825b9ba77f75db531363d29f9dcc6c68..refs/pull/3918/head:/resources/js/markdown/codemirror.js diff --git a/resources/js/markdown/codemirror.js b/resources/js/markdown/codemirror.js index 27491902a..8724a23c8 100644 --- a/resources/js/markdown/codemirror.js +++ b/resources/js/markdown/codemirror.js @@ -23,8 +23,14 @@ export async function init(editor) { cm.on('change', (instance, changeObj) => editor.actions.updateAndRender()); // Handle scroll to sync display view - const onScrollDebounced = debounce(editor.actions.syncDisplayPosition, 100, false); - cm.on('scroll', instance => onScrollDebounced(instance)); + const onScrollDebounced = debounce(editor.actions.syncDisplayPosition.bind(editor.actions), 100, false); + let syncActive = editor.settings.get('scrollSync'); + editor.settings.onChange('scrollSync', val => syncActive = val); + cm.on('scroll', instance => { + if (syncActive) { + onScrollDebounced(instance); + } + }); // Handle image paste cm.on('paste', (cm, event) => {