Skip to content

Commit

Permalink
Merge pull request #18812 from Snuffleupagus/pr-15522-followup
Browse files Browse the repository at this point in the history
Ensure that the CursorTools-buttons are disabled e.g. during editing (PR 15522 follow-up)
  • Loading branch information
Snuffleupagus authored Sep 28, 2024
2 parents 642b9a5 + b1df164 commit a7e1bf6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
25 changes: 17 additions & 8 deletions web/pdf_cursor_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand Down Expand Up @@ -103,6 +115,7 @@ class PDFCursorTools {
this.eventBus.dispatch("cursortoolchanged", {
source: this,
tool,
disabled,
});
}

Expand All @@ -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);
}
};

Expand Down
5 changes: 4 additions & 1 deletion web/secondary_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down

0 comments on commit a7e1bf6

Please sign in to comment.