Skip to content

Commit beacfbd

Browse files
committed
fix: executeHyperlink api is missing some attributes #1282
1 parent 798d555 commit beacfbd

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

src/editor/core/command/CommandAdapt.ts

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,36 +1058,26 @@ export class CommandAdapt {
10581058
this.tableOperate.tableSelectAll()
10591059
}
10601060

1061-
public hyperlink(payload: IElement) {
1061+
public hyperlink(
1062+
payload: Pick<IElement, 'valueList' | 'hyperlinkId' | 'url'>
1063+
) {
1064+
const { valueList, url, hyperlinkId } = payload
1065+
if (!url || !valueList?.length) return
10621066
const isDisabled = this.draw.isReadonly() || this.draw.isDisabled()
10631067
if (isDisabled) return
10641068
const activeControl = this.control.getActiveControl()
10651069
if (activeControl) return
10661070
const { startIndex, endIndex } = this.range.getRange()
10671071
if (!~startIndex && !~endIndex) return
1068-
const elementList = this.draw.getElementList()
1069-
const { valueList, url } = payload
1070-
const hyperlinkId = getUUID()
1071-
const newElementList = valueList?.map<IElement>(v => ({
1072-
url,
1073-
hyperlinkId,
1074-
value: v.value,
1075-
type: ElementType.HYPERLINK
1076-
}))
1077-
if (!newElementList) return
1078-
const start = startIndex + 1
1079-
formatElementContext(elementList, newElementList, startIndex, {
1080-
editorOptions: this.options
1081-
})
1082-
this.draw.spliceElementList(
1083-
elementList,
1084-
start,
1085-
startIndex === endIndex ? 0 : endIndex - startIndex,
1086-
newElementList
1087-
)
1088-
const curIndex = start + newElementList.length - 1
1089-
this.range.setRange(curIndex, curIndex)
1090-
this.draw.render({ curIndex })
1072+
this.insertElementList([
1073+
{
1074+
type: ElementType.HYPERLINK,
1075+
value: '',
1076+
valueList,
1077+
url,
1078+
hyperlinkId: hyperlinkId || getUUID()
1079+
}
1080+
])
10911081
}
10921082

10931083
public getHyperlinkRange(): [number, number] | null {

src/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,6 @@ window.onload = function () {
483483
const url = payload.find(p => p.name === 'url')?.value
484484
if (!url) return
485485
instance.command.executeHyperlink({
486-
type: ElementType.HYPERLINK,
487-
value: '',
488486
url,
489487
valueList: splitText(name).map(n => ({
490488
value: n,

0 commit comments

Comments
 (0)