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,27 +348,36 @@ export class Draw {
isHandleFirstElement: false, isHandleFirstElement: false,
editorOptions: this.options editorOptions: this.options
}) })
const elementList = this.getElementList() let curIndex = -1
const isCollapsed = startIndex === endIndex // 判断是否在控件内
const start = startIndex + 1 const activeControl = this.control.getActiveControl()
if (!isCollapsed) { if (activeControl && !this.control.isRangInPostfix()) {
elementList.splice(start, endIndex - startIndex) curIndex = activeControl.setValue(payload)
} } else {
const positionContext = this.position.getPositionContext() const elementList = this.getElementList()
for (let i = 0; i < payload.length; i++) { const isCollapsed = startIndex === endIndex
const element = payload[i] const start = startIndex + 1
if (positionContext.isTable) { if (!isCollapsed) {
element.tdId = positionContext.tdId elementList.splice(start, endIndex - startIndex)
element.trId = positionContext.trId
element.tableId = positionContext.tableId
} }
elementList.splice(start + i, 0, element) const positionContext = this.position.getPositionContext()
for (let i = 0; i < payload.length; i++) {
const element = payload[i]
if (positionContext.isTable) {
element.tdId = positionContext.tdId
element.trId = positionContext.trId
element.tableId = positionContext.tableId
}
elementList.splice(start + i, 0, element)
}
curIndex = startIndex + payload.length
}
if (~curIndex) {
this.range.setRange(curIndex, curIndex)
this.render({
curIndex
})
} }
const curIndex = startIndex + payload.length
this.range.setRange(curIndex, curIndex)
this.render({
curIndex
})
} }
public getOriginalElementList() { public getOriginalElementList() {

@ -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
} }
rangeManager.setRange(curIndex, curIndex) if (~curIndex) {
draw.render({ rangeManager.setRange(curIndex, curIndex)
curIndex, draw.render({
isSubmitHistory: !isComposing curIndex,
}) 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
} }
rangeManager.setRange(curIndex, curIndex) if (~curIndex) {
draw.render({ curIndex }) rangeManager.setRange(curIndex, 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