# Undo traced point to last point when we click ctrl+z while tracing/drawing annotation and not the entire tracing

**URL:** <https://pdfjs.community/t/undo-traced-point-to-last-point-when-we-click-ctrl-z-while-tracing-drawing-annotation-and-not-the-entire-tracing/533>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [February 22, 2021, 1:21pm UTC](https://pdfjs.community/t/undo-traced-point-to-last-point-when-we-click-ctrl-z-while-tracing-drawing-annotation-and-not-the-entire-tracing/533 "2021-02-22T13:21:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiran.patil](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kiran.patil](https://pdfjs.community/u/kiran.patil)\
**Post date:** [February 22, 2021, 1:21pm UTC](https://pdfjs.community/t/undo-traced-point-to-last-point-when-we-click-ctrl-z-while-tracing-drawing-annotation-and-not-the-entire-tracing/533/1 "2021-02-22T13:21:23Z")

</div>

**PDF.js Express Version**  
Version: 7.2.0

**Detailed description of issue**  
Suppose if user accidently put one vertex at wrong place **while tracing** area/perimeter. So if he hits CTRL+Z to undo that last vertex point while tracing then it should get removed/undo and not the entire annotation. Also tracing should not get ended if undo is triggered.

How can I achieve this ?

**Expected behaviour**  
Undo a vertex point while tracing if user accidently put one vertex at wrong place then by clicking ctrl+z it should go back to point 1 back.

**Code snippet**  
` this.viewerInstance.hotkeys.on('ctrl+z, command+z', e => {`  
` e.preventDefault();`  
` this.undoRedoEnable.emit(new UndoRedoEnable(!this.getHistoryManager().canUndo(),this.isRedo)); });`

---

<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:** [March 1, 2021, 6:54pm UTC](https://pdfjs.community/t/undo-traced-point-to-last-point-when-we-click-ctrl-z-while-tracing-drawing-annotation-and-not-the-entire-tracing/533/2 "2021-03-01T18:54:15Z")

</div>

Hey!

This code should do the trick for you. Basically you just need to get the annotation thats being drawn and pop an item of its path.

I also had to do a hack to work around the history manager deleting the last annotation.

```javascript
  instance.hotkeys.on(
    instance.hotkeys.Keys.CTRL_Z,
    (e) => {
      const currentTool = instance.getToolMode();
      if (currentTool.name === instance.Tools.ToolNames.PERIMETER_MEASUREMENT) {

        const historyManager = instance.docViewer.getAnnotationHistoryManager();

        historyManager.one('historyChanged', () => {
          historyManager.redo();
        })

        e.preventDefault();
        e.stopPropagation();
        if (currentTool.annotation && currentTool.annotation.popPath) {
          currentTool.annotation.popPath();
        }
      }
    }
  )

```

Thanks!  
Logan
