Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix double click #253

Merged
merged 2 commits into from
Jul 28, 2017
Merged

fix double click #253

merged 2 commits into from
Jul 28, 2017

Conversation

create-share
Copy link
Contributor

@create-share create-share commented Jul 27, 2017

Fix #252

Hi. I review the code about double click. I found there is no compare the double click target to the last mouseup target.

Sorry for my poor English. I wish I could help.

Codes in src/Stage.js:

    _mousedown: function(evt) {
       // ...
        if (shape && shape.isListening()) {
          this.clickStartShape = shape;
          shape._fireAndBubble(MOUSEDOWN, { evt: evt });
        }
        // ...
    },
    _mouseup: function(evt) {
      // workaround for mobile IE to force touch event when unhandled pointer event elevates into a mouse event
      if (Konva.UA.ieMobile) {
        return this._touchend(evt);
      }
      if (!Konva.UA.mobile) {
        this._setPointerPosition(evt);
        var shape = this.getIntersection(this.getPointerPosition()),
          clickStartShape = this.clickStartShape,
          fireDblClick = false,
          dd = Konva.DD;

        if (Konva.inDblClickWindow) {
          fireDblClick = true;
          Konva.inDblClickWindow = false;
        } else if (!dd || !dd.justDragged) {
          // don't set inDblClickWindow after dragging
          Konva.inDblClickWindow = true;
        } else if (dd) {
          dd.justDragged = false;
        }

        setTimeout(function() {
          Konva.inDblClickWindow = false;
        }, Konva.dblClickWindow);

        if (shape && shape.isListening()) {
          shape._fireAndBubble(MOUSEUP, { evt: evt });

          // detect if click or double click occurred
          if (
            Konva.listenClickTap &&
            clickStartShape &&
            clickStartShape._id === shape._id
          ) {
            shape._fireAndBubble(CLICK, { evt: evt });

            if (fireDblClick) {// <--- should check the double click target is the last mouseup target or not
              shape._fireAndBubble(DBL_CLICK, { evt: evt });
            }
          }
        }
        // ...
      }
    },

@lavrton
Copy link
Member

lavrton commented Jul 27, 2017

Yeah. Can you also write a unit test? In the best scenario, it should FAIL before the fix, and PASS after the fix.

@create-share
Copy link
Contributor Author

Yeah. I would like to do it.

@lavrton lavrton merged commit 9e179a2 into konvajs:master Jul 28, 2017
@lavrton
Copy link
Member

lavrton commented Jul 28, 2017

Thanks! 👍

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

Successfully merging this pull request may close these issues.

2 participants