apache-flex 如何获取当前所选内容的格式?

ioekq8ef  于 2022-11-01  发布在  Apache
关注(0)|答案(1)|浏览(126)

有没有办法得到当前选择的格式?下面是我目前得到的结果:

var currentFormat:TextLayoutFormat;
var selectionStart:int;
var selectionEnd:int;
var operationState:SelectionState;
var editManager:IEditManager;

if (richEditableText.textFlow && richEditableText.textFlow.interactionManager is IEditManager) {
    editManager = IEditManager(richEditableText.textFlow.interactionManager);

    selectionStart = Math.min(richEditableText.selectionActivePosition, richEditableText.selectionAnchorPosition);
    selectionEnd = Math.max(richEditableText.selectionActivePosition, richEditableText.selectionAnchorPosition);

    if (operationState == null) {
        operationState = new SelectionState(richEditableText.textFlow, selectionStart, selectionEnd);
    }

    // this does not work
    currentFormat = editManager.getCommonCharacterFormat(operationState);

}
xqkwcwgp

xqkwcwgp1#

我找不到任何东西,所以这里是什么似乎工作:

/**
 * Get format of element range

**/

public static function getElementRangeFormat(elementRange:ElementRange):TextLayoutFormat {      
    var leaf:FlowLeafElement = elementRange.firstLeaf;
    var attr:TextLayoutFormat = new TextLayoutFormat(leaf.computedFormat);

    for (;;)
    {
        if (leaf == elementRange.lastLeaf)
            break;
        leaf = leaf.getNextLeaf();
        attr.concatInheritOnly(leaf.computedFormat);
    }

    return Property.extractInCategory(TextLayoutFormat, TextLayoutFormat.description, attr, Category.CHARACTER, false) as TextLayoutFormat;
}

灵感源自ElementRange.getCommonCharacterFormat()

相关问题