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 zoom on first click #83826

Merged
merged 3 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
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
30 changes: 16 additions & 14 deletions extensions/image-preview/media/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
let ctrlPressed = false;
let altPressed = false;
let hasLoadedImage = false;
let consumeClick = false;
let consumeClick = true;
let isActive = false;

// Elements
const container = document.body;
Expand Down Expand Up @@ -117,10 +118,16 @@
});
}

function changeActive(value) {
function setActive(value) {
isActive = value;
if (value) {
container.classList.add('zoom-in');
consumeClick = true;
if (isMac ? altPressed : ctrlPressed) {
container.classList.remove('zoom-in');
container.classList.add('zoom-out');
} else {
container.classList.remove('zoom-out');
container.classList.add('zoom-in');
}
} else {
ctrlPressed = false;
altPressed = false;
Expand Down Expand Up @@ -202,7 +209,10 @@
return;
}

consumeClick = false;
ctrlPressed = e.ctrlKey;
altPressed = e.altKey;

consumeClick = !isActive;
});

container.addEventListener('click', (/** @type {MouseEvent} */ e) => {
Expand All @@ -214,14 +224,6 @@
return;
}

ctrlPressed = e.ctrlKey;
altPressed = e.altKey;

if (isMac ? altPressed : ctrlPressed) {
container.classList.remove('zoom-in');
container.classList.add('zoom-out');
}

if (consumeClick) {
consumeClick = false;
return;
Expand Down Expand Up @@ -308,7 +310,7 @@
break;

case 'setActive':
changeActive(e.data.value);
setActive(e.data.value);
break;

case 'zoomIn':
Expand Down
3 changes: 2 additions & 1 deletion extensions/image-preview/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Preview extends Disposable {

this._register(webviewEditor.onDidChangeViewState(() => {
this.update();
this.webviewEditor.webview.postMessage({ type: 'setActive', value: this.webviewEditor.active });
}));

this._register(webviewEditor.onDidDispose(() => {
Expand All @@ -139,6 +140,7 @@ class Preview extends Disposable {

this.render();
this.update();
this.webviewEditor.webview.postMessage({ type: 'setActive', value: this.webviewEditor.active });
}

public zoomIn() {
Expand Down Expand Up @@ -175,7 +177,6 @@ class Preview extends Disposable {
}
this._previewState = PreviewState.Visible;
}
this.webviewEditor.webview.postMessage({ type: 'setActive', value: this.webviewEditor.active });
}

private getWebiewContents(): string {
Expand Down