Skip to content

Commit

Permalink
feat: handle copy area context boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Nov 15, 2024
1 parent 30b405c commit 64b4100
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/editor/core/event/handlers/keydown/enter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '../../../../dataset/constant/Element'
import { ControlComponent } from '../../../../dataset/enum/Control'
import { IElement } from '../../../../interface/Element'
import { omitObject } from '../../../../utils'
import {
formatElementContext,
getAnchorElement
Expand Down Expand Up @@ -33,7 +34,7 @@ export function enter(evt: KeyboardEvent, host: CanvasEvent) {
return
}
// 列表块内换行
const enterText: IElement = {
let enterText: IElement = {
value: ZERO
}
if (evt.shiftKey && startElement.listId) {
Expand All @@ -44,6 +45,14 @@ export function enter(evt: KeyboardEvent, host: CanvasEvent) {
isBreakWhenWrap: true,
editorOptions: draw.getOptions()
})
// shift长按 && 最后位置回车无需复制区域上下文
if (
evt.shiftKey &&
endElement.areaId &&
endElement.areaId !== elementList[endIndex + 1]?.areaId
) {
enterText = omitObject(enterText, AREA_CONTEXT_ATTR)
}
// 标题结尾处回车无需格式化及样式复制
if (
!(
Expand All @@ -54,7 +63,7 @@ export function enter(evt: KeyboardEvent, host: CanvasEvent) {
// 复制样式属性
const copyElement = getAnchorElement(elementList, endIndex)
if (copyElement) {
const copyAttr = [...EDITOR_ROW_ATTR, ...AREA_CONTEXT_ATTR]
const copyAttr = [...EDITOR_ROW_ATTR]
// 不复制控件后缀样式
if (copyElement.controlComponent !== ControlComponent.POSTFIX) {
copyAttr.push(...EDITOR_ELEMENT_STYLE_ATTR)
Expand Down
5 changes: 3 additions & 2 deletions src/editor/utils/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,11 +885,12 @@ export function getAnchorElement(
const anchorElement = elementList[anchorIndex]
if (!anchorElement) return null
const anchorNextElement = elementList[anchorIndex + 1]
// 非列表元素 && 当前元素是换行符 && 下一个元素不是换行符 则以下一个元素作为参考元素
// 非列表元素 && 当前元素是换行符 && 下一个元素不是换行符 && 区域相同 => 则以下一个元素作为参考元素
return !anchorElement.listId &&
anchorElement.value === ZERO &&
anchorNextElement &&
anchorNextElement.value !== ZERO
anchorNextElement.value !== ZERO &&
anchorElement.areaId === anchorNextElement.areaId
? anchorNextElement
: anchorElement
}
Expand Down

0 comments on commit 64b4100

Please sign in to comment.