VisibleSelection sel = document().visibleSelection(); String selectedText = sel.isRange() ? sel.toNormalizedRange().text() : String();
VisiblePosition endPos = VisiblePosition::lastPositionInNode(node); VisibleSelection sel = document().visibleSelection(); sel.setExtent(endPos);This example shows how to extend the current visible selection to include a specified DOM node. The `VisiblePosition` object is constructed to represent the last position in the node, and then the `visibleSelection()` method is used to get the current selection. Finally, the `setExtent()` method is used to set the newly extended selection. Package/library: WebKit (part of the larger GTK+ and KDE projects)