Merge pull request #15522 from Snuffleupagus/editor-disable-cursor-tools

[Editing] Disable the HandTool during editing (bug 1792422)
This commit is contained in:
Jonas Jenwald 2022-09-29 11:09:44 +02:00 committed by GitHub
commit 294db228bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { AnnotationEditorType } from "pdfjs-lib";
import { GrabToPan } from "./grab_to_pan.js"; import { GrabToPan } from "./grab_to_pan.js";
import { PresentationModeState } from "./ui_utils.js"; import { PresentationModeState } from "./ui_utils.js";
@ -40,7 +41,7 @@ class PDFCursorTools {
this.eventBus = eventBus; this.eventBus = eventBus;
this.active = CursorTool.SELECT; this.active = CursorTool.SELECT;
this.activeBeforePresentationMode = null; this.previouslyActive = null;
this.handTool = new GrabToPan({ this.handTool = new GrabToPan({
element: this.container, element: this.container,
@ -63,13 +64,13 @@ class PDFCursorTools {
} }
/** /**
* NOTE: This method is ignored while Presentation Mode is active.
* @param {number} tool - The cursor mode that should be switched to, * @param {number} tool - The cursor mode that should be switched to,
* must be one of the values in {CursorTool}. * must be one of the values in {CursorTool}.
*/ */
switchTool(tool) { switchTool(tool) {
if (this.activeBeforePresentationMode !== null) { if (this.previouslyActive !== null) {
return; // Cursor tools cannot be used in Presentation Mode. // Cursor tools cannot be used in PresentationMode/AnnotationEditor.
return;
} }
if (tool === this.active) { if (tool === this.active) {
return; // The requested tool is already active. return; // The requested tool is already active.
@ -121,24 +122,54 @@ class PDFCursorTools {
this.switchTool(evt.tool); this.switchTool(evt.tool);
}); });
this.eventBus._on("presentationmodechanged", evt => { let annotationEditorMode = AnnotationEditorType.NONE,
switch (evt.state) { presentationModeState = PresentationModeState.NORMAL;
case PresentationModeState.FULLSCREEN: {
const previouslyActive = this.active;
this.switchTool(CursorTool.SELECT); const disableActive = () => {
this.activeBeforePresentationMode = previouslyActive; const previouslyActive = this.active;
break;
}
case PresentationModeState.NORMAL: {
const previouslyActive = this.activeBeforePresentationMode;
if (previouslyActive !== null) { this.switchTool(CursorTool.SELECT);
this.activeBeforePresentationMode = null; this.previouslyActive ??= previouslyActive; // Keep track of the first one.
this.switchTool(previouslyActive); };
} const enableActive = () => {
break; const previouslyActive = this.previouslyActive;
}
if (
previouslyActive !== null &&
annotationEditorMode === AnnotationEditorType.NONE &&
presentationModeState === PresentationModeState.NORMAL
) {
this.previouslyActive = null;
this.switchTool(previouslyActive);
}
};
this.eventBus._on("secondarytoolbarreset", evt => {
if (this.previouslyActive !== null) {
annotationEditorMode = AnnotationEditorType.NONE;
presentationModeState = PresentationModeState.NORMAL;
enableActive();
}
});
this.eventBus._on("annotationeditormodechanged", ({ mode }) => {
annotationEditorMode = mode;
if (mode === AnnotationEditorType.NONE) {
enableActive();
} else {
disableActive();
}
});
this.eventBus._on("presentationmodechanged", ({ state }) => {
presentationModeState = state;
if (state === PresentationModeState.NORMAL) {
enableActive();
} else if (state === PresentationModeState.FULLSCREEN) {
disableActive();
} }
}); });
} }