Repository: mozilla/pdf.js
File: src/display/editor/tools.js (JavaScript)

Code before:

  static #moveTimestamp = NaN;

  static initializeAndAddPointerId(pointerId) {
    (CurrentPointer.#pointerIds ||= new Set()).add(pointerId);
  }

  static setPointer(pointerType, pointerId) {
    CurrentPointer.#pointerId ||= pointerId;
    CurrentPointer.#pointerType ??= pointerType;
  }

  static setTimeStamp(timeStamp) {
    CurrentPointer.#moveTimestamp = timeStamp;
  }

  static isSamePointerId(pointerId) {
    if (CurrentPointer.#pointerId === pointerId) {
      return true;
    }

    CurrentPointer.#pointerIds?.delete(pointerId);
    return false;
  }

  static isPointerType() {
    return CurrentPointer.#pointerType !== null;
  }

  static isSamePointerType(pointerType) {
    return CurrentPointer.#pointerType === pointerType;
  }

  static isInitializedAndDifferentPointerType(pointerType) {
    return (
      CurrentPointer.isPointerType() &&
      !CurrentPointer.isSamePointerType(pointerType)
    );
  }

  static isSameTimeStamp(timeStamp) {
    return CurrentPointer.#moveTimestamp === timeStamp;
  }

  static isUsingMultiplePointers() {
    return CurrentPointer.#pointerIds?.size >= 1;
  }

  static clearPointerType() {
    CurrentPointer.#pointerType = null;
  }

Review comment (suggestion):
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.

Code after:

  static #pointerIds = null;

  // Track the timestamp to know if the touchmove event is used.
  static #moveTimestamp = NaN;

  // The pointerType is used to know if we are using a mouse, a pen or a touch.
  static #pointerType = null;

  static initializeAndAddPointerId(pointerId) {
    // Store pointer ids. For example, the user is using a second finger.
    (CurrentPointers.#pointerIds ||= new Set()).add(pointerId);
  }

  static setPointer(pointerType, pointerId) {
    CurrentPointers.#pointerId ||= pointerId;
    CurrentPointers.#pointerType ??= pointerType;
  }

  static setTimeStamp(timeStamp) {
    CurrentPointers.#moveTimestamp = timeStamp;
  }

  static isSamePointerId(pointerId) {
    return CurrentPointers.#pointerId === pointerId;
  }

  // Check if it's the same pointer id, otherwise remove it from the set.
  static isSamePointerIdOrRemove(pointerId) {
    if (CurrentPointers.#pointerId === pointerId) {
      return true;
    }

    CurrentPointers.#pointerIds?.delete(pointerId);
    return false;
  }

  static isSamePointerType(pointerType) {
    return CurrentPointers.#pointerType === pointerType;
  }

  static isInitializedAndDifferentPointerType(pointerType) {
    return (
      CurrentPointers.#pointerType !== null &&
      !CurrentPointers.isSamePointerType(pointerType)
    );
  }

  static isSameTimeStamp(timeStamp) {
    return CurrentPointers.#moveTimestamp === timeStamp;
  }