From 03d4fd9a95f37af037c5a26db1e15d5e070bdec3 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sun, 22 Feb 2015 21:18:46 -0500 Subject: [PATCH] Make sure a window isn't selected when C or P is pressed --- popup.js | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/popup.js b/popup.js index a6a1d0d..6d10da3 100644 --- a/popup.js +++ b/popup.js @@ -429,32 +429,36 @@ document.addEventListener('DOMContentLoaded', function() { } //Close when c is pressed else if (event.keyCode===67){ - tabList[tabKeyIndex].querySelector('i.close').click(); - //Move the selection after pressing c. - //Check to make sure we're not leaving the bounds of the list - if (tabKeyIndex-1>0){ - tabKeyIndex-=1; - } - //If we're closing a window with only one tab left, move to the previous list. - if (tabList.length===0){ - //Remove the list from the popup - //If we're at the front of the list, we move to the window below it. - if (windowKeyIndex===0){ - tabList = createTabList(mainList, windowKeyIndex); - tabKeyIndex=0; + if (tabKeyIndex>0){ + tabList[tabKeyIndex].querySelector('i.close').click(); + //Move the selection after pressing c. + //Check to make sure we're not leaving the bounds of the list + if (tabKeyIndex-1>0){ + tabKeyIndex-=1; } - //Otherwise, we move up one. - if (windowKeyIndex>0){ - windowKeyIndex-=1; - tabList = createTabList(mainList, windowKeyIndex); - tabKeyIndex=tabList.length-1; - } + //If we're closing a window with only one tab left, move to the previous list. + if (tabList.length===0){ + //Remove the list from the popup + //If we're at the front of the list, we move to the window below it. + if (windowKeyIndex===0){ + tabList = createTabList(mainList, windowKeyIndex); + tabKeyIndex=0; + } + //Otherwise, we move up one. + if (windowKeyIndex>0){ + windowKeyIndex-=1; + tabList = createTabList(mainList, windowKeyIndex); + tabKeyIndex=tabList.length-1; + } + } + tabList[tabKeyIndex].classList.add('keyHover'); } - tabList[tabKeyIndex].classList.add('keyHover'); } //Pin when p is pressed else if(event.keyCode===80){ - tabList[tabKeyIndex].querySelector('i.pin').click(); + if (tabKeyIndex>0){ + tabList[tabKeyIndex].querySelector('i.pin').click(); + } } //Go to search box when s is pressed. else if (event.keyCode===83){