From 5dbc88b6f2539c5aaa8ecf91606db76613138c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 27 Aug 2018 15:57:07 +0200 Subject: [PATCH] Detect scrolling direction in terminal Only disable autoscroll if we are scrolling up. --- src/octoprint/static/js/app/viewmodels/terminal.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/terminal.js b/src/octoprint/static/js/app/viewmodels/terminal.js index 1a37ccbe3..cd853fe25 100644 --- a/src/octoprint/static/js/app/viewmodels/terminal.js +++ b/src/octoprint/static/js/app/viewmodels/terminal.js @@ -6,6 +6,7 @@ $(function() { self.settings = parameters[1]; self.tabActive = false; + self.previousScroll = undefined; self.log = ko.observableArray([]); self.log.extend({ throttle: 500 }); @@ -278,14 +279,19 @@ $(function() { }; self.terminalScrollEvent = _.throttle(function () { - if (self.autoscrollEnabled()) { - var container = self.fancyFunctionality() ? $("#terminal-output") : $("#terminal-output-lowfi"); + var container = self.fancyFunctionality() ? $("#terminal-output") : $("#terminal-output-lowfi"); + var pos = container.scrollTop(); + var scrollingUp = self.previousScroll !== undefined && pos < self.previousScroll; + + if (self.autoscrollEnabled() && scrollingUp) { var maxScroll = container[0].scrollHeight - container[0].offsetHeight; - if (container.scrollTop() <= maxScroll ) { + if (pos <= maxScroll ) { self.autoscrollEnabled(false); } } + + self.previousScroll = pos; }, 250); self.gotoTerminalCommand = function() {