Skip to content

Commit

Permalink
fix: three click selection paragraph boundary error
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Dec 27, 2023
1 parent 0bd4c5c commit 56ea7d8
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/editor/core/event/handlers/click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function dblclick(host: CanvasEvent, evt: MouseEvent) {
}
// 设置选中区域
const startIndex = index - upCount - 1
if (!~startIndex) return
if (startIndex < 0) return
const rangeManager = draw.getRange()
rangeManager.setRange(startIndex, index + downCount)
// 刷新文档
Expand All @@ -84,28 +84,45 @@ function threeClick(host: CanvasEvent) {
// 向上查询
let upStartIndex = index - 1
while (upStartIndex > 0) {
const value = elementList[upStartIndex].value
if (value !== ZERO) {
upCount++
upStartIndex--
} else {
const element = elementList[upStartIndex]
const preElement = elementList[upStartIndex - 1]
if (
(element.value === ZERO && !element.listWrap) ||
element.listId !== preElement?.listId ||
element.titleId !== preElement?.titleId
) {
break
}
upCount++
upStartIndex--
}
// 向下查询
let downStartIndex = index + 1
while (downStartIndex < elementList.length) {
const value = elementList[downStartIndex].value
if (value !== ZERO) {
downCount++
downStartIndex++
} else {
const element = elementList[downStartIndex]
const nextElement = elementList[downStartIndex + 1]
if (
(element.value === ZERO && !element.listWrap) ||
element.listId !== nextElement?.listId ||
element.titleId !== nextElement?.titleId
) {
break
}
downCount++
downStartIndex++
}
// 设置选中区域
// 设置选中区域-不选择段落首尾换行符
const rangeManager = draw.getRange()
rangeManager.setRange(index - upCount - 1, index + downCount)
let newStartIndex = index - upCount - 1
if (elementList[newStartIndex]?.value !== ZERO) {
newStartIndex -= 1
}
if (newStartIndex < 0) return
let newEndIndex = index + downCount + 1
if (elementList[newEndIndex]?.value === ZERO) {
newEndIndex -= 1
}
rangeManager.setRange(newStartIndex, newEndIndex)
// 刷新文档
draw.render({
isSubmitHistory: false,
Expand Down

0 comments on commit 56ea7d8

Please sign in to comment.