fix(image-annotate): v1.13.1 Shift+X 改成交换填充色与描边色(原来是把填充关掉)

用户反馈「矩形 圆形 钢笔,切换填充与描边色的时候,会导致填充丢掉」,补充一句
「shift+x … 再按这个快捷键填色又回来了,但是描边一直不变」。

实测把能想到的入口全跑了一遍(工具栏两格、色板 tab、SV 拖动、hex、选项栏原生色块、
矩形/圆形/钢笔含闭合与未闭合):fillColor 从来没被清空,画面像素也没丢。
真正的错在 Shift+X 的语义 —— 它绑的是「实心 ↔ 只描边」开关,按一次填充被关掉、
描边色纹丝不动,观感就是「填充色丢了、再按才回来」。而 PS 的 X 是交换前景/背景色。

新增 swapShapeColors(),Shift+X 改为:
- 描边色 ⇄ 填充色对调(同时同步 S.color 与 S.shapeFillColor)
- 填充开关状态不动(交换的是颜色,不是有无)
- 箭头跳过,填充仍「跟随描边色」时只提示不改数据,一步历史可撤销
实心/描边切换仍保留在选项栏那两个按钮上,只把 tooltip 里「(Shift+X 切换)」改掉。

回归:harness 那条旧用例换成「色值互换 + fill 开关不变 + 再按回到原样」,
并挪到文件末尾(交换会写 S.shapeFillColor,夹在中间会污染「新建图形填充跟随描边」
那条断言)。192 项全通,validate 9/9;截图确认钢笔 绿填充/红描边 → 红填充/绿描边。
This commit is contained in:
qiqi committed 2026-11-08 22:53:34 +08:00
1 parent bf32ec6ddb
commit 546999fdf9
6 files changed
+145 -37

No files matched your search

+47 -13
View File
@@ -865,18 +865,8 @@ selShapeDbg = await dbg()
check('选中矩形就地改线宽 9', selShapeDbg.shapes[selShapeDbg.shapes.length - 1].lw === 9,
JSON.stringify(selShapeDbg.shapes.slice(-1)))
// Shift+X:选中形状切 描边/实心(PS 风格;数字框输完值直接按也必须生效)
check('Shift+X 切换选中形状 描边/实心(对象与选项栏按钮同步)', await (async () => {
await page.keyboard.press('Shift+x')
const d = await dbg()
const sh = d.shapes.find(s => s.id === d.selectedShapeId)
const btnActive = await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').classList.contains('active'))
const flipped = sh && sh.fill === true && btnActive
await page.keyboard.press('Shift+x') // 切回描边,恢复现场
const d2 = await dbg()
const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId)
return flipped && sh2 && sh2.fill === false
})())
// Shift+X 的用例在文件末尾(它会把「下一个图形的填充色」也写成具体色值,
// 落在中间会污染后面「新建图形填充默认跟随描边色」那条断言)
// 钢笔:闭合路径选中后同样可切描边/实心
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
@@ -1082,7 +1072,7 @@ check('画笔按住 Alt 临时吸色,松开 Alt 回到画笔(可连续取色
: 'up: tool=' + d3.tool + ' alt=' + d3.altPicker
})())
// Shift+X:选中形状切 描边/实心(PS 风格,用户裁定 2026-11-04 晚)
// Shift+X 的用例见上面「Shift+X 交换填充色与描边色」(v1.13.1 起是交换语义,不再是实心/描边开关)
// 图层快捷键:Ctrl+]/[ 上/下移、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 选层、Delete 删图层
// 注意:__debug().layers 是 S.layers 数组原序,叠放顺序必须看 z(位图与矢量共用一套 z)
@@ -2399,6 +2389,50 @@ check('无选中时 Ctrl+] 有 toast 提示(不再无声失败)', await (asy
return t.indexOf('选中') >= 0
})())
// ---- v1.13.1:Shift+X 改成「交换填充色与描边色」(以前是 实心/描边 开关)----
// 旧语义下按一次,填充被关掉、描边纹丝不动 —— 用户的原话是「丢失填充色」。
// 放在最后跑:交换会把「下一个图形的填充色」也写成具体色值,前面有条断言要求它是 null。
const shiftXSwap = await (async () => {
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
const a = { x: imgBox.x + imgBox.width * 0.10, y: imgBox.y + imgBox.height * 0.10 }
const b = { x: imgBox.x + imgBox.width * 0.30, y: imgBox.y + imgBox.height * 0.30 }
await page.mouse.move(a.x, a.y); await page.mouse.down()
await page.mouse.move(b.x, b.y, { steps: 6 }); await page.mouse.up()
await page.waitForTimeout(180)
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
await page.mouse.click((a.x + b.x) / 2, (a.y + b.y) / 2)
await page.waitForTimeout(150)
// 给个独立填充色,描边色保持主色,两边不同才看得出交换
await page.evaluate(() => {
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
el.value = '#22cc55'
el.dispatchEvent(new Event('input', { bubbles: true }))
el.dispatchEvent(new Event('change', { bubbles: true }))
})
await page.waitForTimeout(180)
const d0 = await dbg()
const sh0 = d0.shapes.find(s => s.id === d0.selectedShapeId)
if (!sh0) return { ok: false, detail: '没选中形状' }
const stroke0 = sh0.color, fill0 = sh0.fillColor, fillOn0 = sh0.fill
await page.keyboard.press('Shift+x')
const d1 = await dbg()
const sh1 = d1.shapes.find(s => s.id === d1.selectedShapeId)
const swapped = Boolean(sh1 && sh1.color === fill0 && sh1.fillColor === stroke0 && sh1.fill === fillOn0)
await page.keyboard.press('Shift+x') // 再按一次回到原样
const d2 = await dbg()
const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId)
const back = Boolean(sh2 && sh2.color === stroke0 && sh2.fillColor === fill0 && sh2.fill === fillOn0)
return {
ok: swapped && back,
detail: JSON.stringify({
原: { 描边: stroke0, 填充: fill0, 填充开: fillOn0 },
交换后: sh1 && { 描边: sh1.color, 填充: sh1.fillColor, 填充开: sh1.fill },
再按: sh2 && { 描边: sh2.color, 填充: sh2.fillColor }
})
}
})()
check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail)
await page.locator('[data-action="cancel"]').click()
const openState = await poll(async () => page.evaluate(() => window.__openState))
check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',