本文整理汇总了C++中VisibleSelection::selectionType方法的典型用法代码示例。如果您正苦于以下问题:C++ VisibleSelection::selectionType方法的具体用法?C++ VisibleSelection::selectionType怎么用?C++ VisibleSelection::selectionType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VisibleSelection
的用法示例。
在下文中一共展示了VisibleSelection::selectionType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visibleSelectionForClosestActualWordStart
VisibleSelection visibleSelectionForClosestActualWordStart(const VisibleSelection& selection)
{
// VisibleSelection validation has a special case when the caret is at the end of a paragraph where
// it selects the paragraph marker. As well, if the position is at the end of a word, it will select
// only the space between words. We want to select an actual word so we move the selection to
// the start of the leftmost word if the character after the selection point is whitespace.
if (selection.selectionType() != VisibleSelection::RangeSelection) {
int leftDistance = 0;
int rightDistance = 0;
VisibleSelection leftSelection(previousWordPosition(selection.start()));
bool leftSelectionIsOnWord = !isWhitespace(leftSelection.visibleStart().characterAfter()) && leftSelection.start().containerNode() == selection.start().containerNode();
if (leftSelectionIsOnWord) {
VisibleSelection rangeSelection(endOfWord(leftSelection.start()), selection.visibleStart());
leftDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get());
}
VisibleSelection rightSelection = previousWordPosition(nextWordPosition(selection.start()));
bool rightSelectionIsOnWord = !isWhitespace(rightSelection.visibleStart().characterAfter()) && rightSelection.start().containerNode() == selection.start().containerNode();
if (rightSelectionIsOnWord) {
VisibleSelection rangeSelection = VisibleSelection(rightSelection.visibleStart(), selection.visibleStart());
rightDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get());
}
// Make sure we found an actual word. If not, return the original selection.
if (!leftSelectionIsOnWord && !rightSelectionIsOnWord)
return selection;
if (!rightSelectionIsOnWord || (leftSelectionIsOnWord && leftDistance <= rightDistance)) {
// Left is closer or right is invalid.
return leftSelection;
}
// Right is closer or equal, or left was invalid.
return rightSelection;
}
// No adjustment required.
return selection;
}