如何在光标或选择下获取特定的FlowElement

时间:2014-04-23 12:22:58

标签: tlf

我有一个附加了SelectionManager的TextFlow。我想得到光标在其中的FlowElement,或者如果选择了多行,则选择在其中。

_textFlow.addEventListener(SelectionEvent.SELECTION_CHANGE,selectionChangeListener,false,0,true);


private function selectionChangeListener(e:SelectionEvent):void
{               
    var selectionState:SelectionState = e.selectionState;
    var selectedElementRange:ElementRange = ElementRange.createElementRange(selectionState.textFlow, selectionState.absoluteStart, selectionState.absoluteEnd);
}

1 个答案:

答案 0 :(得分:0)

我找到了如何使用以下方法找到叶元素,但仍然不知道如何找到包含选择元素

/** Returns the current FlowELement element at the currentStyleLevel */
private function currentStyleElement(absolutePosition:int):FlowElement
{
    var e:FlowElement;
    switch(currentStyleLevel)
    {
        case TextFlow:
            e = _textFlow;
            break;
        case ParagraphElement:
            e = _textFlow.findLeaf(absolutePosition).getParagraph();
            break;
        default:
            e = _textFlow.findLeaf(absolutePosition);
    }
    return e;
}