bug 980197 - on long press of a phone number, select the whole phone number r=mfinkle

This commit is contained in:
Brad Lassey 2014-03-12 21:16:33 -04:00
parent 3b1c716069
commit dfa7a3294c

View File

@ -276,6 +276,42 @@ var SelectionHandler = {
return false; return false;
} }
if (this._isPhoneNumber(selection.toString())) {
let anchorNode = selection.anchorNode;
let anchorOffset = selection.anchorOffset;
let focusNode = null;
let focusOffset = null;
while (this._isPhoneNumber(selection.toString().trim())) {
focusNode = selection.focusNode;
focusOffset = selection.focusOffset;
selection.modify("extend", "forward", "word");
// if we hit the end of the text on the page, we can't advance the selection
if (focusNode == selection.focusNode && focusOffset == selection.focusOffset) {
break;
}
}
// reverse selection
selection.collapse(focusNode, focusOffset);
selection.extend(anchorNode, anchorOffset);
anchorNode = focusNode;
anchorOffset = focusOffset
while (this._isPhoneNumber(selection.toString().trim())) {
focusNode = selection.focusNode;
focusOffset = selection.focusOffset;
selection.modify("extend", "backward", "word");
// if we hit the end of the text on the page, we can't advance the selection
if (focusNode == selection.focusNode && focusOffset == selection.focusOffset) {
break;
}
}
selection.collapse(focusNode, focusOffset);
selection.extend(anchorNode, anchorOffset);
}
// Add a listener to end the selection if it's removed programatically // Add a listener to end the selection if it's removed programatically
selection.QueryInterface(Ci.nsISelectionPrivate).addSelectionListener(this); selection.QueryInterface(Ci.nsISelectionPrivate).addSelectionListener(this);
this._activeType = this.TYPE_SELECTION; this._activeType = this.TYPE_SELECTION;
@ -759,12 +795,14 @@ var SelectionHandler = {
this._closeSelection(); this._closeSelection();
}, },
_phoneRegex: /(?:\s|^)[\+]?(\(?\d{1,8}\)?)?([- \.]+\(?\d{1,8}\)?)+( ?(x|ext) ?\d{1,3})?(?:\s|$)/, _phoneRegex: /^\+?[0-9\s,-.\(\)*#pw]{1,30}$/,
_getSelectedPhoneNumber: function sh_isPhoneNumber() { _getSelectedPhoneNumber: function sh_getSelectedPhoneNumber() {
let selectedText = this._getSelectedText(); return this._isPhoneNumber(this._getSelectedText().trim());
return (selectedText.length && this._phoneRegex.test(selectedText) ? },
selectedText : null);
_isPhoneNumber: function sh_isPhoneNumber(selectedText) {
return (this._phoneRegex.test(selectedText) ? selectedText : null);
}, },
callSelection: function sh_callSelection() { callSelection: function sh_callSelection() {