-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Activating annotation popup on demand #129
Comments
You can already use the useSelection hook (in the React version) or the setSelected API method (in the vanilla JS version) for this. Or am I misunderstanding? |
I don't understand how I can do this using the structure provided. |
Sorry, yes that's right. You'd need to go through the vanilla JS API, either the anno.setSelected method, or the anno.state.selection object. The Popup, by design, is supposed to show up for the selected annotation (programmatically or not). If your use case is different, you'd need to roll your own Popup component for now. |
Oh sure! I thought using the My original idea was to provide a way to communicate between If you think it would be better for the dev using the lib to make their own Popup with that behavior, that's fine. It's my first time using a open-source project like that, so if you have any thoughts on how to interact to it properly, please let me know. Thank's! |
I couldn't find TestPopup (but I'm semi-offline right now - looked only briefly from my phone). But I'd like to understand your use case better. Is there a reason you specifically don't want to use the selection to determine where a popup should be open? |
I'm just revisiting this & realize there's (probably) a different issue involved - one which I'm also running into right now. The popup only opens if there is an actual user action involved along with the selection. (Specifically, there needs to be a This means programmatic selection does currently not open the popup. I'm going to redesign this, but I'm not quite sure how yet. (CCing @oleksandr-danylchenko.) One part of the solution is probably that we should (as discussed previously) create annotations only after the selection is complete, not as soon as the selection starts. Why does this relate to this issue? Annotations are selected as soon as they are created. The fact the popup waits for the Therefore, if we change the behavior, so that the annotations get created (and selected!) only when the user is done with the text selection, there might be no more need for the |
P.S.: I think mobile interaction would still work just fine.
I wonder if there are anything potential gotchas I'm missing related to keyboard-based selection, @oleksandr-danylchenko? |
In a separate branch, I have now made a (surprisingly) tiny tweak to the selection handler to trigger the I don't have a solution for keyboard selection yet. Because there's no |
That's interesting... Because I faced an issue with Android, as it was never dispatching the |
Hm, yes indeed - I did have to "tap out" of the selection to make the appear on Chrome/Android (thus creating another Hm, that does suggest that the original model (create annotation immediately + update) may be more sustainable. Still leads back to the question of how to make the popup work without requiring a user event.... |
Maybe it's worth providing an additional Depression argument to the type TextPopupOpenExpression = boolean | ((selection: ReturnType<typeof useSelection>) => boolean);
interface TextAnnotationPopupProps {
...
open?: TextPopupOpenExpression;
} const selectedKey = selected.map(a => a.annotation.id).join('-');
useEffect(() => {
const { open } = props;
if (open !== undefined) {
setOpen(typeof open === 'function' ? open(selection) : open);
} else {
if (selected.length > 0 && event) {
setOpen(event.type === 'pointerup' || event.type === 'keydown');
}
}
}, [selectedKey, event]); |
I'm moving our conversation here, rather than burying it in the commit comment. So here's something I just learned: on Chrome Android, the thing that happens when the browser considers the text selection "complete" is that the context menu bubble pops up; and we're all supposed to listen to the About the general behavior: the models we've been discussing are:
The first one has some advantages, like moving the popup along with the annotation when the user changes selection (for your case @oleksandr-danylchenko), or broadcasting state change updates in our own multi-user system. (This way, users can see others make selections in realtime. Eye candy, really. But a nice touch.) On the other hand, there are also disadvantages. In particular frequent executions of That being said: which model we implement in the end may actually be less relevant. After all, the real question is: at what point should the popup appear? Right now the popup follows the |
CTRL+A really is the only oddball here... it does trigger selection change, but is otherwise not easily traceable, as you said. |
Given that CTRL+A is the "edge case" here, maybe it's simply worth treating it separately? Instead of tracing a sequence of events (start, select, end), it's really a one-shot operation which we could handle as such. Seems that this could be sufficient? const onSelectAll = (evt: KeyboardEvent) => {
onSelectStart(evt);
// Proper lifecycle management: clear selection first...
selection.clear();
// ...then add annotation to store
store.addAnnotation({
id: currentTarget.annotation,
bodies: [],
target: currentTarget
});
}
hotkeys('⌘+a', { element: container, keydown: true, keyup: false}, evt => {
onSelectAll(evt);
}) |
That's an interesting approach, I would give it a try! |
And one more small thing I realized now - we should conditionally listen to the |
Yes, I was thinking the same. In my branch, I'm now listening to both. But we should branch based on platform, as you say like described here. |
BTW: here's a small progress report: the new branch seems to be working well. As written previously: I'm now waiting for the selection to be "complete" before creating the annotation (for whatever that means on different platforms), avoiding the need to do more complex state tracing in the popup. The As will not surprise you: the way different platforms and interaction modes behave is... peculiar.
I tested all of this with Chrome and FF, BTW. Anyways: it's progress. I'll keep working on it. |
Well, then that's probably the solution. (Also, it's probably good practice to keep default browser behavior untouched as much as possible. Blocking the default context popup is probably an anti-pattern, anyway.) |
Some applications must show the annotation popup on demand, i.e., when a set of behaviors is triggered. The
SelectionHandler
already knows whether an annotation was clicked, so it just needs to export this possibility forTextAnnotator
.From this point on, we can provide a robust set of options for the
TextAnnotatorPopup
, which can be opened/closed on demand.The text was updated successfully, but these errors were encountered: