/pidgin/main: e5b703bc9f03: Fix autoscroll in debug window.

Elliott Sales de Andrade qulogic at pidgin.im
Thu May 9 02:56:35 EDT 2013


Changeset: e5b703bc9f03b74c904d762b9691235b44fed159
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2013-05-08 05:17 -0400
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/e5b703bc9f03

Description:

Fix autoscroll in debug window.

Also, attempt to do sane things when clearing the filter, and
resuming from paused output.

diffstat:

 pidgin/gtkdebug.c    |   1 -
 pidgin/gtkdebug.html |  26 ++++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletions(-)

diffs (87 lines):

diff --git a/pidgin/gtkdebug.c b/pidgin/gtkdebug.c
--- a/pidgin/gtkdebug.c
+++ b/pidgin/gtkdebug.c
@@ -604,7 +604,6 @@ debug_window_new(void)
 	frame = pidgin_create_webview(FALSE, &win->text, NULL, NULL);
 	gtk_webview_set_format_functions(GTK_WEBVIEW(win->text),
 	                                 GTK_WEBVIEW_ALL ^ GTK_WEBVIEW_SMILEY ^ GTK_WEBVIEW_IMAGE);
-	gtk_webview_set_autoscroll(GTK_WEBVIEW(win->text), TRUE);
 	gtk_webview_load_html_string(GTK_WEBVIEW(win->text), gtkdebug_html);
 	gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
 	gtk_widget_show(frame);
diff --git a/pidgin/gtkdebug.html b/pidgin/gtkdebug.html
--- a/pidgin/gtkdebug.html
+++ b/pidgin/gtkdebug.html
@@ -21,9 +21,19 @@
 		span.regex{background-color:#ffafaf;font-weight:bold;}
 	</style>
 	<script>
+		function nearBottom() {
+			return ( document.body.scrollTop >= ( document.body.offsetHeight - ( window.innerHeight * 1.5 ) ) );
+		}
+
+		function scrollToBottom() {
+			document.body.scrollTop = document.body.offsetHeight;
+		}
+
 		regex = {
 			clear: function () {
 				var list, i;
+				var scroll = nearBottom();
+
 				/* Remove highlighting SPANs */
 				list = document.getElementsByClassName('regex');
 				i = list.length;
@@ -42,6 +52,8 @@
 					list[i].classList.remove('hide');
 				}
 
+				if (scroll)
+					scrollToBottom();
 				this.enabled = false;
 			},
 
@@ -186,17 +198,25 @@
 		function append(level, time, cat, msg) {
 			var div = document.createElement('div');
 			div.className = 'l' + level;
+
 			div.appendChild(document.createTextNode('(' + time + ') '));
+
 			if (cat) {
 				var cat_n = document.createElement('b');
 				cat_n.appendChild(document.createTextNode(cat + ':'));
 				div.appendChild(cat_n);
 				div.appendChild(document.createTextNode(' '));
 			}
+
 			div.appendChild(document.createTextNode(msg));
+
 			if (regex.enabled)
 				regex.match(div);
+
+			var scroll = nearBottom();
 			document.body.appendChild(div);
+			if (scroll)
+				scrollToBottom();
 		}
 
 		function clear() {
@@ -212,11 +232,17 @@
 			if (pause) {
 				var parent = pause.parentNode;
 				parent.removeChild(pause);
+				scrollToBottom();
 			}
 		}
 
 		function setFilterLevel(l) {
+			var scroll = nearBottom();
+
 			document.body.className = 'l'+l;
+
+			if (scroll)
+				scrollToBottom();
 		}
 	</script>
 	</head>



More information about the Commits mailing list