diff --git a/common/changes/@visactor/vtable/fix-copy-not-work-3968_2025-06-18-03-51.json b/common/changes/@visactor/vtable/fix-copy-not-work-3968_2025-06-18-03-51.json new file mode 100644 index 0000000000..c4429a6597 --- /dev/null +++ b/common/changes/@visactor/vtable/fix-copy-not-work-3968_2025-06-18-03-51.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "fix: copy not work when after copy tooltip text #3968\n\n", + "type": "none", + "packageName": "@visactor/vtable" + } + ], + "packageName": "@visactor/vtable", + "email": "892739385@qq.com" +} \ No newline at end of file diff --git a/packages/vtable/examples/index.html b/packages/vtable/examples/index.html index 69f6ad7a75..ea8509c66d 100644 --- a/packages/vtable/examples/index.html +++ b/packages/vtable/examples/index.html @@ -20,7 +20,9 @@
-
+
+

test test test

+
diff --git a/packages/vtable/src/event/listener/table-group.ts b/packages/vtable/src/event/listener/table-group.ts index 8abf037a60..5cfecce13d 100644 --- a/packages/vtable/src/event/listener/table-group.ts +++ b/packages/vtable/src/event/listener/table-group.ts @@ -23,6 +23,7 @@ import { getCellMergeInfo } from '../../scenegraph/utils/get-cell-merge'; import type { CheckBox, CheckboxAttributes, Radio } from '@src/vrender'; import { handleWhell } from '../scroll'; import { fireMoveColEventListeners } from '../helper'; +import { clearPageSelection } from '../../tools/env'; export function bindTableGroupListener(eventManager: EventManager) { const table = eventManager.table; const stateManager = table.stateManager; @@ -395,6 +396,7 @@ export function bindTableGroupListener(eventManager: EventManager) { event: e.nativeEvent }); } + clearPageSelection(); // table.eventManager.isPointerDownOnTable = true; // setTimeout(() => { // table.eventManager.isPointerDownOnTable = false; diff --git a/packages/vtable/src/tools/env.ts b/packages/vtable/src/tools/env.ts index aa2008db5e..76c2405d16 100644 --- a/packages/vtable/src/tools/env.ts +++ b/packages/vtable/src/tools/env.ts @@ -84,3 +84,37 @@ function defaultMode(): EnvMode { } return mode; } +/** + * 清空页面上的所有文本选择,使用多种兼容性方法 + */ +export function clearPageSelection(): void { + try { + const selection = window.getSelection(); + if (selection) { + // 方法1: removeAllRanges() - 标准方法,最广泛支持 + if (typeof selection.removeAllRanges === 'function') { + selection.removeAllRanges(); + console.log('使用 removeAllRanges() 清空selection'); + return; + } + + // 方法2: empty() - IE 和一些旧浏览器 + if (typeof (selection as any).empty === 'function') { + (selection as any).empty(); + console.log('使用 empty() 清空selection'); + return; + } + + // 方法3: collapse() - 备用方法 + if (typeof selection.collapse === 'function') { + selection.collapse(document.body, 0); + console.log('使用 collapse() 清空selection'); + return; + } + + console.warn('无法清空selection:不支持的浏览器'); + } + } catch (error) { + console.warn('清空selection时出错:', error); + } +}