feat:text control copy and cut
This commit is contained in:
@@ -313,4 +313,11 @@ export class Control {
|
||||
return this.activeControl.keydown(evt)
|
||||
}
|
||||
|
||||
public cut(): number {
|
||||
if (!this.activeControl) {
|
||||
throw new Error('active control is null')
|
||||
}
|
||||
return this.activeControl.cut()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -149,4 +149,19 @@ export class TextControl implements IControlInstance {
|
||||
return -1
|
||||
}
|
||||
|
||||
public cut(): number {
|
||||
this.control.shrinkBoundary()
|
||||
const { startIndex, endIndex } = this.control.getRange()
|
||||
if (startIndex === endIndex) {
|
||||
return startIndex
|
||||
}
|
||||
const elementList = this.control.getElementList()
|
||||
elementList.splice(startIndex + 1, endIndex - startIndex)
|
||||
const value = this.getValue()
|
||||
if (!value.length) {
|
||||
this.control.addPlaceholder(startIndex)
|
||||
}
|
||||
return startIndex
|
||||
}
|
||||
|
||||
}
|
||||
@@ -314,7 +314,7 @@ export class CanvasEvent {
|
||||
this.range.setRange(curIndex, curIndex)
|
||||
this.draw.render({ curIndex })
|
||||
} else if (evt.key === KeyMap.Enter) {
|
||||
if (isReadonly) return
|
||||
if (isReadonly || isPartRangeInControlOutside) return
|
||||
// 表格需要上下文信息
|
||||
const positionContext = this.position.getPositionContext()
|
||||
let restArg = {}
|
||||
@@ -326,12 +326,17 @@ export class CanvasEvent {
|
||||
value: ZERO,
|
||||
...restArg
|
||||
}
|
||||
let curIndex: number
|
||||
if (activeControl) {
|
||||
curIndex = this.control.setValue([enterText])
|
||||
} else {
|
||||
if (isCollapsed) {
|
||||
elementList.splice(index + 1, 0, enterText)
|
||||
} else {
|
||||
elementList.splice(startIndex + 1, endIndex - startIndex, enterText)
|
||||
}
|
||||
const curIndex = index + 1
|
||||
curIndex = index + 1
|
||||
}
|
||||
this.range.setRange(curIndex, curIndex)
|
||||
this.draw.render({ curIndex })
|
||||
} else if (evt.key === KeyMap.Left) {
|
||||
@@ -540,12 +545,20 @@ export class CanvasEvent {
|
||||
public cut() {
|
||||
const isReadonly = this.draw.isReadonly()
|
||||
if (isReadonly) return
|
||||
const isPartRangeInControlOutside = this.control.isPartRangeInControlOutside()
|
||||
if (isPartRangeInControlOutside) return
|
||||
const activeControl = this.control.getActiveControl()
|
||||
const { startIndex, endIndex } = this.range.getRange()
|
||||
const elementList = this.draw.getElementList()
|
||||
if (startIndex !== endIndex) {
|
||||
writeTextByElementList(elementList.slice(startIndex + 1, endIndex + 1))
|
||||
let curIndex: number
|
||||
if (activeControl) {
|
||||
curIndex = this.control.cut()
|
||||
} else {
|
||||
elementList.splice(startIndex + 1, endIndex - startIndex)
|
||||
const curIndex = startIndex
|
||||
curIndex = startIndex
|
||||
}
|
||||
this.range.setRange(curIndex, curIndex)
|
||||
this.draw.render({ curIndex })
|
||||
}
|
||||
|
||||
@@ -53,5 +53,6 @@ export const TEXTLIKE_ELEMENT_TYPE: ElementType[] = [
|
||||
ElementType.TEXT,
|
||||
ElementType.HYPERLINK,
|
||||
ElementType.SUBSCRIPT,
|
||||
ElementType.SUPERSCRIPT
|
||||
ElementType.SUPERSCRIPT,
|
||||
ElementType.CONTROL
|
||||
]
|
||||
@@ -48,4 +48,6 @@ export interface IControlInstance {
|
||||
setValue(data: IElement[]): number;
|
||||
|
||||
keydown(evt: KeyboardEvent): number;
|
||||
|
||||
cut(): number;
|
||||
}
|
||||
Reference in New Issue
Block a user