From bad88da2fef370146423890c6e13de53ff287a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 2 Dec 2015 18:12:08 +0100 Subject: [PATCH] Fixed a scrolling issue on the terminal tab --- .../static/js/app/viewmodels/terminal.js | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/terminal.js b/src/octoprint/static/js/app/viewmodels/terminal.js index 7be593c6..ba7b0436 100644 --- a/src/octoprint/static/js/app/viewmodels/terminal.js +++ b/src/octoprint/static/js/app/viewmodels/terminal.js @@ -35,7 +35,8 @@ $(function() { var filtered = false; var result = []; - _.each(self.log(), function(entry) { + var lines = self.log(); + _.each(lines, function(entry) { if (lineVisible(entry)) { result.push(entry); filtered = false; @@ -47,14 +48,17 @@ $(function() { return result; }); - self.displayedLines.subscribe(function() { - self.updateOutput(); - }); self.lineCount = ko.computed(function() { - var total = self.log().length; - var filtered = _.filter(self.displayedLines(), function(entry) { return entry.type == "filtered" }).length; - var displayed = _.filter(self.displayedLines(), function(entry) { return entry.type == "line" }).length; + var regex = self.filterRegex(); + var lineVisible = function(entry) { + return regex == undefined || !entry.line.match(regex); + }; + + var lines = self.log(); + var total = lines.length; + var displayed = _.filter(lines, lineVisible).length; + var filtered = total - displayed; if (filtered > 0) { if (total > self.upperLimit()) { @@ -112,10 +116,12 @@ $(function() { newLog = newLog.slice(0, self.upperLimit()); } self.log(newLog); + self.updateOutput(); }; self._processHistoryLogData = function(data) { self.log(_.map(data, function(line) { return self._toInternalFormat(line) })); + self.updateOutput(); }; self._toInternalFormat = function(line, type) { @@ -165,7 +171,7 @@ $(function() { self.scrollToEnd = function() { var container = $("#terminal-output"); if (container.length) { - container.scrollTop(container[0].scrollHeight - container.height()) + container.scrollTop(container[0].scrollHeight); } };