Skip to content

Commit ebd8564

Browse files
committed
refactor: enhance SVG edit box positioning
1 parent 019ac75 commit ebd8564

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/utils/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export const editTopic = function (this: MindElixirInstance, el: Topic) {
172172
if (e.shiftKey) return
173173

174174
e.preventDefault()
175-
div?.blur()
175+
div.blur()
176176
this.map.focus()
177177
}
178178
})

src/utils/svg.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,16 @@ export const editSvgText = function (mei: MindElixirInstance, textEl: SVGTextEle
6767
div.textContent = origin
6868
div.contentEditable = 'true'
6969
div.spellcheck = false
70-
const l = textEl.getAttribute('x')
71-
const t = textEl.getAttribute('y')
72-
div.style.cssText = `min-width:${88}px;position:absolute;left:${l}px;top:${t}px;`
73-
const anchor = textEl.getAttribute('text-anchor')
74-
if (anchor === 'end') div.style.cssText += 'transform: translate(-100%, -100%);'
75-
else if (anchor === 'middle') div.style.cssText += 'transform: translate(-50%, -100%);'
76-
else div.style.cssText += 'transform: translate(0, -100%);'
70+
const bbox = textEl.getBBox()
71+
console.log(bbox)
72+
div.style.cssText = `
73+
min-width:${Math.max(88, bbox.width)}px;
74+
position:absolute;
75+
left:${bbox.x}px;
76+
top:${bbox.y}px;
77+
padding: 2px 4px;
78+
margin: -2px -4px;
79+
`
7780
div.focus()
7881

7982
selectText(div)

0 commit comments

Comments
 (0)