From db91437cca86043fdd49e8943cda3bdac8eeee83 Mon Sep 17 00:00:00 2001 From: Yichuan Shen Date: Tue, 4 Aug 2015 19:50:19 +0200 Subject: [PATCH] Fix uncaught exception when navigating collapsed trees too fast --- view/index.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/view/index.js b/view/index.js index 50ab72724..6cdf89edd 100644 --- a/view/index.js +++ b/view/index.js @@ -74,22 +74,29 @@ function setCurrentTreePosition(tree, index) { // Set current path var t = tree while (t.parent) { - t.parent.collapsed = false t.parent.current = t.parent.subtrees.indexOf(t) t = t.parent } // Update graph and slider - if (tree.collapsed && index == tree.nodes.length - 1) { - tree.collapsed = false - updateGraph() - } + setTimeout(function() { + if (!new Tuple(tree, index).equals(getCurrentTreePosition())) return - var n = getCurrentGraphNode() + var expanded = false || tree.collapsed && index == tree.nodes.length - 1 + var t = tree - setTimeout(function() { - if (n && getCurrentGraphNode() == n) - centerGraphCameraAt(n) + while (t.parent && t.parent.collapsed) { + expanded = true + t.parent.collapsed = false + t = t.parent + } + + if (expanded) { + tree.collapsed = false + updateGraph() + } + + centerGraphCameraAt(getCurrentGraphNode()) updateSlider() }, setting.get('graph.delay')) @@ -301,7 +308,7 @@ function prepareSlider() { function prepareDragDropFiles() { Element.NativeEvents.dragover = 2 Element.NativeEvents.drop = 2 - + document.body.addEvent('dragover', function() { return false }).addEvent('drop', function(e) {