diff --git a/chrome/content/zotero/bindings/tagsbox.xml b/chrome/content/zotero/bindings/tagsbox.xml index 8ee7d5f943..fe7bf61115 100644 --- a/chrome/content/zotero/bindings/tagsbox.xml +++ b/chrome/content/zotero/bindings/tagsbox.xml @@ -411,12 +411,9 @@ var fieldName = 'tag'; var tabindex = textbox.getAttribute('ztabindex'); - - //var value = t.value; + var value = textbox.value; - var elem; - var tagsbox = Zotero.getAncestorByTagName(textbox, 'tagsbox'); if (!tagsbox) { @@ -462,7 +459,34 @@ value = value.replace('\r\n','\n'); value = value.replace('\r','\n'); var nameArray = value.split('\n'); + + var extremeTag = false; + var nextTag = false; + if (this._tabDirection == -1) { + if (this._lastTabIndex == 1) { + extremeTag = true; + } else { + nextTag = row.previousSibling.getAttribute('id').split('-')[1]; + } + } else if (this._tabDirection == 1) { + if (this._lastTabIndex >= this.item.getTags().length) { + extremeTag = true; + } else { + nextTag = row.nextSibling.getAttribute('id').split('-')[1]; + } + } + id = this.item.addTags(nameArray); + + if (extremeTag) { + if (this._tabDirection == 1) { + this._lastTabIndex = this.item.getTags().length; + } else if (this._tabDirection == -1) { + this._lastTabIndex = 2; + } + } else { + this._lastTabIndex = this.item.getTagIndex(nextTag)+1-this._tabDirection; + } } else { id = tagsbox.add(value); @@ -474,7 +498,7 @@ } if (id) { - elem = this.createValueElement( + var elem = this.createValueElement( value, tabindex ); @@ -492,22 +516,10 @@ catch (e) {} } - var focusMode = 'tags'; var focusBox = tagsbox; - //Move at least one field even if no entry was added because of - //the way bookkeeping is done above - var fieldsToMove = 1; - //Check if id is an array and, if so, how many new entries - //were added at once - if (Object.prototype.toString.call(id) === '[object Array]') { - fieldsToMove = id.length; - } - if (this._tabDirection) { - for (var i = 0; i < fieldsToMove; i++) { - this._focusNextField(focusBox, this._lastTabIndex, this._tabDirection == -1); - } + this._focusNextField(focusBox, this._lastTabIndex, this._tabDirection == -1); } ]]> @@ -752,4 +764,4 @@ - \ No newline at end of file + diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 263215ca93..fd06240484 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1,7 +1,7 @@ /* ***** BEGIN LICENSE BLOCK ***** - Copyright © 2009 Center for History and New Media + Copyright ¬© 2009 Center for History and New Media George Mason University, Fairfax, Virginia, USA http://zotero.org @@ -2703,7 +2703,7 @@ Zotero.Item.prototype.getFile = function(row, skipExistsCheck) { // Strip "storage:" var path = row.path.substr(8); // setRelativeDescriptor() silently uses the parent directory on Windows - // if the filename contains certain characters, so strip them — + // if the filename contains certain characters, so strip them ‚Äî // but don't skip characters outside of XML range, since they may be // correct in the opaque relative descriptor string // @@ -3637,6 +3637,22 @@ Zotero.Item.prototype.getTagIDs = function() { return Zotero.DB.columnQuery(sql, this.id); } +//Return the index of tagID in the list of the item's tags +//sorted in alphabetical order. +Zotero.Item.prototype.getTagIndex = function(tagID) { + var tags = this.getTags(); + + var tagIndex=-1; + for (var i=0;i