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