Skip to content

Commit 5c46b4e

Browse files
committed
fix: 🚸 优化卷轴模式下需要多次调小缩放值才能看到效果的情况
#285
1 parent 952a016 commit 5c46b4e

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/components/Manga/actions/scrollMode.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { clamp } from 'helper';
1+
import { clamp, createRootMemo } from 'helper';
22

33
import { store } from '../store';
44
import { setOption } from './helper';
@@ -21,13 +21,34 @@ export const setAdjustToWidth = (
2121
});
2222
};
2323

24+
const minImgWidth = createRootMemo(() => {
25+
let min = Number.POSITIVE_INFINITY;
26+
for (const img of Object.values(store.imgMap))
27+
if (img.width && img.width < min) min = img.width;
28+
return min;
29+
});
30+
2431
/** 在卷轴模式下进行缩放,并且保持滚动进度不变 */
2532
export const setImgScale = (val: number | ((oldVal: number) => number)) => {
2633
if (typeof val === 'function') val = val(store.option.scrollMode.imgScale);
2734
if (Number.isNaN(val)) return;
2835

2936
const jump = saveScrollProgress();
3037
setOption((draftOption) => {
38+
val = clamp(0.1, val as number, 3);
39+
40+
// 如果当前最小图片宽度都大于视窗宽度,并且这次操作是在调小缩放值
41+
// 那就将这次操作改为:将缩放值修改为只要缩小一点就会立刻让图片变小的极限值
42+
// 避免用户需要多次调小缩放值才能看到效果的情况
43+
// https://github.com/hymbz/ComicReadScript/issues/285
44+
if (
45+
minImgWidth() <= store.rootSize.width &&
46+
val < draftOption.scrollMode.imgScale
47+
) {
48+
const maxImgScale = store.rootSize.width / minImgWidth();
49+
if (val > maxImgScale) val = maxImgScale;
50+
}
51+
3152
draftOption.scrollMode.imgScale = clamp(0.1, Number(val.toFixed(2)), 3);
3253
});
3354
jump();

0 commit comments

Comments
 (0)