Repository: flex-utilities Updated Branches: refs/heads/develop 2783266c4 -> 18d0738c4
FLEX-34756 CAUSE: If a spelling job runs while the textFlow of RichEditableText is damaged, then the values that SpellUI.getValidFirstWordIndex() and SpellUI.getValidLastWordIndex() receive from SelectionManager.computeSelectionIndex() will be inaccurate. Sometimes, as in the example attached to the ticket, they will cause a runtime error. SOLUTION: Prevent a spelling job from being executed when the textFlow is damaged. NOTES: -also removed an unused variables and inaccurate comment from SparkHighlighter and SpellUI. Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/f8d36d1b Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/f8d36d1b Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/f8d36d1b Branch: refs/heads/develop Commit: f8d36d1b763db0485892596ecd94a550a0cc00e3 Parents: bbe342b Author: Mihai Chira <mih...@apache.org> Authored: Mon Mar 30 14:06:52 2015 +0200 Committer: Mihai Chira <mih...@apache.org> Committed: Mon Mar 30 14:06:52 2015 +0200 ---------------------------------------------------------------------- .../spelling/framework/ui/SparkHighlighter.as | 13 +-- .../com/adobe/linguistics/spelling/SpellUI.as | 95 +++++++++++--------- 2 files changed, 58 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f8d36d1b/Squiggly/main/SpellingFramework/src/com/adobe/linguistics/spelling/framework/ui/SparkHighlighter.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingFramework/src/com/adobe/linguistics/spelling/framework/ui/SparkHighlighter.as b/Squiggly/main/SpellingFramework/src/com/adobe/linguistics/spelling/framework/ui/SparkHighlighter.as index db402fa..ef01970 100644 --- a/Squiggly/main/SpellingFramework/src/com/adobe/linguistics/spelling/framework/ui/SparkHighlighter.as +++ b/Squiggly/main/SpellingFramework/src/com/adobe/linguistics/spelling/framework/ui/SparkHighlighter.as @@ -127,7 +127,7 @@ package com.adobe.linguistics.spelling.framework.ui mTextField.addChild(mHighlighter); } - drawSquigglyLineForRange(token.first, token.last); + drawSquigglyLineForRange(token.first, token.last); // Just adjust the left padding, top padding is not an issue //var pleft:uint = mTextField.getStyle("paddingLeft"); @@ -144,14 +144,15 @@ package com.adobe.linguistics.spelling.framework.ui var tflIndexFirst:int = tf.flowComposer.findLineIndexAtPosition(start); var tflIndexLast:int = tf.flowComposer.findLineIndexAtPosition(end); - // Pointer var tflIndex:int = tflIndexFirst; - var tfl:TextFlowLine = tflFirst; - - if (tflIndexFirst == tflIndexLast) { + + if (tflIndexFirst == tflIndexLast) + { // Draw one line drawSquigglyLineAtIndex(tflIndexFirst, start - tflFirst.absoluteStart, end - tflFirst.absoluteStart); - } else { + } + else + { // Multiple lines (very long word) drawSquigglyLineAtIndex(tflIndexFirst, start - tflFirst.absoluteStart); http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/f8d36d1b/Squiggly/main/SpellingUIEx/src/com/adobe/linguistics/spelling/SpellUI.as ---------------------------------------------------------------------- diff --git a/Squiggly/main/SpellingUIEx/src/com/adobe/linguistics/spelling/SpellUI.as b/Squiggly/main/SpellingUIEx/src/com/adobe/linguistics/spelling/SpellUI.as index 2d3d9ca..308a703 100644 --- a/Squiggly/main/SpellingUIEx/src/com/adobe/linguistics/spelling/SpellUI.as +++ b/Squiggly/main/SpellingUIEx/src/com/adobe/linguistics/spelling/SpellUI.as @@ -19,42 +19,43 @@ package com.adobe.linguistics.spelling { - import com.adobe.linguistics.spelling.framework.SpellingConfiguration; - import com.adobe.linguistics.spelling.framework.SpellingService; - import com.adobe.linguistics.spelling.framework.ui.HaloHighlighter; - import com.adobe.linguistics.spelling.framework.ui.HaloWordProcessor; - import com.adobe.linguistics.spelling.framework.ui.IHighlighter; - import com.adobe.linguistics.spelling.framework.ui.IWordProcessor; - import com.adobe.linguistics.spelling.framework.ui.SparkHighlighter; - import com.adobe.linguistics.spelling.framework.ui.SparkWordProcessor; - import com.adobe.linguistics.utils.TextTokenizer; - import com.adobe.linguistics.utils.Token; + import com.adobe.linguistics.spelling.framework.SpellingConfiguration; + import com.adobe.linguistics.spelling.framework.SpellingService; + import com.adobe.linguistics.spelling.framework.ui.HaloHighlighter; + import com.adobe.linguistics.spelling.framework.ui.HaloWordProcessor; + import com.adobe.linguistics.spelling.framework.ui.IHighlighter; + import com.adobe.linguistics.spelling.framework.ui.IWordProcessor; + import com.adobe.linguistics.spelling.framework.ui.SparkHighlighter; + import com.adobe.linguistics.spelling.framework.ui.SparkWordProcessor; + import com.adobe.linguistics.utils.TextTokenizer; + import com.adobe.linguistics.utils.Token; - import flash.events.Event; - import flash.events.FocusEvent; - import flash.geom.Point; - import flash.geom.Rectangle; - import flash.net.SharedObject; - import flash.net.URLLoader; - import flash.net.URLRequest; - import flash.text.TextField; - import flash.utils.Dictionary; + import flash.events.Event; + import flash.events.FocusEvent; + import flash.geom.Point; + import flash.geom.Rectangle; + import flash.net.SharedObject; + import flash.net.URLLoader; + import flash.net.URLRequest; + import flash.text.TextField; + import flash.utils.Dictionary; - import flashx.textLayout.edit.SelectionManager; - import flashx.textLayout.tlf_internal; + import flashx.textLayout.edit.SelectionManager; + import flashx.textLayout.elements.TextFlow; + import flashx.textLayout.tlf_internal; - import mx.controls.RichTextEditor; - import mx.controls.TextArea; - import mx.controls.TextInput; - import mx.core.UIComponent; - import mx.core.mx_internal; - import mx.events.ScrollEvent; + import mx.controls.RichTextEditor; + import mx.controls.TextArea; + import mx.controls.TextInput; + import mx.core.UIComponent; + import mx.core.mx_internal; + import mx.events.ScrollEvent; - import spark.components.RichEditableText; - import spark.components.TextArea; - import spark.components.TextInput; + import spark.components.RichEditableText; + import spark.components.TextArea; + import spark.components.TextInput; - use namespace mx_internal; + use namespace mx_internal; use namespace tlf_internal; /** @@ -340,21 +341,28 @@ package com.adobe.linguistics.spelling spellCheckScreen(event); } - /*private function doSpelling():void - { - _checkLastWord = true; - doSpellingJob(); - }*/ - - /** - @private - (This property is for Squiggly Developer use only.) - */ public function doSpellingJob():void { - if (_spellingEnabled == false) return; + if (_spellingEnabled == false) + return; + + if(!isTextFieldReadyForSpellingJob()) + return; + spellCheckRange(getValidFirstWordIndex(), getValidLastWordIndex()); } + + private function isTextFieldReadyForSpellingJob():Boolean + { + if(!mTextField) + return false; + + var textFlow:TextFlow = mTextField is RichEditableText ? RichEditableText(mTextField).textFlow : null; + if(!textFlow || !textFlow.flowComposer) + return true; + + return textFlow.flowComposer.isDamaged(textFlow.textLength); + } private function spellCheckRange(start:uint, end:uint):void { //hh.preSpellCheckRange(start, end); @@ -388,8 +396,7 @@ package com.adobe.linguistics.spelling } var tokenizer:TextTokenizer = new TextTokenizer(mTextField.text.substring(start,end)); - var tokens:Vector.<Token> = new Vector.<Token>(); - + for ( var token:Token = tokenizer.getFirstToken(); token != tokenizer.getLastToken(); token= tokenizer.getNextToken(token) ) { var result:Boolean=_spellingservice.checkWord(mTextField.text.substring(token.first+start, token.last+start)); if (!result){