diff --git a/toolkit/content/widgets/tree.xml b/toolkit/content/widgets/tree.xml index 8fb509e7c78f..918f09487e40 100644 --- a/toolkit/content/widgets/tree.xml +++ b/toolkit/content/widgets/tree.xml @@ -273,6 +273,49 @@ ]]> + + + 1000) + this._incrementalString = key; + else + this._incrementalString += key; + this._lastKeyTime = event.timeStamp; + + var length = this._incrementalString.length; + var incrementalString = this._incrementalString; + var charIndex = 1; + while (charIndex < length && incrementalString[charIndex] == incrementalString[charIndex - 1]) + charIndex++; + // If all letters in incremental string are same, just try to match the first one + if (charIndex == length) { + length = 1; + incrementalString = incrementalString.substring(0, length); + } + + var keyCol = this.columns.getKeyColumn(); + var rowCount = this.view.rowCount; + var start = 1; + + var c = this.currentIndex; + if (length > 1) { + start = 0; + if (c < 0) + c = 0; + } + + for (var i = 0; i < rowCount; i++) { + var l = (i + start + c) % rowCount; + var cellText = this.view.getCellText(l, keyCol); + cellText = cellText.substring(0, length).toLowerCase(); + if (cellText == incrementalString) + return l; + } + return -1; + ]]> + + @@ -741,8 +784,8 @@ if (this._editingColumn) return; - var c = this.currentIndex; if (event.charCode == ' '.charCodeAt(0)) { + var c = this.currentIndex; if (!this.view.selection.isSelected(c) || (!this.view.selection.single && this._isAccelPressed(event))) { this.view.selection.toggleSelect(c); @@ -751,44 +794,10 @@ else if (!this.disableKeyNavigation && event.charCode > 0 && !event.altKey && !this._isAccelPressed(event) && !event.metaKey) { - var key = String.fromCharCode(event.charCode); - key = key.toLowerCase(); - if (event.timeStamp - this._lastKeyTime > 1000) - this._incrementalString = key; - else - this._incrementalString += key; - this._lastKeyTime = event.timeStamp; - - var length = this._incrementalString.length; - var incrementalString = this._incrementalString; - var charIndex = 1; - while (charIndex < length && incrementalString[charIndex] == incrementalString[charIndex - 1]) - charIndex++; - // If all letters in incremental string are same, just try to match the first one - if (charIndex == length) { - length = 1; - incrementalString = incrementalString.substring(0, length); - } - - var keyCol = this.columns.getKeyColumn(); - var rowCount = this.view.rowCount; - var start = 1; - - if (length > 1) { - start = 0; - if (c < 0) - c = 0; - } - - for (var i = 0; i < rowCount; i++) { - var l = (i + start + c) % rowCount; - var cellText = this.view.getCellText(l, keyCol); - cellText = cellText.substring(0, length).toLowerCase(); - if (cellText == incrementalString) { - this.view.selection.timedSelect(l, this._selectDelay); - this.treeBoxObject.ensureRowIsVisible(l); - break; - } + var l = this.keyNavigate(event); + if (l >= 0) { + this.view.selection.timedSelect(l, this._selectDelay); + this.treeBoxObject.ensureRowIsVisible(l); } } ]]> diff --git a/xpfe/global/resources/content/bindings/tree.xml b/xpfe/global/resources/content/bindings/tree.xml index 0b1c4ca681ee..a5050c3fb181 100644 --- a/xpfe/global/resources/content/bindings/tree.xml +++ b/xpfe/global/resources/content/bindings/tree.xml @@ -223,7 +223,43 @@ return true; } return false; + ]]> + + + + + 1000) + this._incrementalString = key; + else + this._incrementalString += key; + this._lastKeyTime = event.timeStamp; + + var incrementalString = this._incrementalString; + if (/^(.)\1*$/.test(incrementalString)) + incrementalString = incrementalString[0]; + var length = incrementalString.length; + + var keyCol = this.columns.getKeyColumn(); + var rowCount = this.view.rowCount; + var start = 1; + + var c = this.currentIndex; + if (length > 1) { + start = 0; + if (c < 0) + c = 0; } + + for (var i = 0; i < rowCount; i++) { + var l = (i + start + c) % rowCount; + var cellText = this.view.getCellText(l, keyCol); + cellText = cellText.slice(0, length).toLowerCase(); + if (cellText == incrementalString) + return l; + } + return -1; ]]> @@ -711,57 +747,22 @@ if (this._editingColumn) return; - var c = this.currentIndex; if (event.charCode == ' '.charCodeAt(0) && !this.view.selection.single) { - if (!this.view.selection.isSelected(c) || event.ctrlKey) { + var c = this.currentIndex; + if (event.ctrlKey || !this.view.selection.isSelected(c)) this.view.selection.toggleSelect(c); - } } else if (!this.disableKeyNavigation && event.charCode > 0 && !event.altKey && !event.ctrlKey && !event.metaKey) { - var key = String.fromCharCode(event.charCode); - key = key.toLowerCase(); - if (event.timeStamp - this._lastKeyTime > 1000) - this._incrementalString = key; - else - this._incrementalString += key; - this._lastKeyTime = event.timeStamp; - - var length = this._incrementalString.length; - var incrementalString = this._incrementalString; - var charIndex = 1; - while (charIndex < length && incrementalString[charIndex] == incrementalString[charIndex - 1]) - charIndex++; - // If all letters in incremental string are same, just try to match the first one - if (charIndex == length) { - length = 1; - incrementalString = incrementalString.substring(0, length); + var l = this.keyNavigate(event); + if (l >= 0) { + this.view.selection.timedSelect(l, this._selectDelay); + this.treeBoxObject.ensureRowIsVisible(l); } - - var keyCol = this.columns.getKeyColumn(); - var rowCount = this.view.rowCount; - var start = 1; - - if (length > 1) { - start = 0; - if (c < 0) - c = 0; - } - - for (var i = 0; i < rowCount; i++) { - var l = (i + start + c) % rowCount; - var cellText = this.view.getCellText(l, keyCol); - cellText = cellText.substring(0, length).toLowerCase(); - if (cellText == incrementalString) { - this.view.selection.timedSelect(l, this._selectDelay); - this.treeBoxObject.ensureRowIsVisible(l); - break; - } - } - } - ]]> + } + ]]> - +