feat: add range and position context api
This commit is contained in:
@@ -71,12 +71,40 @@ instance.command.executeBackspace()
|
|||||||
|
|
||||||
## executeSetRange
|
## executeSetRange
|
||||||
|
|
||||||
Feature: Set selection
|
Feature: Set range
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
instance.command.executeSetRange(startIndex: number , endIndex: number)
|
instance.command.executeSetRange(
|
||||||
|
startIndex: number,
|
||||||
|
endIndex: number,
|
||||||
|
tableId?: string,
|
||||||
|
startTdIndex?: number,
|
||||||
|
endTdIndex?: number,
|
||||||
|
startTrIndex?: number,
|
||||||
|
endTrIndex?: number
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## executeReplaceRange
|
||||||
|
|
||||||
|
Feature: Replace range
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
instance.command.executeReplaceRange(range: IRange)
|
||||||
|
```
|
||||||
|
|
||||||
|
## executeSetPositionContext
|
||||||
|
|
||||||
|
Feature: Set position context
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
instance.command.executeSetPositionContext(range: IRange)
|
||||||
```
|
```
|
||||||
|
|
||||||
## executeForceUpdate
|
## executeForceUpdate
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ const wordCount = await instance.command.getWordCount()
|
|||||||
|
|
||||||
## getRangeText
|
## getRangeText
|
||||||
|
|
||||||
Feature: Get selection text
|
Feature: Get range text
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ const rangeText = instance.command.getRangeText()
|
|||||||
|
|
||||||
## getRangeContext
|
## getRangeContext
|
||||||
|
|
||||||
Feature: Get selection context
|
Feature: Get range context
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ const rangeContext = instance.command.getRangeContext()
|
|||||||
|
|
||||||
## getRangeRow
|
## getRangeRow
|
||||||
|
|
||||||
Feature: Get selection row element list
|
Feature: Get range row element list
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
@@ -87,9 +87,19 @@ Usage:
|
|||||||
const rowElementList = instance.command.getRangeRow()
|
const rowElementList = instance.command.getRangeRow()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## getKeywordRangeList
|
||||||
|
|
||||||
|
Feature: Get range list by keyword
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const rangeList = instance.command.getKeywordRangeList()
|
||||||
|
```
|
||||||
|
|
||||||
## getRangeParagraph
|
## getRangeParagraph
|
||||||
|
|
||||||
Feature: Get selection paragraph element list
|
Feature: Get range paragraph element list
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,35 @@ instance.command.executeBackspace()
|
|||||||
用法:
|
用法:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
instance.command.executeSetRange(startIndex: number , endIndex: number)
|
instance.command.executeSetRange(
|
||||||
|
startIndex: number,
|
||||||
|
endIndex: number,
|
||||||
|
tableId?: string,
|
||||||
|
startTdIndex?: number,
|
||||||
|
endTdIndex?: number,
|
||||||
|
startTrIndex?: number,
|
||||||
|
endTrIndex?: number
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## executeReplaceRange
|
||||||
|
|
||||||
|
功能:替换选区
|
||||||
|
|
||||||
|
用法:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
instance.command.executeReplaceRange(range: IRange)
|
||||||
|
```
|
||||||
|
|
||||||
|
## executeSetPositionContext
|
||||||
|
|
||||||
|
功能:设置位置上下文
|
||||||
|
|
||||||
|
用法:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
instance.command.executeSetPositionContext(range: IRange)
|
||||||
```
|
```
|
||||||
|
|
||||||
## executeForceUpdate
|
## executeForceUpdate
|
||||||
|
|||||||
@@ -87,6 +87,16 @@ const rangeContext = instance.command.getRangeContext()
|
|||||||
const rowElementList = instance.command.getRangeRow()
|
const rowElementList = instance.command.getRangeRow()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## getKeywordRangeList
|
||||||
|
|
||||||
|
功能:获取关键词所在选区列表
|
||||||
|
|
||||||
|
用法:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const rangeList = instance.command.getKeywordRangeList()
|
||||||
|
```
|
||||||
|
|
||||||
## getRangeParagraph
|
## getRangeParagraph
|
||||||
|
|
||||||
功能:获取选区所在段落元素列表
|
功能:获取选区所在段落元素列表
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ export class Command {
|
|||||||
public executeSelectAll: CommandAdapt['selectAll']
|
public executeSelectAll: CommandAdapt['selectAll']
|
||||||
public executeBackspace: CommandAdapt['backspace']
|
public executeBackspace: CommandAdapt['backspace']
|
||||||
public executeSetRange: CommandAdapt['setRange']
|
public executeSetRange: CommandAdapt['setRange']
|
||||||
|
public executeReplaceRange: CommandAdapt['replaceRange']
|
||||||
|
public executeSetPositionContext: CommandAdapt['setPositionContext']
|
||||||
public executeForceUpdate: CommandAdapt['forceUpdate']
|
public executeForceUpdate: CommandAdapt['forceUpdate']
|
||||||
public executeBlur: CommandAdapt['blur']
|
public executeBlur: CommandAdapt['blur']
|
||||||
public executeUndo: CommandAdapt['undo']
|
public executeUndo: CommandAdapt['undo']
|
||||||
@@ -96,6 +98,7 @@ export class Command {
|
|||||||
public getRangeContext: CommandAdapt['getRangeContext']
|
public getRangeContext: CommandAdapt['getRangeContext']
|
||||||
public getRangeRow: CommandAdapt['getRangeRow']
|
public getRangeRow: CommandAdapt['getRangeRow']
|
||||||
public getRangeParagraph: CommandAdapt['getRangeParagraph']
|
public getRangeParagraph: CommandAdapt['getRangeParagraph']
|
||||||
|
public getKeywordRangeList: CommandAdapt['getKeywordRangeList']
|
||||||
public getPaperMargin: CommandAdapt['getPaperMargin']
|
public getPaperMargin: CommandAdapt['getPaperMargin']
|
||||||
public getSearchNavigateInfo: CommandAdapt['getSearchNavigateInfo']
|
public getSearchNavigateInfo: CommandAdapt['getSearchNavigateInfo']
|
||||||
public getLocale: CommandAdapt['getLocale']
|
public getLocale: CommandAdapt['getLocale']
|
||||||
@@ -112,6 +115,8 @@ export class Command {
|
|||||||
this.executeSelectAll = adapt.selectAll.bind(adapt)
|
this.executeSelectAll = adapt.selectAll.bind(adapt)
|
||||||
this.executeBackspace = adapt.backspace.bind(adapt)
|
this.executeBackspace = adapt.backspace.bind(adapt)
|
||||||
this.executeSetRange = adapt.setRange.bind(adapt)
|
this.executeSetRange = adapt.setRange.bind(adapt)
|
||||||
|
this.executeReplaceRange = adapt.replaceRange.bind(adapt)
|
||||||
|
this.executeSetPositionContext = adapt.setPositionContext.bind(adapt)
|
||||||
this.executeForceUpdate = adapt.forceUpdate.bind(adapt)
|
this.executeForceUpdate = adapt.forceUpdate.bind(adapt)
|
||||||
this.executeBlur = adapt.blur.bind(adapt)
|
this.executeBlur = adapt.blur.bind(adapt)
|
||||||
// 撤销、重做、格式刷、清除格式
|
// 撤销、重做、格式刷、清除格式
|
||||||
@@ -204,6 +209,7 @@ export class Command {
|
|||||||
this.getRangeContext = adapt.getRangeContext.bind(adapt)
|
this.getRangeContext = adapt.getRangeContext.bind(adapt)
|
||||||
this.getRangeRow = adapt.getRangeRow.bind(adapt)
|
this.getRangeRow = adapt.getRangeRow.bind(adapt)
|
||||||
this.getRangeParagraph = adapt.getRangeParagraph.bind(adapt)
|
this.getRangeParagraph = adapt.getRangeParagraph.bind(adapt)
|
||||||
|
this.getKeywordRangeList = adapt.getKeywordRangeList.bind(adapt)
|
||||||
this.getCatalog = adapt.getCatalog.bind(adapt)
|
this.getCatalog = adapt.getCatalog.bind(adapt)
|
||||||
this.getPaperMargin = adapt.getPaperMargin.bind(adapt)
|
this.getPaperMargin = adapt.getPaperMargin.bind(adapt)
|
||||||
this.getSearchNavigateInfo = adapt.getSearchNavigateInfo.bind(adapt)
|
this.getSearchNavigateInfo = adapt.getSearchNavigateInfo.bind(adapt)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import {
|
|||||||
import { IElement, IElementStyle } from '../../interface/Element'
|
import { IElement, IElementStyle } from '../../interface/Element'
|
||||||
import { IPasteOption } from '../../interface/Event'
|
import { IPasteOption } from '../../interface/Event'
|
||||||
import { IMargin } from '../../interface/Margin'
|
import { IMargin } from '../../interface/Margin'
|
||||||
import { RangeContext, RangeRect } from '../../interface/Range'
|
import { IRange, RangeContext, RangeRect } from '../../interface/Range'
|
||||||
import { IColgroup } from '../../interface/table/Colgroup'
|
import { IColgroup } from '../../interface/table/Colgroup'
|
||||||
import { ITd } from '../../interface/table/Td'
|
import { ITd } from '../../interface/table/Td'
|
||||||
import { ITr } from '../../interface/table/Tr'
|
import { ITr } from '../../interface/table/Tr'
|
||||||
@@ -150,9 +150,25 @@ export class CommandAdapt {
|
|||||||
this.draw.render({ curIndex })
|
this.draw.render({ curIndex })
|
||||||
}
|
}
|
||||||
|
|
||||||
public setRange(startIndex: number, endIndex: number) {
|
public setRange(
|
||||||
|
startIndex: number,
|
||||||
|
endIndex: number,
|
||||||
|
tableId?: string,
|
||||||
|
startTdIndex?: number,
|
||||||
|
endTdIndex?: number,
|
||||||
|
startTrIndex?: number,
|
||||||
|
endTrIndex?: number
|
||||||
|
) {
|
||||||
if (startIndex < 0 || endIndex < 0 || endIndex < startIndex) return
|
if (startIndex < 0 || endIndex < 0 || endIndex < startIndex) return
|
||||||
this.range.setRange(startIndex, endIndex)
|
this.range.setRange(
|
||||||
|
startIndex,
|
||||||
|
endIndex,
|
||||||
|
tableId,
|
||||||
|
startTdIndex,
|
||||||
|
endTdIndex,
|
||||||
|
startTrIndex,
|
||||||
|
endTrIndex
|
||||||
|
)
|
||||||
const isCollapsed = startIndex === endIndex
|
const isCollapsed = startIndex === endIndex
|
||||||
this.draw.render({
|
this.draw.render({
|
||||||
curIndex: isCollapsed ? startIndex : undefined,
|
curIndex: isCollapsed ? startIndex : undefined,
|
||||||
@@ -162,6 +178,43 @@ export class CommandAdapt {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public replaceRange(range: IRange) {
|
||||||
|
this.setRange(
|
||||||
|
range.startIndex,
|
||||||
|
range.endIndex,
|
||||||
|
range.tableId,
|
||||||
|
range.startTdIndex,
|
||||||
|
range.endTdIndex,
|
||||||
|
range.startTrIndex,
|
||||||
|
range.endTrIndex
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
public setPositionContext(range: IRange) {
|
||||||
|
const { tableId, startTrIndex, startTdIndex } = range
|
||||||
|
const elementList = this.draw.getOriginalElementList()
|
||||||
|
if (tableId) {
|
||||||
|
const tableElementIndex = elementList.findIndex(el => el.id === tableId)
|
||||||
|
if (!~tableElementIndex) return
|
||||||
|
const tableElement = elementList[tableElementIndex]
|
||||||
|
const tr = tableElement.trList![startTrIndex!]
|
||||||
|
const td = tr.tdList[startTdIndex!]
|
||||||
|
this.position.setPositionContext({
|
||||||
|
isTable: true,
|
||||||
|
index: tableElementIndex,
|
||||||
|
trIndex: startTrIndex,
|
||||||
|
tdIndex: startTdIndex,
|
||||||
|
tdId: td.id,
|
||||||
|
trId: tr.id,
|
||||||
|
tableId
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.position.setPositionContext({
|
||||||
|
isTable: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public forceUpdate(options?: IForceUpdateOption) {
|
public forceUpdate(options?: IForceUpdateOption) {
|
||||||
const { isSubmitHistory = false } = options || {}
|
const { isSubmitHistory = false } = options || {}
|
||||||
this.range.clearRange()
|
this.range.clearRange()
|
||||||
@@ -1890,6 +1943,10 @@ export class CommandAdapt {
|
|||||||
return paragraphElementList ? zipElementList(paragraphElementList) : null
|
return paragraphElementList ? zipElementList(paragraphElementList) : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getKeywordRangeList(payload: string): IRange[] {
|
||||||
|
return this.range.getKeywordRangeList(payload)
|
||||||
|
}
|
||||||
|
|
||||||
public pageMode(payload: PageMode) {
|
public pageMode(payload: PageMode) {
|
||||||
this.draw.setPageMode(payload)
|
this.draw.setPageMode(payload)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ export class Search {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public compute(payload: string) {
|
public getMatchList(payload: string): ISearchResult[] {
|
||||||
const keyword = payload.toLocaleLowerCase()
|
const keyword = payload.toLocaleLowerCase()
|
||||||
const searchMatchList: ISearchResult[] = []
|
const searchMatchList: ISearchResult[] = []
|
||||||
// 分组
|
// 分组
|
||||||
@@ -245,6 +245,7 @@ export class Search {
|
|||||||
for (let d = 0; d < tr.tdList.length; d++) {
|
for (let d = 0; d < tr.tdList.length; d++) {
|
||||||
const td = tr.tdList[d]
|
const td = tr.tdList[d]
|
||||||
const restArgs: ISearchResultRestArgs = {
|
const restArgs: ISearchResultRestArgs = {
|
||||||
|
tableId: tableElement.id,
|
||||||
tableIndex: group.index,
|
tableIndex: group.index,
|
||||||
trIndex: t,
|
trIndex: t,
|
||||||
tdIndex: d,
|
tdIndex: d,
|
||||||
@@ -259,7 +260,11 @@ export class Search {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.searchMatchList = searchMatchList
|
return searchMatchList
|
||||||
|
}
|
||||||
|
|
||||||
|
public compute(payload: string) {
|
||||||
|
this.searchMatchList = this.getMatchList(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
public render(ctx: CanvasRenderingContext2D, pageIndex: number) {
|
public render(ctx: CanvasRenderingContext2D, pageIndex: number) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { ElementType } from '../..'
|
|||||||
import { ZERO } from '../../dataset/constant/Common'
|
import { ZERO } from '../../dataset/constant/Common'
|
||||||
import { TEXTLIKE_ELEMENT_TYPE } from '../../dataset/constant/Element'
|
import { TEXTLIKE_ELEMENT_TYPE } from '../../dataset/constant/Element'
|
||||||
import { ControlComponent } from '../../dataset/enum/Control'
|
import { ControlComponent } from '../../dataset/enum/Control'
|
||||||
|
import { EditorContext } from '../../dataset/enum/Editor'
|
||||||
import { IEditorOption } from '../../interface/Editor'
|
import { IEditorOption } from '../../interface/Editor'
|
||||||
import { IElement } from '../../interface/Element'
|
import { IElement } from '../../interface/Element'
|
||||||
import { EventBusMap } from '../../interface/EventBus'
|
import { EventBusMap } from '../../interface/EventBus'
|
||||||
@@ -247,6 +248,36 @@ export class RangeManager {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getKeywordRangeList(payload: string): IRange[] {
|
||||||
|
const searchMatchList = this.draw.getSearch().getMatchList(payload)
|
||||||
|
const searchRangeMap: Map<string, IRange> = new Map()
|
||||||
|
for (const searchMatch of searchMatchList) {
|
||||||
|
const searchRange = searchRangeMap.get(searchMatch.groupId)
|
||||||
|
if (searchRange) {
|
||||||
|
searchRange.endIndex += 1
|
||||||
|
} else {
|
||||||
|
const { type, groupId, tableId, index, tdIndex, trIndex } = searchMatch
|
||||||
|
const range: IRange = {
|
||||||
|
startIndex: index - 1,
|
||||||
|
endIndex: index
|
||||||
|
}
|
||||||
|
if (type === EditorContext.TABLE) {
|
||||||
|
range.tableId = tableId
|
||||||
|
range.startTdIndex = tdIndex
|
||||||
|
range.endTdIndex = tdIndex
|
||||||
|
range.startTrIndex = trIndex
|
||||||
|
range.endTrIndex = trIndex
|
||||||
|
}
|
||||||
|
searchRangeMap.set(groupId, range)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const rangeList: IRange[] = []
|
||||||
|
searchRangeMap.forEach(searchRange => {
|
||||||
|
rangeList.push(searchRange)
|
||||||
|
})
|
||||||
|
return rangeList
|
||||||
|
}
|
||||||
|
|
||||||
public setRange(
|
public setRange(
|
||||||
startIndex: number,
|
startIndex: number,
|
||||||
endIndex: number,
|
endIndex: number,
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ import { defaultPageBreakOption } from './dataset/constant/PageBreak'
|
|||||||
import { IPageBreak } from './interface/PageBreak'
|
import { IPageBreak } from './interface/PageBreak'
|
||||||
import { LETTER_CLASS } from './dataset/constant/Common'
|
import { LETTER_CLASS } from './dataset/constant/Common'
|
||||||
import { INTERNAL_CONTEXT_MENU_KEY } from './dataset/constant/ContextMenu'
|
import { INTERNAL_CONTEXT_MENU_KEY } from './dataset/constant/ContextMenu'
|
||||||
|
import { IRange } from './interface/Range'
|
||||||
|
|
||||||
export default class Editor {
|
export default class Editor {
|
||||||
public command: Command
|
public command: Command
|
||||||
@@ -291,5 +292,6 @@ export type {
|
|||||||
ILang,
|
ILang,
|
||||||
ICatalog,
|
ICatalog,
|
||||||
ICatalogItem,
|
ICatalogItem,
|
||||||
|
IRange,
|
||||||
IRangeStyle
|
IRangeStyle
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export interface ISearchResultBasic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ISearchResultRestArgs {
|
export interface ISearchResultRestArgs {
|
||||||
|
tableId?: string
|
||||||
tableIndex?: number
|
tableIndex?: number
|
||||||
trIndex?: number
|
trIndex?: number
|
||||||
tdIndex?: number
|
tdIndex?: number
|
||||||
|
|||||||
Reference in New Issue
Block a user