|
@@ -776,7 +776,10 @@ export default {
|
|
|
const end = Math.min(currentIndex + chunkSize, text.length);
|
|
const end = Math.min(currentIndex + chunkSize, text.length);
|
|
|
const chunk = text.slice(currentIndex, end);
|
|
const chunk = text.slice(currentIndex, end);
|
|
|
try {
|
|
try {
|
|
|
- this.editorRef && this.editorRef.command && this.editorRef.command.executeInsertText(chunk);
|
|
|
|
|
|
|
+ if (!this.safeExecuteInsertText(chunk)) {
|
|
|
|
|
+ console.warn('Failed to insert chunk, stopping chunk insertion');
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
console.error('Chunk insert failed:', err);
|
|
console.error('Chunk insert failed:', err);
|
|
|
}
|
|
}
|
|
@@ -865,7 +868,9 @@ export default {
|
|
|
if (text.includes('\t') || (text.includes('\n') && text.split('\n').some(line => line.includes('\t') || line.includes(' ')))) {
|
|
if (text.includes('\t') || (text.includes('\n') && text.split('\n').some(line => line.includes('\t') || line.includes(' ')))) {
|
|
|
console.log('Detected table data in table cell, using special paste');
|
|
console.log('Detected table data in table cell, using special paste');
|
|
|
// 直接插入原始文本,让编辑器处理制表符分隔
|
|
// 直接插入原始文本,让编辑器处理制表符分隔
|
|
|
- this.editorRef.command.executeInsertText(text);
|
|
|
|
|
|
|
+ if (!this.safeExecuteInsertText(text)) {
|
|
|
|
|
+ console.warn('Failed to insert text, falling back to default paste behavior');
|
|
|
|
|
+ }
|
|
|
return;
|
|
return;
|
|
|
} else {
|
|
} else {
|
|
|
console.log('Single cell data, using normal paste');
|
|
console.log('Single cell data, using normal paste');
|
|
@@ -877,6 +882,14 @@ export default {
|
|
|
if (!toInsert && htmlContent && htmlContent.trim()) {
|
|
if (!toInsert && htmlContent && htmlContent.trim()) {
|
|
|
const tempDiv = document.createElement('div');
|
|
const tempDiv = document.createElement('div');
|
|
|
tempDiv.innerHTML = htmlContent;
|
|
tempDiv.innerHTML = htmlContent;
|
|
|
|
|
+
|
|
|
|
|
+ // 如果HTML内容包含表格,先合并相邻的表格
|
|
|
|
|
+ const tables = tempDiv.querySelectorAll('table');
|
|
|
|
|
+ if (tables.length > 1) {
|
|
|
|
|
+ console.log(`Found ${tables.length} tables in pasted content, merging adjacent tables...`);
|
|
|
|
|
+ this.mergeAdjacentTables(tempDiv);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
toInsert = tempDiv.textContent || tempDiv.innerText || '';
|
|
toInsert = tempDiv.textContent || tempDiv.innerText || '';
|
|
|
}
|
|
}
|
|
|
if (toInsert) {
|
|
if (toInsert) {
|
|
@@ -893,7 +906,9 @@ export default {
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// 内容较小,直接插入
|
|
// 内容较小,直接插入
|
|
|
- this.editorRef.command.executeInsertText(toInsert);
|
|
|
|
|
|
|
+ if (!this.safeExecuteInsertText(toInsert)) {
|
|
|
|
|
+ console.warn('Failed to insert text, content may not be inserted');
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
console.warn('Both HTML and text content are empty or invalid.');
|
|
console.warn('Both HTML and text content are empty or invalid.');
|
|
@@ -907,6 +922,32 @@ export default {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ // 安全地执行插入文本操作
|
|
|
|
|
+ safeExecuteInsertText(text) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!this.editorRef || !this.editorRef.command) {
|
|
|
|
|
+ console.warn('Editor reference or command not available');
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (typeof this.editorRef.command.executeInsertText === 'function') {
|
|
|
|
|
+ this.editorRef.command.executeInsertText(text);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.warn('executeInsertText method is not available');
|
|
|
|
|
+ // 尝试使用备用方法
|
|
|
|
|
+ if (this.editorRef.command._originalExecuteInsertText) {
|
|
|
|
|
+ this.editorRef.command._originalExecuteInsertText(text);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Error executing insertText:', error);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
// 检测当前光标是否在表格单元格内
|
|
// 检测当前光标是否在表格单元格内
|
|
|
isCursorInTableCell() {
|
|
isCursorInTableCell() {
|
|
|
try {
|
|
try {
|
|
@@ -937,6 +978,227 @@ export default {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ // 合并相邻的表格
|
|
|
|
|
+ mergeAdjacentTables(container) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const tables = Array.from(container.querySelectorAll('table'));
|
|
|
|
|
+ if (tables.length < 2) return;
|
|
|
|
|
+
|
|
|
|
|
+ // 按DOM顺序排序表格
|
|
|
|
|
+ tables.sort((a, b) => {
|
|
|
|
|
+ const position = a.compareDocumentPosition(b);
|
|
|
|
|
+ if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ } else if (position & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 从后往前处理,避免索引变化问题
|
|
|
|
|
+ for (let i = tables.length - 1; i > 0; i--) {
|
|
|
|
|
+ const currentTable = tables[i];
|
|
|
|
|
+ const previousTable = tables[i - 1];
|
|
|
|
|
+
|
|
|
|
|
+ // 检查两个表格是否相邻
|
|
|
|
|
+ if (this.areTablesAdjacent(previousTable, currentTable)) {
|
|
|
|
|
+ // 合并表格
|
|
|
|
|
+ this.mergeTwoTables(previousTable, currentTable);
|
|
|
|
|
+ // 移除已合并的表格
|
|
|
|
|
+ currentTable.remove();
|
|
|
|
|
+ // 更新数组,移除已合并的表格
|
|
|
|
|
+ tables.splice(i, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Error merging adjacent tables:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 检测两个表格是否相邻
|
|
|
|
|
+ areTablesAdjacent(table1, table2) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 获取两个表格的父容器
|
|
|
|
|
+ const parent1 = table1.parentElement;
|
|
|
|
|
+ const parent2 = table2.parentElement;
|
|
|
|
|
+
|
|
|
|
|
+ // 如果不在同一个父容器中,检查是否是兄弟节点
|
|
|
|
|
+ if (parent1 === parent2) {
|
|
|
|
|
+ // 同一父容器,检查是否相邻
|
|
|
|
|
+ let currentNode = table1.nextSibling;
|
|
|
|
|
+ while (currentNode) {
|
|
|
|
|
+ if (currentNode === table2) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 跳过空白文本节点
|
|
|
|
|
+ if (currentNode.nodeType === Node.TEXT_NODE) {
|
|
|
|
|
+ if (currentNode.textContent.trim() !== '') {
|
|
|
|
|
+ // 遇到非空白文本节点,说明不相邻
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ currentNode = currentNode.nextSibling;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果遇到其他元素节点,说明不相邻
|
|
|
|
|
+ if (currentNode.nodeType === Node.ELEMENT_NODE) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ currentNode = currentNode.nextSibling;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 不同父容器,检查table1是否是父容器的最后一个元素,table2是否是下一个父容器的第一个元素
|
|
|
|
|
+ let nextSibling = parent1.nextSibling;
|
|
|
|
|
+ while (nextSibling) {
|
|
|
|
|
+ if (nextSibling === parent2) {
|
|
|
|
|
+ // 检查table1是否是parent1的最后一个表格,table2是否是parent2的第一个表格
|
|
|
|
|
+ const lastTableInParent1 = Array.from(parent1.querySelectorAll('table')).pop();
|
|
|
|
|
+ const firstTableInParent2 = parent2.querySelector('table');
|
|
|
|
|
+ if (lastTableInParent1 === table1 && firstTableInParent2 === table2) {
|
|
|
|
|
+ // 检查两个父容器之间是否只有空白
|
|
|
|
|
+ let node = parent1.nextSibling;
|
|
|
|
|
+ let foundParent2 = false;
|
|
|
|
|
+ while (node) {
|
|
|
|
|
+ if (node === parent2) {
|
|
|
|
|
+ foundParent2 = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (node.nodeType === Node.TEXT_NODE && node.textContent.trim() !== '') {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (node.nodeType === Node.ELEMENT_NODE) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ node = node.nextSibling;
|
|
|
|
|
+ }
|
|
|
|
|
+ return foundParent2;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 跳过空白文本节点
|
|
|
|
|
+ if (nextSibling.nodeType === Node.TEXT_NODE) {
|
|
|
|
|
+ if (nextSibling.textContent.trim() !== '') {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ nextSibling = nextSibling.nextSibling;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 跳过文本节点
|
|
|
|
|
+ if (nextSibling.nodeType === Node.ELEMENT_NODE) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ nextSibling = nextSibling.nextSibling;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Error checking if tables are adjacent:', error);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ // 合并两个表格
|
|
|
|
|
+ mergeTwoTables(table1, table2) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 获取两个表格的所有行
|
|
|
|
|
+ const rows1 = Array.from(table1.querySelectorAll('tr'));
|
|
|
|
|
+ const rows2 = Array.from(table2.querySelectorAll('tr'));
|
|
|
|
|
+
|
|
|
|
|
+ if (rows1.length === 0 || rows2.length === 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取两个表格的列数
|
|
|
|
|
+ const getColumnCount = (table) => {
|
|
|
|
|
+ const firstRow = table.querySelector('tr');
|
|
|
|
|
+ if (!firstRow) return 0;
|
|
|
|
|
+ return firstRow.querySelectorAll('td, th').length;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const cols1 = getColumnCount(table1);
|
|
|
|
|
+ const cols2 = getColumnCount(table2);
|
|
|
|
|
+
|
|
|
|
|
+ // 确定合并后的列数(取较大值)
|
|
|
|
|
+ const maxCols = Math.max(cols1, cols2);
|
|
|
|
|
+
|
|
|
|
|
+ // 统一列数:为列数较少的表格补齐列
|
|
|
|
|
+ const normalizeTableRows = (rows, targetCols) => {
|
|
|
|
|
+ rows.forEach(row => {
|
|
|
|
|
+ const cells = Array.from(row.querySelectorAll('td, th'));
|
|
|
|
|
+ const currentCols = cells.length;
|
|
|
|
|
+ if (currentCols < targetCols) {
|
|
|
|
|
+ // 补齐缺失的列
|
|
|
|
|
+ for (let i = currentCols; i < targetCols; i++) {
|
|
|
|
|
+ const cell = document.createElement('td');
|
|
|
|
|
+ row.appendChild(cell);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 统一两个表格的列数
|
|
|
|
|
+ normalizeTableRows(rows1, maxCols);
|
|
|
|
|
+ normalizeTableRows(rows2, maxCols);
|
|
|
|
|
+
|
|
|
|
|
+ // 将table2的所有行追加到table1
|
|
|
|
|
+ const tbody1 = table1.querySelector('tbody') || table1;
|
|
|
|
|
+ rows2.forEach(row => {
|
|
|
|
|
+ // 克隆行并追加,保持所有内容和样式
|
|
|
|
|
+ const clonedRow = row.cloneNode(true);
|
|
|
|
|
+ // 清除克隆行的背景色
|
|
|
|
|
+ clonedRow.style.backgroundColor = '';
|
|
|
|
|
+ const clonedCells = clonedRow.querySelectorAll('td, th');
|
|
|
|
|
+ clonedCells.forEach(cell => {
|
|
|
|
|
+ cell.style.backgroundColor = '';
|
|
|
|
|
+ if (cell.style.background) {
|
|
|
|
|
+ cell.style.background = '';
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ tbody1.appendChild(clonedRow);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 保持table1的样式和属性
|
|
|
|
|
+ // 如果table2有特殊的样式,可以合并到table1(但避免覆盖table1的样式)
|
|
|
|
|
+ if (table2.style.cssText && !table1.style.cssText) {
|
|
|
|
|
+ table1.style.cssText = table2.style.cssText;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 合并表格属性(如border, cellpadding, cellspacing等)
|
|
|
|
|
+ if (table2.hasAttribute('border') && !table1.hasAttribute('border')) {
|
|
|
|
|
+ table1.setAttribute('border', table2.getAttribute('border'));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (table2.hasAttribute('cellpadding') && !table1.hasAttribute('cellpadding')) {
|
|
|
|
|
+ table1.setAttribute('cellpadding', table2.getAttribute('cellpadding'));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (table2.hasAttribute('cellspacing') && !table1.hasAttribute('cellspacing')) {
|
|
|
|
|
+ table1.setAttribute('cellspacing', table2.getAttribute('cellspacing'));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (table2.hasAttribute('width') && !table1.hasAttribute('width')) {
|
|
|
|
|
+ table1.setAttribute('width', table2.getAttribute('width'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 标记为合并后的表格,并清除所有单元格的背景色
|
|
|
|
|
+ table1.setAttribute('data-merged-table', 'true');
|
|
|
|
|
+
|
|
|
|
|
+ // 清除表格中所有行和单元格的背景色
|
|
|
|
|
+ const allRows = table1.querySelectorAll('tr');
|
|
|
|
|
+ allRows.forEach(row => {
|
|
|
|
|
+ row.style.backgroundColor = '';
|
|
|
|
|
+ const allCells = row.querySelectorAll('td, th');
|
|
|
|
|
+ allCells.forEach(cell => {
|
|
|
|
|
+ cell.style.backgroundColor = '';
|
|
|
|
|
+ // 同时清除内联样式中的背景色
|
|
|
|
|
+ if (cell.style.background) {
|
|
|
|
|
+ cell.style.background = '';
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ console.log(`Merged two tables: ${rows1.length} + ${rows2.length} = ${rows1.length + rows2.length} rows`);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Error merging two tables:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
// 处理粘贴的HTML内容,清理超链接样式
|
|
// 处理粘贴的HTML内容,清理超链接样式
|
|
|
processPastedHtml(htmlContent) {
|
|
processPastedHtml(htmlContent) {
|
|
|
try {
|
|
try {
|
|
@@ -946,6 +1208,9 @@ export default {
|
|
|
const tempDiv = document.createElement('div');
|
|
const tempDiv = document.createElement('div');
|
|
|
tempDiv.innerHTML = htmlContent;
|
|
tempDiv.innerHTML = htmlContent;
|
|
|
|
|
|
|
|
|
|
+ // 先合并相邻的表格
|
|
|
|
|
+ this.mergeAdjacentTables(tempDiv);
|
|
|
|
|
+
|
|
|
// 查找并处理所有超链接,但保持其他样式
|
|
// 查找并处理所有超链接,但保持其他样式
|
|
|
const links = tempDiv.querySelectorAll('a');
|
|
const links = tempDiv.querySelectorAll('a');
|
|
|
links.forEach(link => {
|
|
links.forEach(link => {
|
|
@@ -986,19 +1251,22 @@ export default {
|
|
|
// 特别处理表格,确保表头样式正确
|
|
// 特别处理表格,确保表头样式正确
|
|
|
const tables = tempDiv.querySelectorAll('table');
|
|
const tables = tempDiv.querySelectorAll('table');
|
|
|
tables.forEach(table => {
|
|
tables.forEach(table => {
|
|
|
|
|
+ // 如果是合并后的表格,跳过添加表头背景色
|
|
|
|
|
+ const isMergedTable = table.hasAttribute('data-merged-table');
|
|
|
|
|
+
|
|
|
// 处理表头行
|
|
// 处理表头行
|
|
|
const headerRows = table.querySelectorAll('thead tr, tr:first-child');
|
|
const headerRows = table.querySelectorAll('thead tr, tr:first-child');
|
|
|
headerRows.forEach(headerRow => {
|
|
headerRows.forEach(headerRow => {
|
|
|
- // 确保表头有背景色
|
|
|
|
|
- if (!headerRow.style.backgroundColor) {
|
|
|
|
|
|
|
+ // 如果不是合并后的表格,才添加表头背景色
|
|
|
|
|
+ if (!isMergedTable && !headerRow.style.backgroundColor) {
|
|
|
headerRow.style.backgroundColor = '#f5f5f5'; // 默认表头背景色
|
|
headerRow.style.backgroundColor = '#f5f5f5'; // 默认表头背景色
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 处理表头单元格
|
|
// 处理表头单元格
|
|
|
const headerCells = headerRow.querySelectorAll('th, td');
|
|
const headerCells = headerRow.querySelectorAll('th, td');
|
|
|
headerCells.forEach(cell => {
|
|
headerCells.forEach(cell => {
|
|
|
- // 确保表头单元格有背景色
|
|
|
|
|
- if (!cell.style.backgroundColor) {
|
|
|
|
|
|
|
+ // 如果不是合并后的表格,才添加表头单元格背景色
|
|
|
|
|
+ if (!isMergedTable && !cell.style.backgroundColor) {
|
|
|
cell.style.backgroundColor = '#f5f5f5';
|
|
cell.style.backgroundColor = '#f5f5f5';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1093,26 +1361,67 @@ export default {
|
|
|
Reflect.set(window, "editor", instance);
|
|
Reflect.set(window, "editor", instance);
|
|
|
|
|
|
|
|
// 重写编辑器的粘贴命令,确保所有粘贴操作都经过我们的处理
|
|
// 重写编辑器的粘贴命令,确保所有粘贴操作都经过我们的处理
|
|
|
- const originalExecuteInsertText = instance.command.executeInsertText;
|
|
|
|
|
- const originalExecuteSetHTML = instance.command.executeSetHTML;
|
|
|
|
|
|
|
+ // 安全地保存原始方法引用,使用 bind 确保方法绑定正确
|
|
|
|
|
+ let originalExecuteInsertText = null;
|
|
|
|
|
+ let originalExecuteSetHTML = null;
|
|
|
|
|
+
|
|
|
|
|
+ if (instance.command && instance.command.executeInsertText && typeof instance.command.executeInsertText === 'function') {
|
|
|
|
|
+ // 使用 bind 创建一个绑定了正确 this 的函数引用
|
|
|
|
|
+ originalExecuteInsertText = instance.command.executeInsertText.bind(instance.command);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (instance.command && instance.command.executeSetHTML && typeof instance.command.executeSetHTML === 'function') {
|
|
|
|
|
+ originalExecuteSetHTML = instance.command.executeSetHTML.bind(instance.command);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 重写 executeInsertText 方法
|
|
// 重写 executeInsertText 方法
|
|
|
- instance.command.executeInsertText = (text) => {
|
|
|
|
|
- console.log('Intercepted executeInsertText:', text);
|
|
|
|
|
- // 直接调用原始方法,因为纯文本不需要特殊处理
|
|
|
|
|
- return originalExecuteInsertText.call(instance.command, text);
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ if (originalExecuteInsertText) {
|
|
|
|
|
+ instance.command.executeInsertText = function(text) {
|
|
|
|
|
+ console.log('Intercepted executeInsertText:', text);
|
|
|
|
|
+ // 直接调用已绑定的原始方法
|
|
|
|
|
+ try {
|
|
|
|
|
+ return originalExecuteInsertText(text);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Error in executeInsertText:', error);
|
|
|
|
|
+ // 如果调用失败,尝试直接调用(避免无限递归)
|
|
|
|
|
+ if (instance.command && instance.command._originalExecuteInsertText) {
|
|
|
|
|
+ return instance.command._originalExecuteInsertText.call(instance.command, text);
|
|
|
|
|
+ }
|
|
|
|
|
+ throw error;
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ // 保存一个备用引用
|
|
|
|
|
+ instance.command._originalExecuteInsertText = originalExecuteInsertText;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.warn('executeInsertText method not found or invalid on instance.command, skipping override');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 重写 executeSetHTML 方法
|
|
// 重写 executeSetHTML 方法
|
|
|
- instance.command.executeSetHTML = (htmlData) => {
|
|
|
|
|
- console.log('Intercepted executeSetHTML:', htmlData);
|
|
|
|
|
- if (htmlData && htmlData.main) {
|
|
|
|
|
- // 处理HTML内容
|
|
|
|
|
- const processedHtml = this.processPastedHtml(htmlData.main);
|
|
|
|
|
- htmlData.main = processedHtml;
|
|
|
|
|
- }
|
|
|
|
|
- return originalExecuteSetHTML.call(instance.command, htmlData);
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ if (originalExecuteSetHTML) {
|
|
|
|
|
+ const self = this; // 保存 Vue 实例的引用
|
|
|
|
|
+ instance.command.executeSetHTML = function(htmlData) {
|
|
|
|
|
+ console.log('Intercepted executeSetHTML:', htmlData);
|
|
|
|
|
+ if (htmlData && htmlData.main) {
|
|
|
|
|
+ // 处理HTML内容
|
|
|
|
|
+ const processedHtml = self.processPastedHtml(htmlData.main);
|
|
|
|
|
+ htmlData.main = processedHtml;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 直接调用已绑定的原始方法
|
|
|
|
|
+ try {
|
|
|
|
|
+ return originalExecuteSetHTML(htmlData);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Error in executeSetHTML:', error);
|
|
|
|
|
+ // 如果调用失败,尝试直接调用(避免无限递归)
|
|
|
|
|
+ if (instance.command && instance.command._originalExecuteSetHTML) {
|
|
|
|
|
+ return instance.command._originalExecuteSetHTML.call(instance.command, htmlData);
|
|
|
|
|
+ }
|
|
|
|
|
+ throw error;
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ // 保存一个备用引用
|
|
|
|
|
+ instance.command._originalExecuteSetHTML = originalExecuteSetHTML;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.warn('executeSetHTML method not found or invalid on instance.command, skipping override');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 仅在编辑区域挂载本地粘贴监听,避免拦截系统/浏览器菜单功能
|
|
// 仅在编辑区域挂载本地粘贴监听,避免拦截系统/浏览器菜单功能
|
|
|
const editorElement = document.querySelector(".canvas-editor");
|
|
const editorElement = document.querySelector(".canvas-editor");
|