# canUndo method returns true even after last annotation manipulated from historyManager

**URL:** <https://pdfjs.community/t/canundo-method-returns-true-even-after-last-annotation-manipulated-from-historymanager/278>\
**Category:** Technical Support\
**Created:** [September 21, 2020, 6:00am UTC](https://pdfjs.community/t/canundo-method-returns-true-even-after-last-annotation-manipulated-from-historymanager/278 "2020-09-21T06:00:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivek.sonawane](https://avatars.discourse-cdn.com/v4/letter/v/e95f7d/32.png) [@vivek.sonawane](https://pdfjs.community/u/vivek.sonawane)\
**Post date:** [September 21, 2020, 6:00am UTC](https://pdfjs.community/t/canundo-method-returns-true-even-after-last-annotation-manipulated-from-historymanager/278/1 "2020-09-21T06:00:54Z")

</div>

Hi,  
We have 2 buttons for undo and redo and after click on the respective buttons each time, we check for canUndo/canRedo methods to enable or disable these buttons. redo button works perfect but on undo button we need one extra click to disable it .  
code:  
const historyManager = this.getHistoryManager();  
if (historyManager.canUndo()) historyManager.undo();  
this.isUndo = !historyManager.canUndo();  
this.isRedo = false;

Thank you,  
Vivek Sonawane

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [September 22, 2020, 2:58pm UTC](https://pdfjs.community/t/canundo-method-returns-true-even-after-last-annotation-manipulated-from-historymanager/278/2 "2020-09-22T14:58:29Z")

</div>

Hey there!

I cannot reproduce, but I believe its because `undo()` is async and you are not waiting for that promise to resolve.

```javascript
const historyManager = this.getHistoryManager();
if (historyManager.canUndo()) {
   await historyManager.undo();
}
this.isUndo = !historyManager.canUndo();
this.isRedo = false;

```

The documentation does not state it is async, but we will fix that ASAP.

I hope this helps!  
Thanks,  
Logan
