improve:control element input
This commit is contained in:
@@ -340,11 +340,6 @@ export class Draw {
|
||||
|
||||
public insertElementList(payload: IElement[]) {
|
||||
if (!payload.length) return
|
||||
const activeControl = this.control.getActiveControl()
|
||||
if (activeControl) {
|
||||
const element = activeControl.getElement()
|
||||
if (element.controlComponent !== ControlComponent.POSTFIX) return
|
||||
}
|
||||
const isPartRangeInControlOutside = this.control.isPartRangeInControlOutside()
|
||||
if (isPartRangeInControlOutside) return
|
||||
const { startIndex, endIndex } = this.range.getRange()
|
||||
@@ -353,6 +348,12 @@ export class Draw {
|
||||
isHandleFirstElement: false,
|
||||
editorOptions: this.options
|
||||
})
|
||||
let curIndex = -1
|
||||
// 判断是否在控件内
|
||||
const activeControl = this.control.getActiveControl()
|
||||
if (activeControl && !this.control.isRangInPostfix()) {
|
||||
curIndex = activeControl.setValue(payload)
|
||||
} else {
|
||||
const elementList = this.getElementList()
|
||||
const isCollapsed = startIndex === endIndex
|
||||
const start = startIndex + 1
|
||||
@@ -369,12 +370,15 @@ export class Draw {
|
||||
}
|
||||
elementList.splice(start + i, 0, element)
|
||||
}
|
||||
const curIndex = startIndex + payload.length
|
||||
curIndex = startIndex + payload.length
|
||||
}
|
||||
if (~curIndex) {
|
||||
this.range.setRange(curIndex, curIndex)
|
||||
this.render({
|
||||
curIndex
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public getOriginalElementList() {
|
||||
return this.elementList
|
||||
|
||||
@@ -48,6 +48,16 @@ export class Control {
|
||||
return false
|
||||
}
|
||||
|
||||
// 判断选区是否在后缀处
|
||||
public isRangInPostfix(): boolean {
|
||||
if (!this.activeControl) return false
|
||||
const { startIndex, endIndex } = this.getRange()
|
||||
if (startIndex !== endIndex) return false
|
||||
const elementList = this.getElementList()
|
||||
const element = elementList[startIndex]
|
||||
return element.controlComponent === ControlComponent.POSTFIX
|
||||
}
|
||||
|
||||
public getContainer(): HTMLDivElement {
|
||||
return this.draw.getContainer()
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ export class CheckboxControl implements IControlInstance {
|
||||
}
|
||||
|
||||
public setValue(): number {
|
||||
const { endIndex } = this.control.getRange()
|
||||
return endIndex
|
||||
return -1
|
||||
}
|
||||
|
||||
public setSelect() {
|
||||
|
||||
@@ -68,8 +68,7 @@ export class SelectControl implements IControlInstance {
|
||||
}
|
||||
|
||||
public setValue(): number {
|
||||
const range = this.control.getRange()
|
||||
return range.endIndex
|
||||
return -1
|
||||
}
|
||||
|
||||
public keydown(evt: KeyboardEvent): number {
|
||||
|
||||
@@ -67,7 +67,7 @@ export function input(data: string, host: CanvasEvent) {
|
||||
})
|
||||
// 控件-移除placeholder
|
||||
let curIndex: number
|
||||
if (activeControl && elementList[endIndex + 1]?.controlId === element.controlId) {
|
||||
if (activeControl && !control.isRangInPostfix()) {
|
||||
curIndex = control.setValue(inputData)
|
||||
} else {
|
||||
const start = startIndex + 1
|
||||
@@ -80,11 +80,13 @@ export function input(data: string, host: CanvasEvent) {
|
||||
}
|
||||
curIndex = startIndex + inputData.length
|
||||
}
|
||||
if (~curIndex) {
|
||||
rangeManager.setRange(curIndex, curIndex)
|
||||
draw.render({
|
||||
curIndex,
|
||||
isSubmitHistory: !isComposing
|
||||
})
|
||||
}
|
||||
if (isComposing) {
|
||||
host.compositionInfo = {
|
||||
elementList,
|
||||
|
||||
@@ -74,7 +74,7 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
|
||||
...restArg
|
||||
}
|
||||
let curIndex: number
|
||||
if (activeControl) {
|
||||
if (activeControl && !control.isRangInPostfix()) {
|
||||
curIndex = control.setValue([enterText])
|
||||
} else {
|
||||
if (isCollapsed) {
|
||||
@@ -84,8 +84,10 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
|
||||
}
|
||||
curIndex = index + 1
|
||||
}
|
||||
if (~curIndex) {
|
||||
rangeManager.setRange(curIndex, curIndex)
|
||||
draw.render({ curIndex })
|
||||
}
|
||||
evt.preventDefault()
|
||||
} else if (evt.key === KeyMap.Left) {
|
||||
if (isReadonly) return
|
||||
|
||||
Reference in New Issue
Block a user