Skip to content

Commit d98029d

Browse files
fix(editor): 修复pad大屏模式下粘贴位置计算错误偏移问题 (#612)
* fix: 修复moveable中custom able旋转中心错误问题 * fix: 修复修复pad大屏模式下粘贴位置偏差问题
1 parent a66da8d commit d98029d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/editor/src/services/editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,8 @@ class Editor extends BaseService {
734734

735735
public async doPaste(config: MNode[], position: PastePosition = {}): Promise<MNode[]> {
736736
propsService.clearRelateId();
737-
const pasteConfigs = beforePaste(position, cloneDeep(config));
737+
const doc = this.get('stage')?.renderer.contentWindow?.document;
738+
const pasteConfigs = beforePaste(position, cloneDeep(config), doc);
738739
return pasteConfigs;
739740
}
740741

packages/editor/src/utils/operator.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { toRaw } from 'vue';
22
import { isEmpty } from 'lodash-es';
33

44
import { Id, MContainer, MNode, NodeType } from '@tmagic/schema';
5-
import { isPage, isPageFragment } from '@tmagic/utils';
5+
import { calcValueByFontsize, isPage, isPageFragment } from '@tmagic/utils';
66

77
import editorService from '@editor/services/editor';
88
import propsService from '@editor/services/props';
@@ -15,7 +15,7 @@ import { generatePageNameByApp, getInitPositionStyle } from '@editor/utils/edito
1515
* @param config 待粘贴的元素配置(复制时保存的那份配置)
1616
* @returns
1717
*/
18-
export const beforePaste = (position: PastePosition, config: MNode[]): MNode[] => {
18+
export const beforePaste = (position: PastePosition, config: MNode[], doc?: Document): MNode[] => {
1919
if (!config[0]?.style) return config;
2020
const curNode = editorService.get('node');
2121
// 将数组中第一个元素的坐标作为参照点
@@ -29,7 +29,7 @@ export const beforePaste = (position: PastePosition, config: MNode[]): MNode[] =
2929
if (!isEmpty(pastePosition) && curNode?.items) {
3030
// 如果没有传入粘贴坐标则可能为键盘操作,不再转换
3131
// 如果粘贴时选中了容器,则将元素粘贴到容器内,坐标需要转换为相对于容器的坐标
32-
pastePosition = getPositionInContainer(pastePosition, curNode.id);
32+
pastePosition = getPositionInContainer(pastePosition, curNode.id, doc);
3333
}
3434

3535
// 将所有待粘贴元素坐标相对于多选第一个元素坐标重新计算,以保证多选粘贴后元素间距不变
@@ -71,12 +71,12 @@ export const beforePaste = (position: PastePosition, config: MNode[]): MNode[] =
7171
* @param id 元素id
7272
* @returns PastePosition 转换后的坐标
7373
*/
74-
export const getPositionInContainer = (position: PastePosition = {}, id: Id) => {
74+
export const getPositionInContainer = (position: PastePosition = {}, id: Id, doc?: Document) => {
7575
let { left = 0, top = 0 } = position;
7676
const parentEl = editorService.get('stage')?.renderer?.contentWindow?.document.getElementById(`${id}`);
7777
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);
8080
return {
8181
left,
8282
top,

0 commit comments

Comments
 (0)