Skip to content

Commit 392a82b

Browse files
authored
chore: improve image preview editor style (#2020)
1 parent df33204 commit 392a82b

3 files changed

Lines changed: 32 additions & 48 deletions

File tree

packages/file-scheme/src/browser/preview.view.tsx

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import { useInjectable, Disposable, DomListener } from '@opensumi/ide-core-browser';
3+
import { useInjectable, Disposable } from '@opensumi/ide-core-browser';
44
import { ReactEditorComponent, IResource } from '@opensumi/ide-editor/lib/browser';
55
import { StaticResourceService } from '@opensumi/ide-static-resource/lib/browser';
66

@@ -35,41 +35,6 @@ export const ImagePreview: ReactEditorComponent<null> = (props) => {
3535
const disposer = new Disposable();
3636
if (imgRef.current) {
3737
imgRef.current.src = src;
38-
const last = imgRef.current;
39-
imgRef.current.onload = (ev) => {
40-
if (last !== imgRef.current) {
41-
// 已经不是同一个元素,放弃
42-
return;
43-
}
44-
if (imgContainerRef.current && imgRef.current) {
45-
const container = imgContainerRef.current!;
46-
let delta = 0;
47-
const originalWidth = imgRef.current!.width;
48-
const originalHeight = imgRef.current!.height;
49-
const scale = originalHeight / originalWidth;
50-
function setSize() {
51-
container.style.width = originalWidth + delta + 'px';
52-
container.style.height = originalHeight + delta * scale + 'px';
53-
}
54-
setSize();
55-
disposer.addDispose(
56-
new DomListener(container.parentElement!, 'wheel', (e) => {
57-
// ctrlKey 为 true 代表 mac 上的 pinch gesture
58-
if (e.ctrlKey) {
59-
if (e.deltaY > 0) {
60-
e.preventDefault();
61-
delta -= e.deltaY * 10;
62-
setSize();
63-
} else if (e.deltaY < 0) {
64-
e.preventDefault();
65-
delta -= e.deltaY * 10;
66-
setSize();
67-
}
68-
}
69-
}),
70-
);
71-
}
72-
};
7338
}
7439
return () => {
7540
disposer.dispose();

packages/file-scheme/src/browser/style.module.less

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
11
.kt_image_preview {
22
height: 100%;
3+
display: flex;
4+
35
> div {
46
background-image: linear-gradient(
57
45deg,
6-
rgb(230, 230, 230) 25%,
8+
var(--editorImagePreview-background) 25%,
79
transparent 25%,
810
transparent 75%,
9-
rgb(230, 230, 230) 75%,
10-
rgb(230, 230, 230)
11+
var(--editorImagePreview-background) 75%,
12+
var(--editorImagePreview-background)
1113
),
1214
linear-gradient(
1315
45deg,
14-
rgb(230, 230, 230) 25%,
16+
var(--editorImagePreview-background) 25%,
1517
transparent 25%,
1618
transparent 75%,
17-
rgb(230, 230, 230) 75%,
18-
rgb(230, 230, 230)
19+
var(--editorImagePreview-background) 75%,
20+
var(--editorImagePreview-background)
1921
);
2022
background-size: 16px 16px;
2123
background-position: 0 0, 8px 8px;
22-
background-color: #fff;
23-
display: block;
24+
background-color: var(--editor-background);
25+
display: flex;
26+
justify-content: center;
27+
align-items: center;
2428
margin: 0 auto;
29+
flex: 1;
30+
padding: 20px;
2531
}
32+
2633
img {
27-
image-rendering: pixelated;
2834
display: block;
2935
margin: 0 auto;
3036
flex-grow: 0;
31-
width: 100%;
32-
height: 100%;
37+
width: auto;
38+
height: auto;
39+
max-width: 100%;
40+
max-height: 100%;
3341
}
3442
}
3543

packages/theme/src/common/color-tokens/editor.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { registerColor, transparent, lighten, darken, lessProminent } from '../u
55

66
import { badgeBackground, badgeForeground } from './badge';
77
import { contrastBorder, activeContrastBorder, focusBorder, foreground } from './base';
8-
import { backgroundColor, foregroundColor } from './basic-color';
98
import { listInactiveSelectionBackground } from './list-tree';
9+
1010
// TODO COLOR 此处vscode内的editor error warning info颜色都有做修改
1111
export const editorErrorBackground = registerColor(
1212
'editorError.background',
@@ -874,3 +874,14 @@ export const editorInlayHintParameterBackground = registerColor(
874874
},
875875
localize('editorInlayHintBackgroundParameter', 'Background color of inline hints for parameters'),
876876
);
877+
878+
export const editorImagePreviewBackground = registerColor(
879+
'editorImagePreview.background',
880+
{
881+
dark: new Color(new RGBA(20, 20, 20)),
882+
light: new Color(new RGBA(230, 230, 230)),
883+
hcLight: new Color(new RGBA(230, 230, 230)),
884+
hcDark: new Color(new RGBA(20, 20, 20)),
885+
},
886+
localize('editorImagePreviewBackground', 'Background color of image preview editor.'),
887+
);

0 commit comments

Comments
 (0)