feat: add getText api #240
This commit is contained in:
@@ -80,6 +80,7 @@ export class Command {
|
||||
public getImage: CommandAdapt['getImage']
|
||||
public getValue: CommandAdapt['getValue']
|
||||
public getHTML: CommandAdapt['getHTML']
|
||||
public getText: CommandAdapt['getText']
|
||||
public getWordCount: CommandAdapt['getWordCount']
|
||||
public getRangeText: CommandAdapt['getRangeText']
|
||||
public getRangeContext: CommandAdapt['getRangeContext']
|
||||
@@ -174,6 +175,7 @@ export class Command {
|
||||
this.getImage = adapt.getImage.bind(adapt)
|
||||
this.getValue = adapt.getValue.bind(adapt)
|
||||
this.getHTML = adapt.getHTML.bind(adapt)
|
||||
this.getText = adapt.getText.bind(adapt)
|
||||
this.getWordCount = adapt.getWordCount.bind(adapt)
|
||||
this.getRangeText = adapt.getRangeText.bind(adapt)
|
||||
this.getRangeContext = adapt.getRangeContext.bind(adapt)
|
||||
|
||||
@@ -29,7 +29,8 @@ import {
|
||||
IEditorData,
|
||||
IEditorHTML,
|
||||
IEditorOption,
|
||||
IEditorResult
|
||||
IEditorResult,
|
||||
IEditorText
|
||||
} from '../../interface/Editor'
|
||||
import { IElement, IElementStyle } from '../../interface/Element'
|
||||
import { IMargin } from '../../interface/Margin'
|
||||
@@ -45,7 +46,8 @@ import {
|
||||
formatElementList,
|
||||
isTextLikeElement,
|
||||
pickElementAttr,
|
||||
getElementListByHTML
|
||||
getElementListByHTML,
|
||||
getTextFromElementList
|
||||
} from '../../utils/element'
|
||||
import { printImageBase64 } from '../../utils/print'
|
||||
import { Control } from '../draw/control/Control'
|
||||
@@ -1703,6 +1705,17 @@ export class CommandAdapt {
|
||||
}
|
||||
}
|
||||
|
||||
public getText(): IEditorText {
|
||||
const headerElementList = this.draw.getHeaderElementList()
|
||||
const mainElementList = this.draw.getOriginalMainElementList()
|
||||
const footerElementList = this.draw.getFooterElementList()
|
||||
return {
|
||||
header: getTextFromElementList(headerElementList),
|
||||
main: getTextFromElementList(mainElementList),
|
||||
footer: getTextFromElementList(footerElementList)
|
||||
}
|
||||
}
|
||||
|
||||
public getWordCount(): Promise<number> {
|
||||
return this.workerManager.getWordCount()
|
||||
}
|
||||
|
||||
@@ -509,7 +509,7 @@ export class RangeManager {
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
const selection = this.getSelection()
|
||||
const selection = this.getTextLikeSelection()
|
||||
if (!selection) return ''
|
||||
return selection
|
||||
.map(s => s.value)
|
||||
|
||||
Reference in New Issue
Block a user