@@ -2,7 +2,7 @@ import { toRaw } from 'vue';
2
2
import { isEmpty } from 'lodash-es' ;
3
3
4
4
import { Id , MContainer , MNode , NodeType } from '@tmagic/schema' ;
5
- import { isPage , isPageFragment } from '@tmagic/utils' ;
5
+ import { calcValueByFontsize , isPage , isPageFragment } from '@tmagic/utils' ;
6
6
7
7
import editorService from '@editor/services/editor' ;
8
8
import propsService from '@editor/services/props' ;
@@ -15,7 +15,7 @@ import { generatePageNameByApp, getInitPositionStyle } from '@editor/utils/edito
15
15
* @param config 待粘贴的元素配置(复制时保存的那份配置)
16
16
* @returns
17
17
*/
18
- export const beforePaste = ( position : PastePosition , config : MNode [ ] ) : MNode [ ] => {
18
+ export const beforePaste = ( position : PastePosition , config : MNode [ ] , doc ?: Document ) : MNode [ ] => {
19
19
if ( ! config [ 0 ] ?. style ) return config ;
20
20
const curNode = editorService . get ( 'node' ) ;
21
21
// 将数组中第一个元素的坐标作为参照点
@@ -29,7 +29,7 @@ export const beforePaste = (position: PastePosition, config: MNode[]): MNode[] =
29
29
if ( ! isEmpty ( pastePosition ) && curNode ?. items ) {
30
30
// 如果没有传入粘贴坐标则可能为键盘操作,不再转换
31
31
// 如果粘贴时选中了容器,则将元素粘贴到容器内,坐标需要转换为相对于容器的坐标
32
- pastePosition = getPositionInContainer ( pastePosition , curNode . id ) ;
32
+ pastePosition = getPositionInContainer ( pastePosition , curNode . id , doc ) ;
33
33
}
34
34
35
35
// 将所有待粘贴元素坐标相对于多选第一个元素坐标重新计算,以保证多选粘贴后元素间距不变
@@ -71,12 +71,12 @@ export const beforePaste = (position: PastePosition, config: MNode[]): MNode[] =
71
71
* @param id 元素id
72
72
* @returns PastePosition 转换后的坐标
73
73
*/
74
- export const getPositionInContainer = ( position : PastePosition = { } , id : Id ) => {
74
+ export const getPositionInContainer = ( position : PastePosition = { } , id : Id , doc ?: Document ) => {
75
75
let { left = 0 , top = 0 } = position ;
76
76
const parentEl = editorService . get ( 'stage' ) ?. renderer ?. contentWindow ?. document . getElementById ( `${ id } ` ) ;
77
77
const parentElRect = parentEl ?. getBoundingClientRect ( ) ;
78
- left = left - ( parentElRect ?. left || 0 ) ;
79
- top = top - ( parentElRect ?. top || 0 ) ;
78
+ left = left - calcValueByFontsize ( doc , parentElRect ?. left || 0 ) ;
79
+ top = top - calcValueByFontsize ( doc , parentElRect ?. top || 0 ) ;
80
80
return {
81
81
left,
82
82
top,
0 commit comments