]> BookStack Code Mirror - bookstack/blobdiff - resources/js/markdown/codemirror.js
Guest create page: name field autofocus
[bookstack] / resources / js / markdown / codemirror.js
index 27491902a1679fd912828cd73ffcaff7e78d4922..8724a23c89e33a04b8e0b700dd6395eeb9beaad0 100644 (file)
@@ -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) => {