Skip to content

Conversation

legraina
Copy link

@legraina legraina commented Aug 30, 2025

I have created a different PR as requested.

Move current pointer field of DrawingEditor to CurrentPointer class in tools.js. Also, only reset pointer type when user select a new mode.

  • PointerType:
    • The pointer types fields have been moved to a CurrentPointer object in tools.js. This object is used by eraser.js and ink.js
    • Clear the pointer type when changing mode, instead of at the end of the session. It seems more stable, as the method is not called this way when the user changes pages.
    • Only clear the pointer type when the mode is changed by an event (the user changes the editor type), otherwise, the same pointer type is kept (the document is changed for example).

@legraina legraina mentioned this pull request Aug 30, 2025
10 tasks
return true;
}

CurrentPointer.#pointerIds?.delete(pointerId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange to delete something in a function which is supposed to be a simple checker.
The delete is because originally the pointer was up or cancel which means that this pointer is no more active, consequently I'm not sure it makes sense to use this function here:
https://github.com/mozilla/pdf.js/pull/20213/files#diff-02919db67aef2f378464ba4c97e5f59e1e114498a147113025cd4163287f25f4R802

Copy link
Author

@legraina legraina Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the function name to isSamePointerIdOrRemove. And I also created a isSamePointerId function for the last check you were referencing to.

// For example, we started with a pen and the user
// is now using a finger.
return;
}

// For example, the user is using a second finger.
(DrawingEditor.#currentPointerIds ||= new Set()).add(e.pointerId);
CurrentPointer.initializeAndAddPointerId(e.pointerId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, the comment above this line should be copied, pasted and adapted in the new class you introduced.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've modified the comments and put some of them in the new class.

@@ -42,6 +42,78 @@ function bindEvents(obj, element, names) {
}
}

/**
* Class to store current pointer used by the editor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't exactly correct: the idea is more about handling multiple pointers (fingers, pen, mouse, ...)

Copy link
Author

@legraina legraina Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the comment, and change the name of the class to CurrentPointers.

DrawingEditor.#currentPointerType &&
DrawingEditor.#currentPointerType !== pointerType
) {
if (CurrentPointer.isInitializedAndDifferentPointerType(pointerType)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above should be updated: the variable currentPointerType isn't defined in this file.
Probably a part of it should be moved in the new class you created.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done.

return false;
}

static isPointerType() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert in english, but the name looks strange for me... I'd have said hasPointerType.
I just read again https://github.com/mozilla/pdf.js/pull/20213/files#diff-02919db67aef2f378464ba4c97e5f59e1e114498a147113025cd4163287f25f4R670 and I've the feeling that this class should be initialized with this the pointer type and the static methods in this class shouldn't be static. An instance could be created in startDrawing and set in a static member of DrawingEditor.

Copy link
Author

@legraina legraina Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the name.
For the logic, I feel that we need a static class outside of the editor if we want all editors to share the same pointer type. It's really important for pdf with multiple pages as each page has its own editor, and you don't want to reinitialized the pointer type on each page. Furthermore, when you use this mode for the first time, you want to initialize the pointer type, and the only way to do that is to check if the pointer type is null. Also, you will have to put the class with a getter/setter if you want to be able to clear it outside of the DrawingEditor (it's the only way to check if the mode is changed to the best of my knowledge, or perhaps through disableEditing).

@@ -1767,13 +1839,16 @@ class AnnotationEditorUIManager {
* edit mode.
* @param {boolean} [editComment] - true if the mode change is due to a
* comment edit.
* @param {boolean} [isFromEvent] - true if the mode change is due to an event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but this change should be in an other patch.
I've the feeling you're fixing a bug and if it's the case we should have an integration test for it.

Copy link
Author

@legraina legraina Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm creating a new PR #20226. This PR should be merged before.

@calixteman
Copy link
Contributor

Please update the title of the PR to precise its goal in few words.

@legraina legraina changed the title CurrentPointer A new CurrentPointers class to store current pointers used by the editor Sep 3, 2025
Copy link
Author

@legraina legraina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made most of the modifications asked.

@legraina legraina changed the title A new CurrentPointers class to store current pointers used by the editor [Editor] A new CurrentPointers class to store current pointers used by the editor Sep 3, 2025
@legraina
Copy link
Author

legraina commented Sep 9, 2025

Hi @calixteman, everything looks good ? Or anything else to change/improve ? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants