From 475c964ed94c9503c83515c258a0dfb59303a491 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 15 Jun 2020 10:23:09 +0200 Subject: [PATCH] Allow tracking codemirror's scroll offset within a dedicated input --- wcfsetup/install/files/acp/templates/codemirror.tpl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wcfsetup/install/files/acp/templates/codemirror.tpl b/wcfsetup/install/files/acp/templates/codemirror.tpl index fe7b64c74b..5a27c7e6f7 100644 --- a/wcfsetup/install/files/acp/templates/codemirror.tpl +++ b/wcfsetup/install/files/acp/templates/codemirror.tpl @@ -106,6 +106,17 @@ } }); } + + 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; + }); + } }); }); -- 2.20.1