提交 e327a218 编写于 作者: M Matt Bierner

Reverse pinch zooming direction in resource viewer

Fixes #43138

**Bug**
Pinch opening should zoom in. Pinch close shoud zoom out. This is currently reversed

**Fix**
Invert the pinch direction. Only inverts pinches. Scrollwhell events should remain as-is: scroll up to zoom in scroll back to zoom out
上级 c2ffb2a7
...@@ -91,10 +91,6 @@ export interface IResourceDescriptor { ...@@ -91,10 +91,6 @@ export interface IResourceDescriptor {
mime: string; mime: string;
} }
enum ScaleDirection {
IN, OUT,
}
class BinarySize { class BinarySize {
public static readonly KB = 1024; public static readonly KB = 1024;
public static readonly MB = BinarySize.KB * BinarySize.KB; public static readonly MB = BinarySize.KB * BinarySize.KB;
...@@ -391,7 +387,9 @@ class InlineImageView { ...@@ -391,7 +387,9 @@ class InlineImageView {
const cacheKey = descriptor.resource.toString(); const cacheKey = descriptor.resource.toString();
let scaleDirection = ScaleDirection.IN; let ctrlPressed = false;
let altPressed = false;
const initialState: ImageState = InlineImageView.imageStateCache.get(cacheKey) || { scale: 'fit', offsetX: 0, offsetY: 0 }; const initialState: ImageState = InlineImageView.imageStateCache.get(cacheKey) || { scale: 'fit', offsetX: 0, offsetY: 0 };
let scale = initialState.scale; let scale = initialState.scale;
let img: Builder | null = null; let img: Builder | null = null;
...@@ -455,9 +453,10 @@ class InlineImageView { ...@@ -455,9 +453,10 @@ class InlineImageView {
if (!img) { if (!img) {
return; return;
} }
ctrlPressed = e.ctrlKey;
altPressed = e.altKey;
if (platform.isMacintosh ? e.altKey : e.ctrlKey) { if (platform.isMacintosh ? altPressed : ctrlPressed) {
scaleDirection = ScaleDirection.OUT;
c.removeClass('zoom-in').addClass('zoom-out'); c.removeClass('zoom-in').addClass('zoom-out');
} }
}) })
...@@ -466,8 +465,10 @@ class InlineImageView { ...@@ -466,8 +465,10 @@ class InlineImageView {
return; return;
} }
if (!(platform.isMacintosh ? e.altKey : e.ctrlKey)) { ctrlPressed = e.ctrlKey;
scaleDirection = ScaleDirection.IN; altPressed = e.altKey;
if (!(platform.isMacintosh ? altPressed : ctrlPressed)) {
c.removeClass('zoom-out').addClass('zoom-in'); c.removeClass('zoom-out').addClass('zoom-in');
} }
}) })
...@@ -485,7 +486,7 @@ class InlineImageView { ...@@ -485,7 +486,7 @@ class InlineImageView {
firstZoom(); firstZoom();
} }
if (scaleDirection === ScaleDirection.IN) { if (!(platform.isMacintosh ? altPressed : ctrlPressed)) { // zoom in
let i = 0; let i = 0;
for (; i < InlineImageView.zoomLevels.length; ++i) { for (; i < InlineImageView.zoomLevels.length; ++i) {
if (InlineImageView.zoomLevels[i] > scale) { if (InlineImageView.zoomLevels[i] > scale) {
...@@ -507,8 +508,9 @@ class InlineImageView { ...@@ -507,8 +508,9 @@ class InlineImageView {
if (!img) { if (!img) {
return; return;
} }
// pinching is reported as scroll wheel + ctrl
if (!e.ctrlKey) { const isScrollWhellKeyPressed = platform.isMacintosh ? altPressed : ctrlPressed;
if (!isScrollWhellKeyPressed && !e.ctrlKey) { // pinching is reported as scroll wheel + ctrl
return; return;
} }
...@@ -519,8 +521,12 @@ class InlineImageView { ...@@ -519,8 +521,12 @@ class InlineImageView {
firstZoom(); firstZoom();
} }
// scrolling up, pinching out should increase the scale let delta = e.deltaY < 0 ? 1 : -1;
const delta = e.deltaY < 0 ? 1 : -1;
// Pinching should increase the scale
if (e.ctrlKey && !isScrollWhellKeyPressed) {
delta *= -1;
}
updateScale(scale as number * (1 - delta * InlineImageView.SCALE_PINCH_FACTOR)); updateScale(scale as number * (1 - delta * InlineImageView.SCALE_PINCH_FACTOR));
}) })
.on(DOM.EventType.SCROLL, () => { .on(DOM.EventType.SCROLL, () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册