1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Pop open a message when user deletes an annotation

When a user deletes any number of annotations, they are notified of the action
by a popup message with an undo button. Besides that, this change reuses the
existing messageBar CSS class from the new alt-text dialog as much as possible.
This commit is contained in:
Ujjwal Sharma 2024-10-22 13:23:47 +05:30
parent 962eb6206a
commit dd82d78a2d
11 changed files with 321 additions and 3 deletions

View file

@ -69,6 +69,7 @@ import { AltTextManager } from "web-alt_text_manager";
import { AnnotationEditorParams } from "web-annotation_editor_params";
import { CaretBrowsingMode } from "./caret_browsing.js";
import { DownloadManager } from "web-download_manager";
import { EditorUndoBar } from "./editor_undo_bar.js";
import { OverlayManager } from "./overlay_manager.js";
import { PasswordPrompt } from "./password_prompt.js";
import { PDFAttachmentViewer } from "web-pdf_attachment_viewer";
@ -192,6 +193,7 @@ const PDFViewerApplication = {
_isCtrlKeyDown: false,
_caretBrowsing: null,
_isScrolling: false,
editorUndoBar: null,
// Called once when the document is loaded.
async initialize(appConfig) {
@ -461,6 +463,10 @@ const PDFViewerApplication = {
: null;
}
if (appConfig.editorUndoBar) {
this.editorUndoBar = new EditorUndoBar(appConfig.editorUndoBar, eventBus);
}
const enableHWA = AppOptions.get("enableHWA");
const pdfViewer = new PDFViewer({
container,
@ -470,6 +476,7 @@ const PDFViewerApplication = {
linkService: pdfLinkService,
downloadManager,
altTextManager,
editorUndoBar: this.editorUndoBar,
findController,
scriptingManager:
AppOptions.get("enableScripting") && pdfScriptingManager,
@ -2732,7 +2739,7 @@ function onTouchEnd(evt) {
this._isPinching = false;
}
function onClick(evt) {
function closeSecondaryToolbar(evt) {
if (!this.secondaryToolbar?.isOpen) {
return;
}
@ -2749,6 +2756,20 @@ function onClick(evt) {
}
}
function closeEditorUndoBar(evt) {
if (!this.editorUndoBar?.isOpen) {
return;
}
if (this.appConfig.secondaryToolbar?.toolbar.contains(evt.target)) {
this.editorUndoBar.hide();
}
}
function onClick(evt) {
closeSecondaryToolbar.call(this, evt);
closeEditorUndoBar.call(this, evt);
}
function onKeyUp(evt) {
// evt.ctrlKey is false hence we use evt.key.
if (evt.key === "Control") {
@ -2759,6 +2780,20 @@ function onKeyUp(evt) {
function onKeyDown(evt) {
this._isCtrlKeyDown = evt.key === "Control";
if (
this.editorUndoBar?.isOpen &&
evt.keyCode !== 9 &&
evt.keyCode !== 16 &&
!(
(evt.keyCode === 13 || evt.keyCode === 32) &&
getActiveOrFocusedElement() === this.appConfig.editorUndoBar.undoButton
)
) {
// Hide undo bar on keypress except for Shift, Tab, Shift+Tab.
// Also avoid hiding if the undo button is triggered.
this.editorUndoBar.hide();
}
if (this.overlayManager.active) {
return;
}