Skip to content

Commit 907cceb

Browse files
Merge pull request #20460 from calixteman/issue20452
[Editor] Allow to save an edited comment in using CTRL+Enter shortcut.
2 parents 40b52fa + b6fcb52 commit 907cceb

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

test/integration/comment_spec.mjs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import {
1717
awaitPromise,
18+
clearInput,
1819
closePages,
1920
createPromise,
2021
dragAndDrop,
@@ -851,4 +852,62 @@ describe("Comment", () => {
851852
);
852853
});
853854
});
855+
856+
describe("Save a comment in using CTRL+Enter", () => {
857+
let pages;
858+
859+
beforeEach(async () => {
860+
pages = await loadAndWait(
861+
"comments.pdf",
862+
".annotationEditorLayer",
863+
"page-fit",
864+
null,
865+
{ enableComment: true }
866+
);
867+
});
868+
869+
afterEach(async () => {
870+
await closePages(pages);
871+
});
872+
873+
it("must check that the comment is saved", async () => {
874+
await Promise.all(
875+
pages.map(async ([browserName, page]) => {
876+
const commentButtonSelector = `[data-annotation-id="612R"] + button.annotationCommentButton`;
877+
await waitAndClick(page, commentButtonSelector);
878+
const commentPopupSelector = "#commentPopup";
879+
const editButtonSelector = `${commentPopupSelector} button.commentPopupEdit`;
880+
await waitAndClick(page, editButtonSelector);
881+
882+
const textInputSelector = "#commentManagerTextInput";
883+
await page.waitForSelector(textInputSelector, {
884+
visible: true,
885+
});
886+
await clearInput(page, textInputSelector, true);
887+
const comment = "Comment saved using CTRL+Enter";
888+
await page.type(textInputSelector, comment);
889+
await page.focus(textInputSelector);
890+
891+
await page.keyboard.down("Control");
892+
await page.keyboard.press("Enter");
893+
await page.keyboard.up("Control");
894+
895+
await page.waitForSelector("#commentManagerDialog", {
896+
visible: false,
897+
});
898+
899+
await page.hover(commentButtonSelector);
900+
await page.waitForSelector(commentPopupSelector, {
901+
visible: true,
902+
});
903+
const popupTextSelector = `${commentPopupSelector} .commentPopupText`;
904+
const popupText = await page.evaluate(
905+
selector => document.querySelector(selector).textContent,
906+
popupTextSelector
907+
);
908+
expect(popupText).withContext(`In ${browserName}`).toEqual(comment);
909+
})
910+
);
911+
});
912+
});
854913
});

web/alt_text_manager.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ class AltTextManager {
8787
saveButton.addEventListener("click", this.#save.bind(this));
8888
optionDescription.addEventListener("change", onUpdateUIState);
8989
optionDecorative.addEventListener("change", onUpdateUIState);
90+
textarea.addEventListener("keydown", e => {
91+
if (
92+
(e.ctrlKey || e.metaKey) &&
93+
e.key === "Enter" &&
94+
!saveButton.disabled
95+
) {
96+
this.#save();
97+
}
98+
});
9099

91100
this.#overlayManager.register(dialog);
92101
}

web/comment_manager.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,15 @@ class CommentDialog {
723723
textInput.addEventListener("input", () => {
724724
saveButton.disabled = textInput.value === this.#previousText;
725725
});
726+
textInput.addEventListener("keydown", e => {
727+
if (
728+
(e.ctrlKey || e.metaKey) &&
729+
e.key === "Enter" &&
730+
!saveButton.disabled
731+
) {
732+
this.#save();
733+
}
734+
});
726735

727736
// Make the dialog draggable.
728737
let pointerMoveAC;

web/new_alt_text_manager.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ class NewAltTextManager {
141141
textarea.addEventListener("input", () => {
142142
this.#toggleTitleAndDisclaimer();
143143
});
144+
textarea.addEventListener("keydown", e => {
145+
if (
146+
(e.ctrlKey || e.metaKey) &&
147+
e.key === "Enter" &&
148+
!saveButton.disabled
149+
) {
150+
this.#save();
151+
}
152+
});
144153

145154
eventBus._on("enableguessalttext", ({ value }) => {
146155
this.#toggleGuessAltText(value, /* isInitial = */ false);

0 commit comments

Comments
 (0)