forked from Hufe921/canvas-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
115 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,71 @@ | ||
import { ControlComponent } from '../../../dataset/enum/Control' | ||
import { ElementType } from '../../../dataset/enum/Element' | ||
import { IElement } from '../../../interface/Element' | ||
import { ICurrentPosition } from '../../../interface/Position' | ||
import { Draw } from '../Draw' | ||
|
||
export class Control { | ||
|
||
|
||
private draw: Draw | ||
|
||
constructor(draw: Draw) { | ||
this.draw = draw | ||
} | ||
|
||
// 调整起始光标位置到控件合适的位置 | ||
public moveCursorIndex(position: ICurrentPosition) { | ||
const { index, trIndex, tdIndex, tdValueIndex } = position | ||
let elementList = this.draw.getOriginalElementList() | ||
let element: IElement | ||
if (position.isTable) { | ||
elementList = elementList[index!].trList![trIndex!].tdList[tdIndex!].value | ||
element = elementList[tdValueIndex!] | ||
} else { | ||
element = elementList[index] | ||
} | ||
if (element.type !== ElementType.CONTROL) return | ||
// VALUE-无需移动 | ||
if (element.controlComponent === ControlComponent.VALUE) return | ||
// POSTFIX-移动到最后一个后缀字符后 | ||
if (element.controlComponent === ControlComponent.POSTFIX) { | ||
let startIndex = index + 1 | ||
while (startIndex < elementList.length) { | ||
const nextElement = elementList[startIndex] | ||
if (nextElement.controlId !== element.controlId) { | ||
position.index = startIndex - 1 | ||
break | ||
} | ||
startIndex++ | ||
} | ||
} else if (element.controlComponent === ControlComponent.PREFIX) { | ||
// PREFIX-移动到最后一个前缀字符后 | ||
let startIndex = index + 1 | ||
while (startIndex < elementList.length) { | ||
const nextElement = elementList[startIndex] | ||
if ( | ||
nextElement.controlId !== element.controlId | ||
|| nextElement.controlComponent !== ControlComponent.PREFIX | ||
) { | ||
position.index = startIndex - 1 | ||
break | ||
} | ||
startIndex++ | ||
} | ||
} else if (element.controlComponent === ControlComponent.PLACEHOLDER) { | ||
// PLACEHOLDER-移动到第一个前缀后 | ||
let startIndex = index - 1 | ||
while (startIndex > 0) { | ||
const preElement = elementList[startIndex] | ||
if ( | ||
preElement.controlId !== element.controlId | ||
|| preElement.controlComponent === ControlComponent.PREFIX | ||
) { | ||
position.index = startIndex | ||
break | ||
} | ||
startIndex-- | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters