Skip to content

[Editor] 元素被设定editable为false后,通过select函数选择元素仍可被编辑的问题 #794

@dawumusic

Description

@dawumusic

你好,业务中发现,如果元素的editable为false,使用editor.select()方式选中UI后,会弹出EditBox并可被继续编辑,感觉和editable语义存在矛盾,看看是否可以改进。

测试视频:

CleanShot.2026-02-12.at.05.18.49.mp4

测试代码:

import { App, Rect } from 'leafer-ui'
import '@leafer-in/editor' // 导入图形编辑器插件  
import '@leafer-in/viewport' // 导入视口插件 (可选)

const app = new App({ view: window, editor: {} })

const rect1 = Rect.one({ editable: false,fill: '#FEB027', cornerRadius: [20, 0, 0, 20] }, 100, 100) 
const rect2 = Rect.one({ editable: true, fill: '#FFE04B', cornerRadius: [0, 20, 20, 0] }, 300, 100)

app.tree.add(rect1)
app.tree.add(rect2)
setTimeout(()=>{
    app.editor.select(rect1)        // 此处会触发EditBox显示,并且可被进一步编辑,但rect1声明了editable:false, 不应当再显示(保持editable语义逻辑的一致性)
},2000)

源码位置:
leafer-in/packages/editor/src/display/EditBox.ts

// ...
// line 152-159
    public update(): void {
        const { editor } = this
        const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true)
        // this.visible = !this.target.locked  <-- 我临时修改了这里
        this.visible = !this.target.locked && this.target.editable
        this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY })
        this.updateBounds({ x: 0, y: 0, width, height })
    }
// ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions