Reputation: 4521
How do I prevent the inclusion of periods when double-clicking to select text in a Flex 4 TextArea?
For example, in a Flex 4 TextArea component, if I have the words "something.else" and I double-click on the word "something", it highlights "something.else".
How do I make it only highlight "something"?
I've googled the heck out of this, dug through the API, examined the related classes and haven't found anything "official".
NOTE: I would prefer to avoid simply intercepting the double-click event to handle setting the selection range myself as the complexity of restoring the other existing functionality may become insurmountable.
Upvotes: 0
Views: 210
Reputation: 4521
Here's the solution I went with:
protected var lastClickedSelectionAnchorIndex:int = 0;
protected function textArea_doubleClickHandler( event:MouseEvent ):void
{
if( event.target != textArea.textDisplay ) return;
if( textArea.selectionAnchorPosition == textArea.selectionActivePosition ) return;
var targetText:String = textArea.text;
if( targetText == null || targetText == "" || targetText.indexOf( "." ) === -1 ) return;
var selectedText:String = targetText.substring( textArea.selectionAnchorPosition, textArea.selectionActivePosition );
if( selectedText == null || selectedText == "" || selectedText.indexOf( "." ) === -1 ) return;
var selectionStart:int = textArea.selectionAnchorPosition;
var selectionEnd:int = textArea.selectionActivePosition;
if( selectionStart > selectionEnd ){
selectionStart = textArea.selectionActivePosition;
selectionEnd = textArea.selectionAnchorPosition;
}
if( lastClickedSelectionAnchorIndex < selectionStart || lastClickedSelectionAnchorIndex > selectionEnd ){
return;
}
var newSelectionStart:int = targetText.lastIndexOf( ".", lastClickedSelectionAnchorIndex );
var newSelectionEnd:int = targetText.indexOf( ".", lastClickedSelectionAnchorIndex );
var startSelectionOffset:int = 1;
if( newSelectionStart < selectionStart || newSelectionStart === -1 ){
newSelectionStart = selectionStart;
startSelectionOffset = 0;
}
if( newSelectionEnd > selectionEnd || newSelectionEnd === -1 ){
newSelectionEnd = selectionEnd;
}
textArea.selectRange( newSelectionStart + startSelectionOffset, newSelectionEnd );
}
protected function textArea_mouseDownHandler( event:MouseEvent ):void
{
try{
lastClickedSelectionAnchorIndex = textArea.selectionAnchorPosition;
}catch( error:Error ){
lastClickedSelectionAnchorIndex = 0;
}
}
Upvotes: 1
Reputation: 1313
1) TextArea uses RichEditableText. RichEditableText uses SelectionManager. SelectionManager has public function mouseDoubleClickHandler. mouseDoubleClickHandler uses ParagraphElement(which is final class) and its findPreviousWordBoundary and findNextWordBoundary functions. And they use TextBlock's functions with similar names. And TextBlock is a part of playerglobal.swc.
So, the only 'professional' way with overrideing methods can be applied by overriding SelectionManager's handler, and then extending RichEditableText and some infrastructure classes to make it use of your custom SelectionManager.
But it's not an easy way.
2)You can place one of the space characters around '.' (preferring narrow ones or creating custom font where one of those characters has 0 width).
rslt[0x0020] = true; //SPACE
rslt[0x1680] = true; //OGHAM SPACE MARK
rslt[0x180E] = true; //MONGOLIAN VOWEL SEPARATOR
rslt[0x2000] = true; //EN QUAD
rslt[0x2001] = true; //EM QUAD
rslt[0x2002] = true; //EN SPACE
rslt[0x2003] = true; //EM SPACE
rslt[0x2004] = true; //THREE-PER-EM SPACE
rslt[0x2005] = true; //FOUR-PER-EM SPACE
rslt[0x2006] = true; //SIZE-PER-EM SPACE
rslt[0x2007] = true; //FIGURE SPACE
rslt[0x2008] = true; //PUNCTUATION SPACE
rslt[0x2009] = true; //THIN SPACE
rslt[0x200A] = true; //HAIR SPACE
rslt[0x202F] = true; //NARROW NO-BREAK SPACE
rslt[0x205F] = true; //MEDIUM MATHEMATICAL SPACE
rslt[0x3000] = true; //IDEOGRAPHIC SPACE
//members of LineSeparator category
rslt[0x2028] = true; //LINE SEPARATOR
//members of ParagraphSeparator category
rslt[0x2029] = true;
//Other characters considered to be a space
rslt[0x0009] = true; //CHARACTER TABULATION
rslt[0x000A] = true; //LINE FEED
rslt[0x000B] = true; //LINE TABULATION
rslt[0x000C] = true; //FORM FEED
rslt[0x000D] = true; //CARRIAGE RETURN
rslt[0x0085] = true; //NEXT LINE
rslt[0x00A0] = true; //NO-BREAK SPACE
3) So, I think that your option with custom doubleclick handler is no so bad.
Upvotes: 2