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

optimize double-click #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/ui/container/container.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ export abstract class ContainerView {
// click event: hide container view
this.imgInfo.oitContainerEl.addEventListener('click', this.closeContainerView);
}
matchedImg.imgViewEl.addEventListener('dblclick', this.dblclickImgView);
matchedImg.imgViewEl.addEventListener('mouseenter', this.mouseenterImgView);
matchedImg.imgViewEl.addEventListener('mouseleave', this.mouseleaveImgView);
// drag the image via mouse
Expand All @@ -505,6 +506,7 @@ export abstract class ContainerView {
if (!this.isPinMode()) {
this.imgInfo.oitContainerEl.removeEventListener('click', this.closeContainerView);
}
matchedImg.imgViewEl.removeEventListener('dblclick', this.dblclickImgView);
matchedImg.imgViewEl.removeEventListener('mouseenter', this.mouseenterImgView);
matchedImg.imgViewEl.removeEventListener('mouseleave', this.mouseleaveImgView);
matchedImg.imgViewEl.removeEventListener('mousedown', this.mousedownImgView);
Expand Down Expand Up @@ -689,6 +691,16 @@ export abstract class ContainerView {
}
}

protected dblclickImgView = (event: MouseEvent) => {
event.stopPropagation();
event.preventDefault();
const activeImg = this.getAndUpdateActiveImg(event);
if (!activeImg) return;
if (0 == event.button) { // left click
this.clickImgToolbar(null, this.plugin.settings.doubleClickToolbar, activeImg);
}
}

/**
* move the image by mouse or keyboard
* @param event
Expand Down Expand Up @@ -748,11 +760,6 @@ export abstract class ContainerView {
this.imgGlobalStatus.clickTimer = setTimeout(() => {
const clickCount = this.imgGlobalStatus.clickCount;
this.resetClickTimer();
if (2 === clickCount) { // double click
if (!activeImg) activeImg = this.imgGlobalStatus.activeImg;
// console.log('mousedownImgView: double click...', activeImg.index);
this.clickImgToolbar(null, this.plugin.settings.doubleClickToolbar, activeImg);
}
}, 200);
}

Expand Down