FLEX-33985 In RTL text, computing the next/previous atom is much more tricky


Project: http://git-wip-us.apache.org/repos/asf/flex-tlf/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-tlf/commit/db303b54
Tree: http://git-wip-us.apache.org/repos/asf/flex-tlf/tree/db303b54
Diff: http://git-wip-us.apache.org/repos/asf/flex-tlf/diff/db303b54

Branch: refs/heads/develop
Commit: db303b5410522441a7afaeb7553bb4222735ecaf
Parents: f8c8369
Author: Alex Harui <aha...@apache.org>
Authored: Sun Feb 9 22:55:19 2014 -0800
Committer: Alex Harui <aha...@apache.org>
Committed: Sun Feb 9 22:55:19 2014 -0800

----------------------------------------------------------------------
 .../textLayout/elements/ParagraphElement.as     | 119 ++++++++++++++-----
 1 file changed, 90 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-tlf/blob/db303b54/textLayout/src/flashx/textLayout/elements/ParagraphElement.as
----------------------------------------------------------------------
diff --git a/textLayout/src/flashx/textLayout/elements/ParagraphElement.as 
b/textLayout/src/flashx/textLayout/elements/ParagraphElement.as
index 896f873..fbf2e68 100644
--- a/textLayout/src/flashx/textLayout/elements/ParagraphElement.as
+++ b/textLayout/src/flashx/textLayout/elements/ParagraphElement.as
@@ -481,26 +481,59 @@ package flashx.textLayout.elements
                        if 
(ContainerController.tlf_internal::usesDiscretionaryHyphens)
                        {
                                var textBlock:TextBlock = getTextBlock();
+                var isRTL:Boolean = textBlock.bidiLevel == 1;
                                var tl:TextLine = 
textBlock.getTextLineAtCharIndex(relativePosition);
                                var currentAtomIndex:int = 
tl.getAtomIndexAtCharIndex(relativePosition);
-                               if (currentAtomIndex == 0)
-                               {
-                                       tl = tl.previousLine;
-                                       if (!tl)
-                                               return -1;
-                                       // need this when 0x2028 line separator 
in use
-                                       if (tl.textBlockBeginIndex + 
tl.rawTextLength == relativePosition)
-                                               return tl.textBlockBeginIndex + 
tl.rawTextLength - 1;
-                                       return tl.textBlockBeginIndex + 
tl.rawTextLength;
-                               }
-                               while (--relativePosition)
-                               {
-                                       if 
(tl.getAtomIndexAtCharIndex(relativePosition) < currentAtomIndex)
-                                               break;
-                               }
+                trace("relpos", relativePosition, "atomIndex", 
currentAtomIndex);
+                if (isRTL)
+                {
+                   var foo:int = 
getTextBlock().findPreviousAtomBoundary(relativePosition);
+                   if (currentAtomIndex == 0)
+                   {
+                       // when cursor is left of all characters (end of line)
+                       // atomIndex is 0, so compensate
+                       if (tl.atomCount > 0)
+                       {
+                           while (--relativePosition)
+                           {
+                               if 
(tl.getAtomIndexAtCharIndex(relativePosition) != currentAtomIndex)
+                                   break;
+                           }
+                       }
+                   }
+                   else
+                   {
+                       while (--relativePosition)
+                       {
+                           if (tl.getAtomIndexAtCharIndex(relativePosition) != 
currentAtomIndex)
+                               break;
+                       }
+                   }
+                   trace("previous", relativePosition, foo);
+                }
+                else
+                {
+                               if (currentAtomIndex == 0)
+                               {
+                                       tl = tl.previousLine;
+                                       if (!tl)
+                                               return -1;
+                                       // need this when 0x2028 line separator 
in use
+                                       if (tl.textBlockBeginIndex + 
tl.rawTextLength == relativePosition)
+                                               return tl.textBlockBeginIndex + 
tl.rawTextLength - 1;
+                                       return tl.textBlockBeginIndex + 
tl.rawTextLength;
+                               }
+                               while (--relativePosition)
+                               {
+                                       if 
(tl.getAtomIndexAtCharIndex(relativePosition) < currentAtomIndex)
+                                               break;
+                               }
+                }
                                return relativePosition;
                        }
-                       return 
getTextBlock().findPreviousAtomBoundary(relativePosition);
+            var pos:int = 
getTextBlock().findPreviousAtomBoundary(relativePosition);
+            trace("previous", relativePosition, pos);
+                       return pos;
                }
 
                /** 
@@ -526,23 +559,51 @@ package flashx.textLayout.elements
                        if 
(ContainerController.tlf_internal::usesDiscretionaryHyphens)
                        {
                                var textBlock:TextBlock = getTextBlock();
+                var isRTL:Boolean = textBlock.bidiLevel == 1;
                                var tl:TextLine = 
textBlock.getTextLineAtCharIndex(relativePosition);
                                var currentAtomIndex:int = 
tl.getAtomIndexAtCharIndex(relativePosition);
-                               if (currentAtomIndex == tl.atomCount - 1)
-                               {
-                                       tl = tl.nextLine;
-                                       if (!tl)
-                                               return -1;
-                                       return tl.textBlockBeginIndex;
-                               }
-                               while (++relativePosition)
-                               {
-                                       if 
(tl.getAtomIndexAtCharIndex(relativePosition) > currentAtomIndex)
-                                               break;
-                               }
+                trace("relpos", relativePosition, "atomIndex", 
currentAtomIndex);
+                if (isRTL)
+                {
+                    var foo:int = 
getTextBlock().findNextAtomBoundary(relativePosition);
+                    if (currentAtomIndex == 0)
+                    {
+                        while (++relativePosition)
+                        {
+                            if (tl.getAtomIndexAtCharIndex(relativePosition) 
!= currentAtomIndex)
+                                break;
+                        }
+                    }
+                    else
+                    {
+                        while (++relativePosition)
+                        {
+                            if (tl.getAtomIndexAtCharIndex(relativePosition) 
!= currentAtomIndex)
+                                break;
+                        }
+                    }
+                    trace("next", relativePosition, foo);
+                }
+                else
+                {
+                               if (currentAtomIndex == tl.atomCount - 1)
+                               {
+                                       tl = tl.nextLine;
+                                       if (!tl)
+                                               return -1;
+                                       return tl.textBlockBeginIndex;
+                               }
+                               while (++relativePosition)
+                               {
+                                       if 
(tl.getAtomIndexAtCharIndex(relativePosition) > currentAtomIndex)
+                                               break;
+                               }
+                }
                                return relativePosition;
                        }
-                       return 
getTextBlock().findNextAtomBoundary(relativePosition);
+                       var pos:int = 
getTextBlock().findNextAtomBoundary(relativePosition);
+            trace("next", relativePosition, pos);
+            return pos;
                }
                
                /** @private */

Reply via email to