commit e3947e7b45bc433b4cb8d10a647c49e42231d48b
parent eb1cecf404b224c6fd5953d043c777dea3a377dd
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 25 Jul 2017 02:30:44 -0400
Debug output viewer tweaks
- Decrease font size
- Do a better job of pinning to bottom
- Disable submit button when clearing output
- Filter ANSI color codes from slow lines
Diffstat:
3 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/chrome/content/zotero/debugViewer.html b/chrome/content/zotero/debugViewer.html
@@ -55,7 +55,7 @@
margin-top: 38px;
padding: 10px 9px;
font-family: Monaco, Consolas, Inconsolata, monospace;
- font-size: 9pt;
+ font-size: 8pt;
}
#errors {
diff --git a/chrome/content/zotero/debugViewer.js b/chrome/content/zotero/debugViewer.js
@@ -3,8 +3,18 @@
var interval = 1000;
var intervalID;
var stopping = false;
+var scrolling = false;
+var autoscroll = true;
function start() {
+ // If scrolled to the bottom of the page, stay there
+ document.body.onscroll = function (event) {
+ if (!scrolling) {
+ autoscroll = atPageBottom();
+ }
+ scrolling = false;
+ };
+
updateErrors().then(function () {
if (stopping) return;
@@ -31,13 +41,9 @@ function updateErrors() {
var errors = Zotero.getErrors(true);
var errorStr = errors.length ? errors.join('\n\n') + '\n\n' : '';
- var scroll = atPageBottom();
-
document.getElementById('errors').textContent = errorStr + sysInfo;
- // TODO: This doesn't seem to work for some reason -- when errors are logged, it doesn't stay
- // at the bottom
- if (scroll) {
+ if (autoscroll) {
scrollToPageBottom();
}
});
@@ -50,15 +56,12 @@ function addInitialOutput() {
}
function addLine(line) {
- var scroll = atPageBottom()
-
var p = document.createElement('p');
p.textContent = line;
var output = document.getElementById('output');
output.appendChild(p);
- // If scrolled to the bottom of the page, stay there
- if (scroll) {
+ if (autoscroll) {
scrollToPageBottom();
}
@@ -71,6 +74,8 @@ function atPageBottom() {
}
function scrollToPageBottom() {
+ // Set a flag when auto-scrolling to differentiate from manual scrolls
+ scrolling = true;
window.scrollTo(0, document.body.scrollHeight);
}
@@ -180,6 +185,7 @@ function clearSubmitStatus() {
}
function clearOutput(button) {
+ document.getElementById('submit-button').setAttribute('disabled', '');
button.setAttribute('disabled', '');
document.getElementById('output').textContent = '';
clearSubmitStatus();
diff --git a/chrome/content/zotero/xpcom/debug.js b/chrome/content/zotero/xpcom/debug.js
@@ -151,6 +151,13 @@ Zotero.Debug = new function () {
}
// Console window
if (_consoleViewer) {
+ // Remove ANSI color codes. We could replace this with HTML, but it's probably
+ // unnecessarily distracting/alarming to show the red in the viewer. Devs who care
+ // about times should just use a terminal.
+ if (slowPrefix) {
+ output = output.replace(slowPrefix, '').replace(slowSuffix, '');
+ }
+
// If there's a listener, pass line immediately
if (_consoleViewerListener) {
_consoleViewerListener(output);