Ticket #1665: addCitation_focus.patch

File addCitation_focus.patch, 4.6 KB (added by fbennett, 6 years ago)

addCitation_focus.patch (revised)

  • chrome/content/zotero/integration/addCitationDialog.js

     
    3737        var _lastSelected = null; 
    3838        var _previewShown = false; 
    3939        var _suppressNextTreeSelect = false; 
     40        var _suppressNextListSelect = false; 
    4041        var _locatorIndexArray = {}; 
    4142        var _locatorNameArray = {}; 
    4243        var _autoRegeneratePref; 
     
    212213                        var hasBeenAdded = itemID && _itemData[itemID] !== undefined; 
    213214                        // disable boxes if item not added; otherwise, enable 
    214215                        _itemSelected(hasBeenAdded ? itemID : false); 
     216                        // turn off highlight in selected item list 
     217                        _suppressNextListSelect = true; 
     218                        document.getElementById("citation-list").selectedIndex = -1; 
    215219                        // disable adding nothing, or things already added 
    216220                        document.getElementById("add").disabled = !itemID || hasBeenAdded; 
     221                        document.getElementById("remove").disabled = true; 
     222                        document.getElementById("up").disabled = true; 
     223                        document.getElementById("down").disabled = true; 
    217224                } else { 
    218225                        _updateAccept(); 
    219226                        _updatePreview(); 
    220227                } 
    221                 _configListPosition(true); 
    222228        } 
    223229         
    224230        /* 
    225231         * called when an item in the selected items list is clicked 
    226232         */ 
    227233        function listItemSelected() { 
     234                if(_suppressNextListSelect) { 
     235                        _suppressNextListSelect = false; 
     236                        _updateAccept(); 
     237                        return; 
     238                } 
    228239                var selectedListItem = _citationList.getSelectedItem(0); 
     240                var selectedListIndex = _citationList.selectedIndex; 
    229241                var itemID = (selectedListItem ? selectedListItem.value : false); 
    230242                _itemSelected(itemID); 
    231                 _configListPosition(!itemID); 
    232                  
     243                // turn off highlight in item tree 
     244                _suppressNextTreeSelect = true; 
     245                document.getElementById("zotero-items-tree").view.selection.clearSelection(); 
    233246                document.getElementById("remove").disabled = !itemID; 
     247                document.getElementById("add").disabled = true; 
     248                _configListPosition(!itemID, selectedListIndex); 
    234249        } 
    235250         
    236         function _configListPosition(flag) { 
    237                 var selectedIndex = _citationList.selectedIndex; 
    238                 if (selectedIndex > 0) { 
     251        function _configListPosition(flag, selectedListIndex) { 
     252                if (selectedListIndex > 0) { 
    239253                        document.getElementById("up").disabled = flag; 
    240254                } else { 
    241255                        document.getElementById("up").disabled = true; 
    242256                } 
    243                 if (selectedIndex < (_citationList.getRowCount() - 1)) { 
     257                if (-1 < selectedListIndex && selectedListIndex < (_citationList.getRowCount() - 1)) { 
    244258                        document.getElementById("down").disabled = flag; 
    245259                } else { 
    246260                        document.getElementById("down").disabled = true; 
     
    256270                 
    257271                var insertBeforeItem; 
    258272                var selectedListItem = _citationList.getSelectedItem(0); 
     273                var selectedListIndex = _citationList.selectedIndex; 
    259274                var itemID = selectedListItem.value; 
    260                 var selectedListIndex = _citationList.selectedIndex; 
    261275                if (direction === -1) { 
    262276                        insertBeforeItem = selectedListItem.previousSibling; 
    263277                } else { 
     
    268282                _citationList.selectedIndex = (selectedListIndex + direction); 
    269283                _itemSelected(itemID); 
    270284                _updatePreview(); 
    271                 _configListPosition(false); 
     285                _configListPosition(false, (selectedListIndex + direction)); 
    272286        } 
    273287 
    274288        function up() { 
     
    286300                var item = itemsView.getSelectedItems()[0]; // treeview from selectItemsDialog.js 
    287301                _itemSelected(item.getID()); 
    288302                _addItem(item); 
    289                 _citationList.focus(); 
    290                 _citationList.selectedIndex = _citationList.getRowCount()-1; 
    291303                 
    292304                // don't let someone select it again 
    293305                document.getElementById("add").disabled = true; 
     
    303315         */ 
    304316        function remove() { 
    305317                var selectedListItem = _citationList.getSelectedItem(0); 
     318                var selectedListIndex = _citationList.selectedIndex; 
    306319                var itemID = selectedListItem.value; 
    307320                 
    308321                // remove from _itemData 
     
    310323                _itemData[itemID] = undefined; 
    311324                _lastSelected = null; 
    312325                 
    313                 // re-select currently selected in left pane 
    314                 var itemIDs = itemsView.getSelectedItems(true); // treeview from selectItemsDialog.js 
    315                 if(itemIDs.length) { 
    316                         document.getElementById("zotero-items-tree").focus(); 
    317                         treeItemSelected(); 
    318                 } 
    319                  
    320326                // remove from list 
    321327                _citationList.removeChild(selectedListItem); 
    322328                 
     329                if (selectedListIndex >= _citationList.getRowCount()) { 
     330                        selectedListIndex = _citationList.getRowCount() - 1; 
     331                } 
     332                _citationList.selectedIndex = selectedListIndex; 
     333 
    323334                _updateAccept(); 
    324335                _updatePreview(); 
    325                 treeItemSelected(); 
    326336        } 
    327337         
    328338        /* 
     
    575585                itemNode.setAttribute("class", "listitem-iconic"); 
    576586                itemNode.setAttribute("image", item.getImageSrc()); 
    577587                _citationList.appendChild(itemNode); 
    578                 _configListPosition(false); 
    579588        } 
    580589         
    581590        /*