Skip to content

Commit

Permalink
Merge pull request #84 from concord-consortium/185363141-add-keyboard…
Browse files Browse the repository at this point in the history
…-annotation-deletes

feat: Add keyboard annotation deletes [PT-185363141]
  • Loading branch information
dougmartin authored Jun 28, 2024
2 parents 34fb762 + 56c7f07 commit afc9141
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/scripts/fabric-extensions/annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,32 @@ function handleAnnotations(annotationTool) {
});
}
});

canvas.on('text:editing:entered', (e) => {
e.target.__annotationTextLastValue = e.target.hiddenTextarea.value;
if (e.target.__annotationKeyUpHandler) {
e.target.hiddenTextarea.removeEventListener("keyup", e.target.__annotationKeyUpHandler);
}

e.target.__annotationKeyUpHandler = (keyEvent) => {
var key = keyEvent.key;
var value = e.target.hiddenTextarea.value;
if (((key === "Delete") || (key === "Backspace")) && (value === "") && (e.target.__annotationTextLastValue === "")) {
e.target.hiddenTextarea.removeEventListener("keyup", e.target.__annotationKeyUpHandler);
e.target.__annotationKeyUpHandler = null;
canvas.remove(e.target);
}
e.target.__annotationTextLastValue = value;
}
e.target.hiddenTextarea.addEventListener("keyup", e.target.__annotationKeyUpHandler);
});

canvas.on('text:editing:exiting', (e) => {
if (e.target.__annotationKeyUpHandler) {
e.target.hiddenTextarea.removeEventListener("keyup", e.target.__annotationKeyUpHandler);
e.target.__annotationKeyUpHandler = null;
}
});
}

module.exports = handleAnnotations;
Expand Down Expand Up @@ -305,6 +331,15 @@ module.exports = handleAnnotations;
point.y >= borderRect.top && point.y <= borderRect.top + borderRect.height;
},

exitEditing: function() {
// fire this before calling into the library so we have access to the hidden textarea
// which isn't present when the 'text:editing:exited' event is fired
if (this.canvas) {
this.canvas.fire('text:editing:exiting', { target: this });
}
this.callSuper('exitEditing');
},

_renderTextCommon: function (ctx, method) {
this.callSuper('_renderTextCommon', ctx, method);

Expand Down

0 comments on commit afc9141

Please sign in to comment.