From 2df03ed3867cf8edf5fb656c017986af6725780c Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Mon, 3 Jun 2024 22:11:14 +0800 Subject: [PATCH] feat: add selection info to rangeContext --- src/editor/core/command/CommandAdapt.ts | 8 +++++++- src/editor/interface/Range.ts | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index d3efb69..64fe8ca 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -2085,6 +2085,10 @@ export class CommandAdapt { if (!~startIndex && !~endIndex) return null // 选区信息 const isCollapsed = startIndex === endIndex + const selectionText = this.range.toString() + const selectionElementList = zipElementList( + this.range.getSelectionElementList() || [] + ) // 元素信息 const elementList = this.draw.getElementList() const startElement = pickElementAttr( @@ -2172,7 +2176,9 @@ export class CommandAdapt { isTable, trIndex: trIndex ?? null, tdIndex: tdIndex ?? null, - tableElement + tableElement, + selectionText, + selectionElementList }) } diff --git a/src/editor/interface/Range.ts b/src/editor/interface/Range.ts index 74f4be0..fe54a61 100644 --- a/src/editor/interface/Range.ts +++ b/src/editor/interface/Range.ts @@ -31,6 +31,8 @@ export type RangeContext = { trIndex: number | null tdIndex: number | null tableElement: IElement | null + selectionText: string | null + selectionElementList: IElement[] } export interface IRangeParagraphInfo {