fix(image-annotate): v1.2.10 选中形状/文字后切吸管取色能改对象颜色

- 根因:setTool() 切工具时无差别清掉 selectedShapeId/selectedTextId/selectedLayerId,
  选中形状按 I 切吸管时选中态当场丢失,applyColorChange 找不到对象,颜色只写进画笔色
- 修复:picker 作为临时工具保留选中态(与 select 同级白名单);exitPicker 按落回的工具用
  同一套规则清理,避免画笔工具下残留选中框
- 吸管提示文案补充「选中形状/文字时取色直接改它的颜色」
- __debug().shapes 补 color 字段;harness 新增 1 项回归断言(114 项全绿)
This commit is contained in:
qiqi committed 2026-11-04 22:52:46 +08:00
1 parent 9d923aed26
commit 0d161d6ded
7 files changed
+52 -15

No files matched your search

+1 -1
View File
@@ -145,7 +145,7 @@ import { bindEvents } from './events.js'
<button class="iwb-editor-tool" data-tool="arrow" title="箭头 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></button>
<button class="iwb-editor-tool" data-tool="picker" title="吸管 (I):点击画布取色(悬停预览),取色后自动切回上一工具"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
<button class="iwb-editor-tool" data-tool="picker" title="吸管 (I):点击画布取色(悬停预览);选中形状/文字时取色直接改它的颜色,取完切回上一工具"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
<button class="iwb-editor-tool" data-tool="hand" title="抓手 (H):拖拽自由移动画布(任意工具下按住空格或鼠标中键也可平移)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"/><path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v2"/><path d="M10 10.5V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v8"/><path d="M18 10a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/></svg></button>
+1 -1
View File
@@ -810,7 +810,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
const OPT_HINTS = {
crop: '裁剪栏在画布下方;裁剪与选区互斥,确认后可 Ctrl+Z 撤销',
select: '点击选中元素,拖拽移动,手柄缩放',
picker: '点击画布取色,取完自动切回上一个工具',
picker: '点击画布取色;选中形状/文字时取色直接改它的颜色,取完自动切回上一个工具',
hand: '拖拽平移画布;任意工具下按住空格也可以',
marquee: '拖出选区 → 操作条就在选区旁边',
lasso: '按住拖动画圈,松手闭合'
+1 -1
View File
@@ -288,7 +288,7 @@ import { toast } from './commands.js'
zoom: S.zoom,
fit: { w: Math.round(S.fitW || 0), h: Math.round(S.fitH || 0) },
layers: S.layers.map(l => ({ id: l.id, name: l.name, z: l.z, locked: !!l.locked, visible: l.visible !== false })),
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z })),
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color })),
texts: S.textLayers.map(t => ({ id: t.id, text: t.text })),
selectedShapeId: S.selectedShapeId,
selectedTextId: S.selectedTextId,
+12 -3
View File
@@ -323,6 +323,11 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
export function exitPicker() {
S.tool = (S.prevTool && S.prevTool !== 'picker') ? S.prevTool : 'brush'
S.prevTool = null
// 回到的若不是选择/形状类工具,选中态按 setTool 同一套规则清掉,避免画布残留选中框
const back = S.tool
if (back !== 'select') S.selectedLayerId = null
if (back !== 'text' && back !== 'select') S.selectedTextId = null
if (back !== 'rect' && back !== 'circle' && back !== 'arrow' && back !== 'pen' && back !== 'select') S.selectedShapeId = null
S.pickerComposite = null
hidePickerTip()
updateToolUI()
@@ -334,6 +339,7 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
cancelCrop()
hideCropBar()
}
// 回到上一个工具后选项栏由 updateToolUI() → renderOptionBar() 按新工具重建
renderObjects()
}
@@ -370,9 +376,12 @@ import { hexToRgb, rgbToHex } from '../vendor/image-math.js'
S.lassoPts = null
}
S.tool = tool
if (tool !== 'select') S.selectedLayerId = null
if (tool !== 'text' && tool !== 'select') S.selectedTextId = null
if (tool !== 'rect' && tool !== 'circle' && tool !== 'arrow' && tool !== 'pen' && tool !== 'select') S.selectedShapeId = null
// 吸管是临时取色工具:必须保留选中态,否则「选中形状 → 按 I 取色」时选中被清掉,
// applyColorChange 找不到对象,颜色只写进画笔色、形状不变(用户反馈 2026-11-04)
const keepSel = tool === 'select' || tool === 'picker'
if (!keepSel) S.selectedLayerId = null
if (tool !== 'text' && !keepSel) S.selectedTextId = null
if (tool !== 'rect' && tool !== 'circle' && tool !== 'arrow' && tool !== 'pen' && !keepSel) S.selectedShapeId = null
S.bitmapDrag = null
S.textDrag = null
S.shapeDrag = null