From 869bda649597a5b57f83862e3d93f84d98c62f5f Mon Sep 17 00:00:00 2001 From: Sean Lip Date: Thu, 21 Jul 2016 17:12:10 -0700 Subject: [PATCH] Autoscroll to the current node when the active desc changes. --- accessible/tree.service.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/accessible/tree.service.js b/accessible/tree.service.js index b2430aee8..077d062a7 100644 --- a/accessible/tree.service.js +++ b/accessible/tree.service.js @@ -144,6 +144,16 @@ blocklyApp.TreeService = ng.core this.unmarkActiveDesc_(this.getActiveDescId(treeId)); this.markActiveDesc_(newActiveDescId); this.activeDescendantIds_[treeId] = newActiveDescId; + + // Scroll the new active desc into view, if needed. This has no effect + // for blind users, but is helpful for sighted onlookers. + var activeDescNode = document.getElementById(newActiveDescId); + var documentNode = document.body || document.documentElement; + if (activeDescNode.offsetTop < documentNode.scrollTop || + activeDescNode.offsetTop > + documentNode.scrollTop + window.innerHeight) { + window.scrollTo(0, activeDescNode.offsetTop); + } }, getTreeIdForBlock: function(blockId) { // Walk up the DOM until we get to the root node of the tree.