1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #18812 from Snuffleupagus/pr-15522-followup

Ensure that the CursorTools-buttons are disabled e.g. during editing (PR 15522 follow-up)
This commit is contained in:
Jonas Jenwald 2024-09-28 19:20:56 +02:00 committed by GitHub
commit a7e1bf64c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 9 deletions

View file

@ -65,7 +65,19 @@ class PDFCursorTools {
// Cursor tools cannot be used in PresentationMode/AnnotationEditor.
return;
}
this.#switchTool(tool);
}
#switchTool(tool, disabled = false) {
if (tool === this.#active) {
if (this.#prevActive !== null) {
// Ensure that the `disabled`-attribute of the buttons will be updated.
this.eventBus.dispatch("cursortoolchanged", {
source: this,
tool,
disabled,
});
}
return; // The requested tool is already active.
}
@ -103,6 +115,7 @@ class PDFCursorTools {
this.eventBus.dispatch("cursortoolchanged", {
source: this,
tool,
disabled,
});
}
@ -122,21 +135,17 @@ class PDFCursorTools {
presentationModeState = PresentationModeState.NORMAL;
const disableActive = () => {
const prevActive = this.#active;
this.switchTool(CursorTool.SELECT);
this.#prevActive ??= prevActive; // Keep track of the first one.
this.#prevActive ??= this.#active; // Keep track of the first one.
this.#switchTool(CursorTool.SELECT, /* disabled = */ true);
};
const enableActive = () => {
const prevActive = this.#prevActive;
if (
prevActive !== null &&
this.#prevActive !== null &&
annotationEditorMode === AnnotationEditorType.NONE &&
presentationModeState === PresentationModeState.NORMAL
) {
this.#switchTool(this.#prevActive);
this.#prevActive = null;
this.switchTool(prevActive);
}
};

View file

@ -240,11 +240,14 @@ class SecondaryToolbar {
eventBus._on("spreadmodechanged", this.#spreadModeChanged.bind(this));
}
#cursorToolChanged({ tool }) {
#cursorToolChanged({ tool, disabled }) {
const { cursorSelectToolButton, cursorHandToolButton } = this.#opts;
toggleCheckedBtn(cursorSelectToolButton, tool === CursorTool.SELECT);
toggleCheckedBtn(cursorHandToolButton, tool === CursorTool.HAND);
cursorSelectToolButton.disabled = disabled;
cursorHandToolButton.disabled = disabled;
}
#scrollModeChanged({ mode }) {