Select next logical tag when adding multiple tags at once.

This commit is contained in:
Will S 2011-12-27 09:02:06 -05:00
parent e10d049428
commit 87c47c0615
2 changed files with 49 additions and 21 deletions

View file

@ -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);
}
]]>
</body>
@ -752,4 +764,4 @@
</xul:scrollbox>
</content>
</binding>
</bindings>
</bindings>

View file

@ -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<tags.length;i++) {
if (tagID == tags[i].id) {
tagIndex=i;
break;
}
}
return tagIndex;
}
Zotero.Item.prototype.replaceTag = function(oldTagID, newTag) {
if (!this.id) {
throw ('Cannot replace tag on unsaved item');