That’s why I don’t have instance object, so I cannot follow this topic to prevent Delete key pressing behaviour. I see that, when I press the Delete key, the delete action (for annotationManager) is triggered and the annotation vanishes from the PDF file. I don’t want to that.
I tried to define addEventListener for documentViewer and stop Delete key by preventDefault or stopPropagation, but it doesn’t work. I even tried to get an advice from this topic, but the only effect, that I can achieve, is an infinite loop.
OK, I could probably prevent this with the document (not documentViewer), but I still want to use Delete key in a form, when an annotation is selected.
In my case, is it even possible to programatically stop deleting annotations after pressing Delete key?
You can get the instance by importing the getInstance function from the WebViewer library.
This will allow you to use the instance to disable any hotkeys.
Thanks for the advice. Unfortunately, this won’t help in my case.
To create my own UI, I followed this tutorial. Therefore I cannot import anything from @pdftron/webviewer. Is there another solution to use your great library?
Considering version 8.7 - I checked 8.7.4 and in my case it is not useful because the library throws an error:
from this line in PDFJSDocumentType.js file: window.instance.addSearchListener(function(searchValue, options, results)
and pdf is not loaded. Perhaps this is the “instance”, but I don’t have it.
After taking a closer look at our documentation on hotkeys guide, it appears that we do not have an available hotkey for the delete key, so I don’t think this method will work.
You mentioned that you tried adding a confirmation popup before deleting and that causes an infinite loop? Could you explain this in more detail? What errors are you receiving and could you provide the code?
One possible solution could be to redraw the annotation whenever a user deletes it. Would something like this work for you?
Yes! This is exactly what i meant earlier . This solution is even beter, because I don’t have to remember to “unblock” the deletion if I want to programatically remove annotations. Also, I just realized that Backspace button behaves the same way (although it should be obvious for me). Thank you for all your help.