pdfrx
pdfrx copied to clipboard
Is there an API to clear the current text selection?
Whenever a user selects some text, the callback
onTextSelectionChange: (selection) { _selectedText = selection; },
gets called.
But I would also like to clear the selection (eg after calling _addCurrentSelectionToMarkers in the example app).
Is this possible?
No at the current released version. I'm still working on text selection and the git master has the changes to add the feature.
See the disucssion #265.
The following code seems to work fine to clear the selection (based on the info in #265 but without using a perPageSelectableRegionInjector)
T? findChildWidget<T extends Widget>(BuildContext context) {
T? foundWidget;
void search(Element element) {
if (element.widget is T) {
foundWidget = element.widget as T;
} else {
element.visitChildren(search);
}
}
context.visitChildElements(search);
return foundWidget;
}
void clearSelection() {
//find the internal SelectableRegion
SelectableRegion? selectableRegion = findChildWidget<SelectableRegion>(context);
if (selectableRegion?.key is GlobalKey) {
final state = (selectableRegion!.key as GlobalKey<SelectableRegionState>).currentState;
state?.clearSelection();
}
}