Ticket #1665: addCitation_focus.patch
| File addCitation_focus.patch, 4.6 KB (added by fbennett, 6 years ago) |
|---|
-
chrome/content/zotero/integration/addCitationDialog.js
37 37 var _lastSelected = null; 38 38 var _previewShown = false; 39 39 var _suppressNextTreeSelect = false; 40 var _suppressNextListSelect = false; 40 41 var _locatorIndexArray = {}; 41 42 var _locatorNameArray = {}; 42 43 var _autoRegeneratePref; … … 212 213 var hasBeenAdded = itemID && _itemData[itemID] !== undefined; 213 214 // disable boxes if item not added; otherwise, enable 214 215 _itemSelected(hasBeenAdded ? itemID : false); 216 // turn off highlight in selected item list 217 _suppressNextListSelect = true; 218 document.getElementById("citation-list").selectedIndex = -1; 215 219 // disable adding nothing, or things already added 216 220 document.getElementById("add").disabled = !itemID || hasBeenAdded; 221 document.getElementById("remove").disabled = true; 222 document.getElementById("up").disabled = true; 223 document.getElementById("down").disabled = true; 217 224 } else { 218 225 _updateAccept(); 219 226 _updatePreview(); 220 227 } 221 _configListPosition(true);222 228 } 223 229 224 230 /* 225 231 * called when an item in the selected items list is clicked 226 232 */ 227 233 function listItemSelected() { 234 if(_suppressNextListSelect) { 235 _suppressNextListSelect = false; 236 _updateAccept(); 237 return; 238 } 228 239 var selectedListItem = _citationList.getSelectedItem(0); 240 var selectedListIndex = _citationList.selectedIndex; 229 241 var itemID = (selectedListItem ? selectedListItem.value : false); 230 242 _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(); 233 246 document.getElementById("remove").disabled = !itemID; 247 document.getElementById("add").disabled = true; 248 _configListPosition(!itemID, selectedListIndex); 234 249 } 235 250 236 function _configListPosition(flag) { 237 var selectedIndex = _citationList.selectedIndex; 238 if (selectedIndex > 0) { 251 function _configListPosition(flag, selectedListIndex) { 252 if (selectedListIndex > 0) { 239 253 document.getElementById("up").disabled = flag; 240 254 } else { 241 255 document.getElementById("up").disabled = true; 242 256 } 243 if ( selectedIndex < (_citationList.getRowCount() - 1)) {257 if (-1 < selectedListIndex && selectedListIndex < (_citationList.getRowCount() - 1)) { 244 258 document.getElementById("down").disabled = flag; 245 259 } else { 246 260 document.getElementById("down").disabled = true; … … 256 270 257 271 var insertBeforeItem; 258 272 var selectedListItem = _citationList.getSelectedItem(0); 273 var selectedListIndex = _citationList.selectedIndex; 259 274 var itemID = selectedListItem.value; 260 var selectedListIndex = _citationList.selectedIndex;261 275 if (direction === -1) { 262 276 insertBeforeItem = selectedListItem.previousSibling; 263 277 } else { … … 268 282 _citationList.selectedIndex = (selectedListIndex + direction); 269 283 _itemSelected(itemID); 270 284 _updatePreview(); 271 _configListPosition(false );285 _configListPosition(false, (selectedListIndex + direction)); 272 286 } 273 287 274 288 function up() { … … 286 300 var item = itemsView.getSelectedItems()[0]; // treeview from selectItemsDialog.js 287 301 _itemSelected(item.getID()); 288 302 _addItem(item); 289 _citationList.focus();290 _citationList.selectedIndex = _citationList.getRowCount()-1;291 303 292 304 // don't let someone select it again 293 305 document.getElementById("add").disabled = true; … … 303 315 */ 304 316 function remove() { 305 317 var selectedListItem = _citationList.getSelectedItem(0); 318 var selectedListIndex = _citationList.selectedIndex; 306 319 var itemID = selectedListItem.value; 307 320 308 321 // remove from _itemData … … 310 323 _itemData[itemID] = undefined; 311 324 _lastSelected = null; 312 325 313 // re-select currently selected in left pane314 var itemIDs = itemsView.getSelectedItems(true); // treeview from selectItemsDialog.js315 if(itemIDs.length) {316 document.getElementById("zotero-items-tree").focus();317 treeItemSelected();318 }319 320 326 // remove from list 321 327 _citationList.removeChild(selectedListItem); 322 328 329 if (selectedListIndex >= _citationList.getRowCount()) { 330 selectedListIndex = _citationList.getRowCount() - 1; 331 } 332 _citationList.selectedIndex = selectedListIndex; 333 323 334 _updateAccept(); 324 335 _updatePreview(); 325 treeItemSelected();326 336 } 327 337 328 338 /* … … 575 585 itemNode.setAttribute("class", "listitem-iconic"); 576 586 itemNode.setAttribute("image", item.getImageSrc()); 577 587 _citationList.appendChild(itemNode); 578 _configListPosition(false);579 588 } 580 589 581 590 /*