优化:当编辑节点文本时节点在画布外时移入画布内
This commit is contained in:
parent
ec22656bee
commit
e676bff453
@ -1,4 +1,4 @@
|
|||||||
import { getStrWithBrFromHtml } from './utils'
|
import { getStrWithBrFromHtml, checkNodeOuter } from './utils'
|
||||||
|
|
||||||
// 节点文字编辑类
|
// 节点文字编辑类
|
||||||
export default class TextEdit {
|
export default class TextEdit {
|
||||||
@ -60,6 +60,8 @@ export default class TextEdit {
|
|||||||
|
|
||||||
// 显示文本编辑框
|
// 显示文本编辑框
|
||||||
show(node) {
|
show(node) {
|
||||||
|
let { offsetLeft, offsetTop } = checkNodeOuter(this.mindMap, node)
|
||||||
|
this.mindMap.view.translateXY(offsetLeft, offsetTop)
|
||||||
let rect = node._textData.node.node.getBoundingClientRect()
|
let rect = node._textData.node.node.getBoundingClientRect()
|
||||||
if (this.mindMap.richText) {
|
if (this.mindMap.richText) {
|
||||||
this.mindMap.richText.showEditText(node, rect)
|
this.mindMap.richText.showEditText(node, rect)
|
||||||
|
|||||||
@ -124,6 +124,13 @@ class View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 平移x,y方向
|
||||||
|
translateXY(x, y) {
|
||||||
|
this.x += x
|
||||||
|
this.y += y
|
||||||
|
this.transform()
|
||||||
|
}
|
||||||
|
|
||||||
// 平移x方向
|
// 平移x方向
|
||||||
translateX(step) {
|
translateX(step) {
|
||||||
this.x += step
|
this.x += step
|
||||||
|
|||||||
@ -302,4 +302,34 @@ export const nextTick = function (fn, ctx) {
|
|||||||
pending = true
|
pending = true
|
||||||
timerFunc(handle, 0)
|
timerFunc(handle, 0)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查节点是否超出画布
|
||||||
|
export const checkNodeOuter = (mindMap, node) => {
|
||||||
|
let elRect = mindMap.elRect
|
||||||
|
let { scaleX, scaleY, translateX, translateY } = mindMap.draw.transform()
|
||||||
|
let { left, top, width, height } = node
|
||||||
|
let right = (left + width) * scaleX + translateX
|
||||||
|
let bottom = (top + height) * scaleY + translateY
|
||||||
|
left = left * scaleX + translateX
|
||||||
|
top = top * scaleY + translateY
|
||||||
|
let offsetLeft = 0
|
||||||
|
let offsetTop = 0
|
||||||
|
if (left < 0) {
|
||||||
|
offsetLeft = -left
|
||||||
|
}
|
||||||
|
if (right > elRect.width) {
|
||||||
|
offsetLeft = -(right - elRect.width)
|
||||||
|
}
|
||||||
|
if (top < 0) {
|
||||||
|
offsetTop = -top
|
||||||
|
}
|
||||||
|
if (bottom > elRect.height) {
|
||||||
|
offsetTop = -(bottom - elRect.height)
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
isOuter: offsetLeft !== 0 || offsetTop !== 0,
|
||||||
|
offsetLeft,
|
||||||
|
offsetTop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user