From 866b3ecde6be06913f58b13a408292aef726cf7f Mon Sep 17 00:00:00 2001 From: Magnus Ellinge Date: Fri, 5 Apr 2019 12:05:32 +0200 Subject: [PATCH] fix: Code smell --- src/tree-manager/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tree-manager/index.js b/src/tree-manager/index.js index e6450b3d..56a9fffe 100644 --- a/src/tree-manager/index.js +++ b/src/tree-manager/index.js @@ -238,7 +238,12 @@ class TreeManager { return newFocus } - return this.handleToggleNavigationkey(tree, action, currentFocus, readOnly, onToggleChecked, onToggleExpanded) + if (!prevFocus || !tree.has(prevFocus._id)) { + // No current focus or not visible + return currentFocus + } + + return this.handleToggleNavigationkey(action, prevFocus, readOnly, onToggleChecked, onToggleExpanded) } handleFocusNavigationkey(tree, action, prevFocus, markSubTreeOnNonExpanded) { @@ -254,12 +259,7 @@ class TreeManager { return prevFocus && prevFocus._id } - handleToggleNavigationkey(tree, action, currentFocus, readOnly, onToggleChecked, onToggleExpanded) { - const prevFocus = currentFocus && this.getNodeById(currentFocus) - if (!prevFocus || !tree.has(prevFocus._id)) { - // No current focus or not visible - return currentFocus - } + handleToggleNavigationkey = (action, prevFocus, readOnly, onToggleChecked, onToggleExpanded) => { if (action === NavActions.ToggleChecked && !readOnly && !(prevFocus.readOnly || prevFocus.disabled)) { onToggleChecked(prevFocus._id, prevFocus.checked !== true) } else if (action === NavActions.ToggleExpanded) {