Skip to main content
Participant
April 2, 2012
Question

Problem with SelectionState, plase help

  • April 2, 2012
  • 1 reply
  • 3377 views

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);

This topic has been closed for replies.

1 reply

Participant
April 4, 2012

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

Participating Frequently
April 5, 2012

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 = listElement;

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

                                                  var e:FlowGroupElement = FlowGroupElement (elem2);

                                                  var i:int=0;

                                                  while (i < e.mxmlChildren.length)

                                                  {

                                                            if (e.mxmlChildren as ListElement)

                                                            {

                                                                      var listElement1:ListElement = e.mxmlChildren 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 as ListElement)

                                                                                {

                                                                                          listsFound++;

                                                                                          a++;

                                                                                          allListElement = e1.mxmlChildren as ListElement;

                                                                                }

                                                                                j++;

                                                                      }

                                                                      listsFound++;

                                                                      a++;

                                                                      allListElement = e.mxmlChildren 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 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;

 

                              }

Participant
April 5, 2012

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?