webui: add Escape key handler to dismiss empty line comments
Dismiss the line comment input box when the Escape key is pressed
and the text input is empty.
Co-Authored-By: sketch <hello@sketch.dev>
diff --git a/webui/src/web-components/sketch-diff-view.ts b/webui/src/web-components/sketch-diff-view.ts
index ee7a12d..d08b520 100644
--- a/webui/src/web-components/sketch-diff-view.ts
+++ b/webui/src/web-components/sketch-diff-view.ts
@@ -512,6 +512,19 @@
cancelButton.onclick = () => this.closeDiffCommentBox();
}
+ // Add keydown event listener to handle Escape key
+ if (commentInput) {
+ commentInput.addEventListener("keydown", (event) => {
+ // If Escape key is pressed
+ if (event.key === "Escape") {
+ // If the comment input is empty, dismiss the comment box
+ if (commentInput.value.trim() === "") {
+ this.closeDiffCommentBox();
+ }
+ }
+ });
+ }
+
// Focus on the comment input
if (commentInput) {
commentInput.focus();