Skip to content

Commit

Permalink
Delete ink annotation if all its points are erased
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Aug 10, 2023
1 parent 9ba277c commit a7eba21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/common/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ class Reader {
this._annotationManager.updateAnnotations(annotations);
};

let onDeleteAnnotations = (ids) => {
this._annotationManager.deleteAnnotations(ids);
};

let onOpenLink = (url) => {
this._onOpenLink(url);
};
Expand Down Expand Up @@ -745,7 +749,8 @@ class Reader {
onRequestPassword,
onSetThumbnails,
onSetOutline,
onSetPageLabels
onSetPageLabels,
onDeleteAnnotations // For complete ink erase
});

if (primary) {
Expand Down
10 changes: 9 additions & 1 deletion src/pdf/pdf-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class PDFView {
this._onSetDataTransferAnnotations = options.onSetDataTransferAnnotations;
this._onAddAnnotation = options.onAddAnnotation;
this._onUpdateAnnotations = options.onUpdateAnnotations;
this._onDeleteAnnotations = options.onDeleteAnnotations;
this._onOpenLink = options.onOpenLink;
this._onSelectAnnotations = options.onSelectAnnotations;
this._onSetSelectionPopup = options.onSetSelectionPopup;
Expand Down Expand Up @@ -1967,7 +1968,14 @@ class PDFView {
}
else if (action.type === 'erase' && action.triggered) {
let annotations = [...action.annotations.values()];
this._onUpdateAnnotations(annotations);
let updated = annotations.filter( x => x.position.paths.length);
let deleted = annotations.filter( x => !x.position.paths.length);
if (updated.length) {
this._onUpdateAnnotations(updated);
}
if (deleted.length) {
this._onDeleteAnnotations(deleted.map(x => x.id));
}
}
}
else if (!this.action.alreadySelectedAnnotations && this._tool.type !== 'eraser') {
Expand Down

0 comments on commit a7eba21

Please sign in to comment.