Как очистить форматирование выделения в TLF?

Я пытаюсь удалить форматирование выделения, и то, что у меня есть до сих пор, удаляет форматирование выделения только тогда, когда выделение находится внутри абзаца. Если выделение распространяется на другой абзац, форматирование не удаляется.

Вот что у меня есть до сих пор:

var currentFormat:TextLayoutFormat;
var currentParagraphFormat:TextLayoutFormat;
var containerFormat: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);
    }

    currentFormat = editManager.getCommonCharacterFormat(operationState);
    currentParagraphFormat = editManager.getCommonParagraphFormat(operationState);
    containerFormat = editManager.getCommonContainerFormat(operationState);

    editManager.clearFormat(currentFormat, currentParagraphFormat, containerFormat);

}

person 1.21 gigawatts    schedule 04.02.2018    source источник


Ответы (1)


Кажется, что SelectionManager.getCommonCharacterFormat() не совсем то, что я думал. Мне нужно получить формат выбранных символов, и эта функция, похоже, этого не делает.

Если я получу ElementRange, а затем пройдусь по нему, я смогу создать TextLayoutFormat, который содержит форматы для всех листьев в диапазоне элементов.

var currentFormat:TextLayoutFormat;
var currentParagraphFormat:TextLayoutFormat;
var containerFormat: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);
    }

    // following lines were change
    elementRange = ElementRange.createElementRange(richEditableText.textFlow, selectionStart, selectionEnd);
    currentFormat = getElementRangeFormat(elementRange);

    editManager.clearFormat(currentFormat, currentParagraphFormat, containerFormat);

}

// method to get format of the selected 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;
}
person 1.21 gigawatts    schedule 04.02.2018