From 88ebfd2f74b4cb1f3686478d0bba6a8231020ccb Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Tue, 6 Jun 2023 22:22:25 +0800 Subject: [PATCH] fix: copy highlight element #193 --- src/editor/core/draw/Draw.ts | 22 +++++++++++----------- src/editor/utils/clipboard.ts | 13 ++++++++----- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 9dfe731..94f4f8f 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -1178,6 +1178,17 @@ export class Draw { leftTop: [x, y] } } = positionList[curRow.startIndex + j] + const preElement = curRow.elementList[j - 1] + // 元素高亮记录 + if (element.highlight) { + // 高亮元素相连需立即绘制,并记录下一元素坐标 + if (preElement && preElement.highlight && preElement.highlight !== element.highlight) { + this.highlight.render(ctx) + } + this.highlight.recordFillInfo(ctx, x, y, metrics.width, curRow.height, element.highlight) + } else if (preElement?.highlight) { + this.highlight.render(ctx) + } // 元素绘制 if (element.type === ElementType.IMAGE) { this._drawRichText(ctx) @@ -1228,7 +1239,6 @@ export class Draw { } else { this.textParticle.record(ctx, element, x, y + offsetY) } - const preElement = curRow.elementList[j - 1] // 下划线记录 if (element.underline) { this.underline.recordFillInfo(ctx, x, y + curRow.height, metrics.width, 0, element.color) @@ -1241,16 +1251,6 @@ export class Draw { } else if (preElement?.strikeout) { this.strikeout.render(ctx) } - // 元素高亮记录 - if (element.highlight) { - // 高亮元素相连需立即绘制,并记录下一元素坐标 - if (preElement && preElement.highlight && preElement.highlight !== element.highlight) { - this.highlight.render(ctx) - } - this.highlight.recordFillInfo(ctx, x, y, metrics.width, curRow.height, element.highlight) - } else if (preElement?.highlight) { - this.highlight.render(ctx) - } // 选区记录 const { zone: currentZone, startIndex, endIndex } = this.range.getRange() if (currentZone === zone && startIndex !== endIndex && startIndex <= index && index <= endIndex) { diff --git a/src/editor/utils/clipboard.ts b/src/editor/utils/clipboard.ts index 991e3fa..8cdecb8 100644 --- a/src/editor/utils/clipboard.ts +++ b/src/editor/utils/clipboard.ts @@ -204,10 +204,13 @@ export function writeElementList(elementList: IElement[], options: DeepRequired< export function convertTextNodeToElement(textNode: Element | Node): IElement | null { if (!textNode || textNode.nodeType !== 3) return null const parentNode = textNode.parentNode - const rowFlex = getElementRowFlex(parentNode) + const anchorNode = parentNode.nodeName === 'FONT' + ? parentNode.parentNode + : parentNode + const rowFlex = getElementRowFlex(anchorNode) const value = textNode.textContent - const style = window.getComputedStyle(parentNode) - if (!value || parentNode.nodeName === 'STYLE') return null + const style = window.getComputedStyle(anchorNode) + if (!value || anchorNode.nodeName === 'STYLE') return null const element: IElement = { value, color: style.color, @@ -216,9 +219,9 @@ export function convertTextNodeToElement(textNode: Element | Node): IElement | n size: Math.floor(parseFloat(style.fontSize)) } // 元素类型-默认文本 - if (parentNode.nodeName === 'SUB') { + if (anchorNode.nodeName === 'SUB' || style.verticalAlign === 'sub') { element.type = ElementType.SUBSCRIPT - } else if (parentNode.nodeName === 'SUP') { + } else if (anchorNode.nodeName === 'SUP' || style.verticalAlign === 'super') { element.type = ElementType.SUPERSCRIPT } // 行对齐