Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Tell me please, how to determine the DOM elements in TextFlow in RichEditableText by MouseClick?
Copy link to clipboard
Copied
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
{
listsFound++;
a++;
allListElement = e1.mxmlChildren
}
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;
}
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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