-
-
Notifications
You must be signed in to change notification settings - Fork 603
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
5 changed files
with
167 additions
and
81 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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { ZERO } from '../../../../dataset/constant/Common' | ||
import { IElement } from '../../../../interface/Element' | ||
import { formatElementContext } from '../../../../utils/element' | ||
import { CanvasEvent } from '../../CanvasEvent' | ||
|
||
export function enter(evt: KeyboardEvent, host: CanvasEvent) { | ||
const draw = host.getDraw() | ||
const isReadonly = draw.isReadonly() | ||
const control = draw.getControl() | ||
if (isReadonly || control.isPartRangeInControlOutside()) return | ||
const rangeManager = draw.getRange() | ||
const { startIndex, endIndex } = rangeManager.getRange() | ||
const isCollapsed = rangeManager.getIsCollapsed() | ||
const elementList = draw.getElementList() | ||
const startElement = elementList[startIndex] | ||
const endElement = elementList[endIndex] | ||
// 最后一个列表项行首回车取消列表设置 | ||
if ( | ||
isCollapsed && | ||
endElement.listId && | ||
endElement.value === ZERO && | ||
elementList[endIndex + 1]?.listId !== endElement.listId | ||
) { | ||
draw.getListParticle().unsetList() | ||
return | ||
} | ||
// 列表块内换行 | ||
const enterText: IElement = { | ||
value: ZERO | ||
} | ||
if (evt.shiftKey && startElement.listId) { | ||
enterText.listWrap = true | ||
} | ||
// 标题结尾处回车无需格式化 | ||
if ( | ||
!( | ||
endElement.titleId && | ||
endElement.titleId !== elementList[endIndex + 1]?.titleId | ||
) | ||
) { | ||
formatElementContext(elementList, [enterText], startIndex) | ||
} | ||
// 控件或文档插入换行元素 | ||
const activeControl = control.getActiveControl() | ||
let curIndex: number | ||
if (activeControl && !control.isRangInPostfix()) { | ||
curIndex = control.setValue([enterText]) | ||
} else { | ||
const position = draw.getPosition() | ||
const cursorPosition = position.getCursorPosition() | ||
if (!cursorPosition) return | ||
const { index } = cursorPosition | ||
if (isCollapsed) { | ||
draw.spliceElementList(elementList, index + 1, 0, enterText) | ||
} else { | ||
draw.spliceElementList( | ||
elementList, | ||
startIndex + 1, | ||
endIndex - startIndex, | ||
enterText | ||
) | ||
} | ||
curIndex = index + 1 | ||
} | ||
if (~curIndex) { | ||
rangeManager.setRange(curIndex, curIndex) | ||
draw.render({ curIndex }) | ||
} | ||
evt.preventDefault() | ||
} |
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