improve:control element input

pr675
Hufe921 3 years ago
parent 909096bd0d
commit dc54622258

@ -340,11 +340,6 @@ export class Draw {
public insertElementList(payload: IElement[]) { public insertElementList(payload: IElement[]) {
if (!payload.length) return 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() const isPartRangeInControlOutside = this.control.isPartRangeInControlOutside()
if (isPartRangeInControlOutside) return if (isPartRangeInControlOutside) return
const { startIndex, endIndex } = this.range.getRange() const { startIndex, endIndex } = this.range.getRange()
@ -353,6 +348,12 @@ export class Draw {
isHandleFirstElement: false, isHandleFirstElement: false,
editorOptions: this.options 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 elementList = this.getElementList()
const isCollapsed = startIndex === endIndex const isCollapsed = startIndex === endIndex
const start = startIndex + 1 const start = startIndex + 1
@ -369,12 +370,15 @@ export class Draw {
} }
elementList.splice(start + i, 0, element) elementList.splice(start + i, 0, element)
} }
const curIndex = startIndex + payload.length curIndex = startIndex + payload.length
}
if (~curIndex) {
this.range.setRange(curIndex, curIndex) this.range.setRange(curIndex, curIndex)
this.render({ this.render({
curIndex curIndex
}) })
} }
}
public getOriginalElementList() { public getOriginalElementList() {
return this.elementList return this.elementList

@ -48,6 +48,16 @@ export class Control {
return false 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 { public getContainer(): HTMLDivElement {
return this.draw.getContainer() return this.draw.getContainer()
} }

@ -61,8 +61,7 @@ export class CheckboxControl implements IControlInstance {
} }
public setValue(): number { public setValue(): number {
const { endIndex } = this.control.getRange() return -1
return endIndex
} }
public setSelect() { public setSelect() {

@ -68,8 +68,7 @@ export class SelectControl implements IControlInstance {
} }
public setValue(): number { public setValue(): number {
const range = this.control.getRange() return -1
return range.endIndex
} }
public keydown(evt: KeyboardEvent): number { public keydown(evt: KeyboardEvent): number {

@ -67,7 +67,7 @@ export function input(data: string, host: CanvasEvent) {
}) })
// 控件-移除placeholder // 控件-移除placeholder
let curIndex: number let curIndex: number
if (activeControl && elementList[endIndex + 1]?.controlId === element.controlId) { if (activeControl && !control.isRangInPostfix()) {
curIndex = control.setValue(inputData) curIndex = control.setValue(inputData)
} else { } else {
const start = startIndex + 1 const start = startIndex + 1
@ -80,11 +80,13 @@ export function input(data: string, host: CanvasEvent) {
} }
curIndex = startIndex + inputData.length curIndex = startIndex + inputData.length
} }
if (~curIndex) {
rangeManager.setRange(curIndex, curIndex) rangeManager.setRange(curIndex, curIndex)
draw.render({ draw.render({
curIndex, curIndex,
isSubmitHistory: !isComposing isSubmitHistory: !isComposing
}) })
}
if (isComposing) { if (isComposing) {
host.compositionInfo = { host.compositionInfo = {
elementList, elementList,

@ -74,7 +74,7 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
...restArg ...restArg
} }
let curIndex: number let curIndex: number
if (activeControl) { if (activeControl && !control.isRangInPostfix()) {
curIndex = control.setValue([enterText]) curIndex = control.setValue([enterText])
} else { } else {
if (isCollapsed) { if (isCollapsed) {
@ -84,8 +84,10 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
} }
curIndex = index + 1 curIndex = index + 1
} }
if (~curIndex) {
rangeManager.setRange(curIndex, curIndex) rangeManager.setRange(curIndex, curIndex)
draw.render({ curIndex }) draw.render({ curIndex })
}
evt.preventDefault() evt.preventDefault()
} else if (evt.key === KeyMap.Left) { } else if (evt.key === KeyMap.Left) {
if (isReadonly) return if (isReadonly) return

Loading…
Cancel
Save