feat:add search navigate result
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IElement, ImageDisplay } from '../..'
|
||||
import { IElement, ImageDisplay, INavigateInfo } from '../..'
|
||||
import { EditorMode, PageMode } from '../../dataset/enum/Editor'
|
||||
import { RowFlex } from '../../dataset/enum/Row'
|
||||
import { IDrawImagePayload, IPainterOptions } from '../../interface/Draw'
|
||||
@@ -58,6 +58,7 @@ export class Command {
|
||||
private static search: CommandAdapt['search']
|
||||
private static searchNavigatePre: CommandAdapt['searchNavigatePre']
|
||||
private static searchNavigateNext: CommandAdapt['searchNavigateNext']
|
||||
private static getSearchNavigateInfo: CommandAdapt['getSearchNavigateInfo']
|
||||
private static replace: CommandAdapt['replace']
|
||||
private static print: CommandAdapt['print']
|
||||
private static replaceImageElement: CommandAdapt['replaceImageElement']
|
||||
@@ -126,6 +127,7 @@ export class Command {
|
||||
Command.search = adapt.search.bind(adapt)
|
||||
Command.searchNavigatePre = adapt.searchNavigatePre.bind(adapt)
|
||||
Command.searchNavigateNext = adapt.searchNavigateNext.bind(adapt)
|
||||
Command.getSearchNavigateInfo = adapt.getSearchNavigateInfo.bind(adapt)
|
||||
Command.replace = adapt.replace.bind(adapt)
|
||||
Command.print = adapt.print.bind(adapt)
|
||||
Command.replaceImageElement = adapt.replaceImageElement.bind(adapt)
|
||||
@@ -345,6 +347,10 @@ export class Command {
|
||||
return Command.searchNavigateNext()
|
||||
}
|
||||
|
||||
public getSearchNavigateInfo(): null | INavigateInfo {
|
||||
return Command.getSearchNavigateInfo()
|
||||
}
|
||||
|
||||
public executeReplace(payload: string) {
|
||||
return Command.replace(payload)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import { formatElementList } from '../../utils/element'
|
||||
import { printImageBase64 } from '../../utils/print'
|
||||
import { Control } from '../draw/control/Control'
|
||||
import { Draw } from '../draw/Draw'
|
||||
import { Search } from '../draw/interactive/Search'
|
||||
import { INavigateInfo, Search } from '../draw/interactive/Search'
|
||||
import { TableTool } from '../draw/particle/table/TableTool'
|
||||
import { CanvasEvent } from '../event/CanvasEvent'
|
||||
import { HistoryManager } from '../history/HistoryManager'
|
||||
@@ -1239,6 +1239,10 @@ export class CommandAdapt {
|
||||
})
|
||||
}
|
||||
|
||||
public getSearchNavigateInfo(): null | INavigateInfo {
|
||||
return this.searchManager.getSearchNavigateInfo()
|
||||
}
|
||||
|
||||
public replace(payload: string) {
|
||||
const isReadonly = this.draw.isReadonly()
|
||||
if (isReadonly) return
|
||||
|
||||
@@ -10,6 +10,11 @@ import { getUUID } from '../../../utils'
|
||||
import { Position } from '../../position/Position'
|
||||
import { Draw } from '../Draw'
|
||||
|
||||
export interface INavigateInfo {
|
||||
index: number;
|
||||
count: number;
|
||||
}
|
||||
|
||||
export class Search {
|
||||
|
||||
private draw: Draw
|
||||
@@ -120,6 +125,25 @@ export class Search {
|
||||
return this.searchMatchList
|
||||
}
|
||||
|
||||
public getSearchNavigateInfo(): null | INavigateInfo {
|
||||
if (!this.searchKeyword || !this.searchMatchList.length) return null
|
||||
const index = this.searchNavigateIndex !== null
|
||||
? (this.searchNavigateIndex / this.searchKeyword.length) + 1
|
||||
: 0
|
||||
let count = 0
|
||||
let groupId = null
|
||||
for (let s = 0; s < this.searchMatchList.length; s++) {
|
||||
const match = this.searchMatchList[s]
|
||||
if (groupId === match.groupId) continue
|
||||
groupId = match.groupId
|
||||
count += 1
|
||||
}
|
||||
return {
|
||||
index,
|
||||
count
|
||||
}
|
||||
}
|
||||
|
||||
public compute(payload: string) {
|
||||
const searchMatchList: ISearchResult[] = []
|
||||
// 分组
|
||||
|
||||
+3
-1
@@ -23,6 +23,7 @@ import { IControlOption } from './interface/Control'
|
||||
import { ICheckboxOption } from './interface/Checkbox'
|
||||
import { defaultCheckboxOption } from './dataset/constant/Checkbox'
|
||||
import { DeepRequired } from './interface/Common'
|
||||
import { INavigateInfo } from './core/draw/interactive/Search'
|
||||
|
||||
export default class Editor {
|
||||
|
||||
@@ -128,5 +129,6 @@ export type {
|
||||
IEditorResult,
|
||||
IContextMenuContext,
|
||||
IRegisterContextMenu,
|
||||
IWatermark
|
||||
IWatermark,
|
||||
INavigateInfo
|
||||
}
|
||||
Reference in New Issue
Block a user