提交 9048856b 编写于 作者: M MartinBrathen 提交者: Matt Bierner

Fixed: Image preview should not zoom on first click if unfocused (#82074)

* Fixed a bug where first click on an unfocused image preview would zoom

* added two spaces

* removed unnecessary state variable

* User now has ability to enter zoom-out mode on first click

* removed some code that was not needed

* removed useless if statement
上级 3d320280
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
let ctrlPressed = false; let ctrlPressed = false;
let altPressed = false; let altPressed = false;
let hasLoadedImage = false; let hasLoadedImage = false;
let consumeClick = false;
// Elements // Elements
const container = document.body; const container = document.body;
...@@ -116,6 +117,18 @@ ...@@ -116,6 +117,18 @@
}); });
} }
function changeActive(value) {
if (value) {
container.classList.add('zoom-in');
consumeClick = true;
} else {
ctrlPressed = false;
altPressed = false;
container.classList.remove('zoom-out');
container.classList.remove('zoom-in');
}
}
function firstZoom() { function firstZoom() {
if (!image || !hasLoadedImage) { if (!image || !hasLoadedImage) {
return; return;
...@@ -152,6 +165,18 @@ ...@@ -152,6 +165,18 @@
} }
}); });
container.addEventListener('mousedown', (/** @type {MouseEvent} */ e) => {
if (!image || !hasLoadedImage) {
return;
}
if (e.button !== 0) {
return;
}
consumeClick = false;
});
container.addEventListener('click', (/** @type {MouseEvent} */ e) => { container.addEventListener('click', (/** @type {MouseEvent} */ e) => {
if (!image || !hasLoadedImage) { if (!image || !hasLoadedImage) {
return; return;
...@@ -161,6 +186,18 @@ ...@@ -161,6 +186,18 @@
return; 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;
}
// left click // left click
if (scale === 'fit') { if (scale === 'fit') {
firstZoom(); firstZoom();
...@@ -218,7 +255,6 @@ ...@@ -218,7 +255,6 @@
}); });
container.classList.add('image'); container.classList.add('image');
container.classList.add('zoom-in');
image.classList.add('scale-to-fit'); image.classList.add('scale-to-fit');
...@@ -254,6 +290,9 @@ ...@@ -254,6 +290,9 @@
case 'setScale': case 'setScale':
updateScale(e.data.scale); updateScale(e.data.scale);
break; break;
case 'setActive':
changeActive(e.data.value);
break;
} }
}); });
}()); }());
...@@ -120,6 +120,7 @@ export class Preview extends Disposable { ...@@ -120,6 +120,7 @@ export class Preview extends Disposable {
} }
this._previewState = PreviewState.Visible; this._previewState = PreviewState.Visible;
} }
this.webviewEditor.webview.postMessage({ type: 'setActive', value: this.webviewEditor.active });
} }
private getWebiewContents(): string { private getWebiewContents(): string {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册