From a71479dd1f2e18a1bf42212f37ecfabd0f6f2242 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Tue, 22 Nov 2022 22:12:15 +0800 Subject: [PATCH] feat:get range text command --- src/editor/core/command/Command.ts | 6 ++++++ src/editor/core/command/CommandAdapt.ts | 4 ++++ src/editor/core/range/RangeManager.ts | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/src/editor/core/command/Command.ts b/src/editor/core/command/Command.ts index e81593f..0356ee7 100644 --- a/src/editor/core/command/Command.ts +++ b/src/editor/core/command/Command.ts @@ -68,6 +68,7 @@ export class Command { private static getImage: CommandAdapt['getImage'] private static getValue: CommandAdapt['getValue'] private static getWordCount: CommandAdapt['getWordCount'] + private static getRangeText: CommandAdapt['getRangeText'] private static pageMode: CommandAdapt['pageMode'] private static pageScaleRecovery: CommandAdapt['pageScaleRecovery'] private static pageScaleMinus: CommandAdapt['pageScaleMinus'] @@ -138,6 +139,7 @@ export class Command { Command.getImage = adapt.getImage.bind(adapt) Command.getValue = adapt.getValue.bind(adapt) Command.getWordCount = adapt.getWordCount.bind(adapt) + Command.getRangeText = adapt.getRangeText.bind(adapt) Command.pageMode = adapt.pageMode.bind(adapt) Command.pageScaleRecovery = adapt.pageScaleRecovery.bind(adapt) Command.pageScaleMinus = adapt.pageScaleMinus.bind(adapt) @@ -389,6 +391,10 @@ export class Command { return Command.getWordCount() } + public getRangeText(): string { + return Command.getRangeText() + } + // 页面模式、页面缩放、纸张大小、页边距 public executePageMode(payload: PageMode) { return Command.pageMode(payload) diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 196585c..122f729 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -1400,6 +1400,10 @@ export class CommandAdapt { return this.workerManager.getWordCount() } + public getRangeText(): string { + return this.range.toString() + } + public pageMode(payload: PageMode) { this.draw.setPageMode(payload) } diff --git a/src/editor/core/range/RangeManager.ts b/src/editor/core/range/RangeManager.ts index 33bc180..2e49f10 100644 --- a/src/editor/core/range/RangeManager.ts +++ b/src/editor/core/range/RangeManager.ts @@ -1,4 +1,5 @@ import { ElementType } from '../..' +import { ZERO } from '../../dataset/constant/Common' import { ControlComponent } from '../../dataset/enum/Control' import { IEditorOption } from '../../interface/Editor' import { IElement } from '../../interface/Element' @@ -253,4 +254,12 @@ export class RangeManager { ctx.restore() } + public toString(): string { + const selection = this.getSelection() + if (!selection) return '' + return selection.map(s => s.value) + .join('') + .replace(new RegExp(ZERO, 'g'), '') + } + } \ No newline at end of file