From 8617da29f9c5d54ee305c1fc4b0b890975280796 Mon Sep 17 00:00:00 2001
From: Bruce Toll <btoll@dhsus.com>
Date: Sun, 8 Dec 2019 15:57:40 -0500
Subject: [PATCH] Additional logging for WTableView scrollTo issue

---
 src/js/WTableView.js | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/js/WTableView.js b/src/js/WTableView.js
index 8892ed75..df032300 100644
--- a/src/js/WTableView.js
+++ b/src/js/WTableView.js
@@ -44,24 +44,31 @@ WT_DECLARE_WT_MEMBER
    var scrollTop = 0, scrollLeft = 0, currentWidth = 0, currentHeight = 0;
 
    function maybeEmitScrolled() {
+console.log("maybeEmitScrolled [" + contentsContainer.id + "]: called: scrollToPendingCount: " + scrollToPendingCount);
      if (contentsContainer.clientWidth && contentsContainer.clientHeight
          && (scrollToPendingCount === 0)
          && (contentsContainer.scrollTop < scrollY1
      || contentsContainer.scrollTop > scrollY2
      || contentsContainer.scrollLeft < scrollX1
      || contentsContainer.scrollLeft > scrollX2)) {
+console.log("maybeEmitScrolled [" + contentsContainer.id + "]: emitting scrolled: scrollTop: " + Math.round(contentsContainer.scrollTop));
        APP.emit(el, 'scrolled',
         Math.round(rtlScrollLeft(contentsContainer)),
             Math.round(contentsContainer.scrollTop),
         Math.round(contentsContainer.clientWidth),
             Math.round(contentsContainer.clientHeight));
      }
-   }
+     else {
+console.log("maybeEmitScrolled: [" + contentsContainer.id + "]: not emitting, previous ignoreScrollEvent: " + ignoreScrollEvent);
+     }
+   };
 
    headerContainer.onscroll = function(obj, event) {
      if (ignoreScrollEvent) {
        ignoreScrollEvent = false;
+console.log("headerContainer.onscroll [" + contentsContainer.id + "]: ignoring scrollevent, scrollToPendingCount: " + scrollToPendingCount);
      } else {
+console.log("headerContainer.onscroll [" + contentsContainer.id + "]: handling scrollevent, scrollToPendingCount: " + scrollToPendingCount);
        ignoreScrollEvent = true;
        scrollLeft = contentsContainer.scrollLeft = headerContainer.scrollLeft;
        maybeEmitScrolled();
@@ -71,8 +78,10 @@ WT_DECLARE_WT_MEMBER
    this.onContentsContainerScroll = function() {
      if (ignoreScrollEvent) {
        ignoreScrollEvent = false;
+console.log("OnContentsContainerScroll [" + contentsContainer.id + "]: ignoring scrollevent, scrollToPendingCount: " + scrollToPendingCount + ", contentsContainer.scrollTop: " + contentsContainer.scrollTop + ", scrollTop: " + scrollTop);
      } else {
        ignoreScrollEvent = true;
+console.log("OnContentsContainerScroll [" + contentsContainer.id + "]: handling scrollevent, scrollToPendingCount: " + scrollToPendingCount + ", contentsContainer.scrollTop: " + contentsContainer.scrollTop + ", scrollTop: " + scrollTop);;
        scrollLeft = headerContainer.scrollLeft
              = contentsContainer.scrollLeft;
        scrollTop = headerColumnsContainer.scrollTop
@@ -82,6 +91,7 @@ WT_DECLARE_WT_MEMBER
    };
 
    contentsContainer.wtResize = function(o, w, h, setSize) {
+console.log("contentsContainer [" + contentsContainer.id + "]: wtResize called: o:" + o.id + ", w: " + w + ", h: " + h + ", setSize: " + setSize + ", initialScrollTopSet: " + initialScrollTopSet + ", initialScrollTop: " + initialScrollTop);
      if (!initialScrollTopSet) {
        o.scrollTop = initialScrollTop;
        o.onscroll();
@@ -93,6 +103,7 @@ WT_DECLARE_WT_MEMBER
        var height = o.clientHeight == o.firstChild.offsetHeight
          ? -1
          : o.clientHeight;
+console.log("wtResize [" + contentsContainer.id + "]: emitting scrolled: scrollTop: " + Math.round(o.scrollTop));
        APP.emit(el, 'scrolled',
         Math.round(rtlScrollLeft(o)),
         Math.round(o.scrollTop),
@@ -312,6 +323,7 @@ WT_DECLARE_WT_MEMBER
    };
 
    this.scrolled = function(X1, X2, Y1, Y2) {
+console.log("scrolled called[" + contentsContainer.id + "]: X1: " + X1 + ", X2: " + X2 + ", Y1: " + Y1 + ", Y2: " + Y2);
      scrollX1 = X1;
      scrollX2 = X2;
      scrollY1 = Y1;
@@ -319,6 +331,7 @@ WT_DECLARE_WT_MEMBER
    };
 
    this.resetScroll = function() {
+console.log("resetScroll called[" + contentsContainer.id + "]: contentsContainer.scrollTop: " + contentsContainer.scrollTop + ", scrollTop: " + scrollTop);
      headerContainer.scrollLeft = scrollLeft;
      contentsContainer.scrollLeft = scrollLeft;
      contentsContainer.scrollTop = scrollTop;
@@ -336,6 +349,7 @@ WT_DECLARE_WT_MEMBER
    };
 
    this.scrollTo = function(x, y, hint) {
+console.log("scrollTo called[" + contentsContainer.id + "]: x: " + x + ", y: " + y + ", hint: " + hint + ", scrollToPendingCount: " + scrollToPendingCount);
      if (scrollToPendingCount > 0)
        scrollToPendingCount -= 1;
      if (y != -1) {
@@ -357,6 +371,7 @@ WT_DECLARE_WT_MEMBER
          contentsContainer.scrollTop = y - (height - rowHeight())/2; break;
        }
 
+console.log("scrollTo [" + contentsContainer.id + "]: calling contentsContainer.onscroll()");
        contentsContainer.onscroll();
      }
    };
@@ -527,6 +542,7 @@ WT_DECLARE_WT_MEMBER
      headerContainer.scrollLeft = contentsContainer.scrollLeft
        = scrollLeft;
        }
+console.log("autoJavaScript [" + contentsContainer.id + "]: setting contentsContainer.scrollTop from: " + contentsContainer.scrollTop + ", to: " + scrollTop);
        headerColumnsContainer.scrollTop = contentsContainer.scrollTop
      = scrollTop;
      }
-- 
2.19.2

