5 Replies Latest reply: Apr 5, 2012 11:20 PM by Gang Cai RSS

    Problem with SelectionState, plase help

    anton.zhuk

      Hi

      I've tried create list and convert it to plain text at runtime.

      With creating text evrething is ok    

         

           var tf:TextLayoutFormat = editor.getFormatOfRange(null, editor.selectionAnchorPosition, editor.selectionActivePosition);    

           var selState : SelectionState = new SelectionState(editor.textFlow, editor.selectionAnchorPosition, editor.selectionActivePosition);

           var listFormar : TextLayoutFormat = tf;

           listFormar.listStyleType = ListStyleType.DISC;

           listFormar.listStylePosition = ListStylePosition.OUTSIDE;

           var operation : CreateListOperation = new CreateListOperation(selState, null, listFormar);

           operation.doOperation();

       

      With this evtething is ok - list was created.

       

      But when I've tried to convert selected text from list to plain text I have problem. I've selected list but SelectedState return all textFlow from editor (RichEditableText), and I can't receive root list element. Please help to select list in textFlow.

      var selState : SelectionState = new SelectionState(editor.textFlow, editor.selectionAnchorPosition, editor.selectionActivePosition);

        • 1. Re: Problem with SelectionState, plase help
          anton.zhuk Community Member

          Tell me please, how to determine the DOM elements in TextFlow in RichEditableText by MouseClick?

          • 2. Re: Problem with SelectionState, plase help
            Gang Cai Adobe Employee

            I pasted a code scrap of how to enumerate the listElements. Hope it will be helpful

             

            //this test case will check up to three level nested lists

                                          //create three lists

                                          SelManager.createList();

                                          SelManager.createList();

                                          SelManager.createList();

                                          var tf:TextFlow = SelManager.textFlow;

                                          var listsFound:int = 0;

                                          var elem:FlowElement = tf.getChildAt(0);

                                          while (elem)

                                          {

                                                    if (elem as ListElement)

                                                    {

                                                              var listElement:ListElement = elem as ListElement;

                                                              var allListElement:Array = [];

                                                              var a:int = 0;

                                                              allListElement[a] = listElement;

                                                              var elem2:FlowElement = listElement.getChildAt(0);

                                                              var e:FlowGroupElement = FlowGroupElement (elem2);

                                                              var i:int=0;

                                                              while (i < e.mxmlChildren.length)

                                                              {

                                                                        if (e.mxmlChildren[i] as ListElement)

                                                                        {

                                                                                  var listElement1:ListElement = e.mxmlChildren[i] as ListElement;

                                                                                  var elem3:FlowElement = listElement1.getChildAt(0);

                                                                                  var e1:FlowGroupElement = FlowGroupElement (elem3);

                                                                                  var j:int=0;

                                                                                  while (j < e1.mxmlChildren.length)

                                                                                  {

                                                                                            if (e1.mxmlChildren[j] as ListElement)

                                                                                            {

                                                                                                      listsFound++;

                                                                                                      a++;

                                                                                                      allListElement[a] = e1.mxmlChildren[j] as ListElement;

                                                                                            }

                                                                                            j++;

                                                                                  }

                                                                                  listsFound++;

                                                                                  a++;

                                                                                  allListElement[a] = e.mxmlChildren[i] as ListElement;

                                                                        }

                                                                        i++;

                                                              }

                                                              listsFound++;

                                                    }

                                                    elem = elem.getNextSibling();

                                          }

             

             

                                          // determine what the bullet text should be

                                          var listItem:ListItemElement = new ListItemElement();

                                          var bulletText:String = "";

                                          var markerLength:int = 0;

                                          var listStartIndex:int = 0;

                                          var listFlowLine:TextFlowLine;

                                          var listLine:TextLine;

                                          var bulletLine:TextLine;

                                          for (i=0; i<listsFound; i++)

                                          {

                                                    listElement = allListElement[i] as ListElement;

                                                    listItem = listElement.getChildAt(0) as ListItemElement;

                                                    bulletText = listElement.computeListItemText(listItem, listItem.computedListMarkerFormat());

                                                    markerLength = bulletText.length + 1;

                                                    // find the TextFlowLine for the list start

                                                    listStartIndex = listElement.getElementRelativeStart(tf);

                                                    listFlowLine = tf.flowComposer.findLineAtPosition(listStartIndex);

                                                    listLine = listFlowLine.getTextLine();

                                                    bulletLine = listLine.getChildAt(0) as TextLine;

             

                                          }

            • 3. Re: Problem with SelectionState, plase help
              anton.zhuk Community Member

              Thanks for your answer, but I need something else

               

              for example I've had next text in RTF

              111

              *222

              *333

              *444

              555

               

              Where 222, 333, 444 are list element

               

              I've select from 222 to 444 and press button

              Next code are runing

              var selState : SelectionState = new SelectionState(editor.textFlow, editor.selectionAnchorPosition, editor.selectionActivePosition);

              var elem:FlowElement = selState.textFlow.getChildAt(0);

              So, I've expect get first item from selection, but I've got first item of the textflow - paragraph 111.

              Where did I wrong?

              • 4. Re: Problem with SelectionState, plase help
                anton.zhuk Community Member

                As I see SelectionState doesn't work correctly

                The SelectionState class represents a selection in a text flow.

                But in any case SelectionState return all textFlow. So, this is bug

                • 5. Re: Problem with SelectionState, plase help
                  Gang Cai Adobe Employee

                  There will be only one textFlow in your case. It's the container of all the text elements. The selection state represents the selection in 'that' text flow.

                   

                  The selection state will record the position information of your selection. You should get use the position information to retrieve your text flow elements