Allow tracking codemirror's scroll offset within a dedicated input
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Jun 2020 08:23:09 +0000 (10:23 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 15 Jun 2020 08:23:09 +0000 (10:23 +0200)
wcfsetup/install/files/acp/templates/codemirror.tpl

index fe7b64c74b73050e7ebc91688a31b131f1bdf342..5a27c7e6f730bdf61ad8e54d10af8edd06059982 100644 (file)
                                        }
                                });
                        }
+                       
+                       var scrollOffsetStorage = element;
+                       do {
+                               scrollOffsetStorage = scrollOffsetStorage.nextElementSibling;
+                       } while (scrollOffsetStorage && !scrollOffsetStorage.classList.contains('codeMirrorScrollOffset'));
+                       if (scrollOffsetStorage) {
+                               element.codemirror.scrollTo(null, scrollOffsetStorage.value);
+                               element.codemirror.on('scroll', function (cm) {
+                                       scrollOffsetStorage.value = cm.getScrollInfo().top;
+                               });
+                       }
                });
        });
 </script>