fix: three click selection paragraph boundary error

pr675
Hufe921 2 years ago
parent 0bd4c5cc51
commit 56ea7d8bb1

@ -58,7 +58,7 @@ function dblclick(host: CanvasEvent, evt: MouseEvent) {
} }
// 设置选中区域 // 设置选中区域
const startIndex = index - upCount - 1 const startIndex = index - upCount - 1
if (!~startIndex) return if (startIndex < 0) return
const rangeManager = draw.getRange() const rangeManager = draw.getRange()
rangeManager.setRange(startIndex, index + downCount) rangeManager.setRange(startIndex, index + downCount)
// 刷新文档 // 刷新文档
@ -84,28 +84,45 @@ function threeClick(host: CanvasEvent) {
// 向上查询 // 向上查询
let upStartIndex = index - 1 let upStartIndex = index - 1
while (upStartIndex > 0) { while (upStartIndex > 0) {
const value = elementList[upStartIndex].value const element = elementList[upStartIndex]
if (value !== ZERO) { const preElement = elementList[upStartIndex - 1]
upCount++ if (
upStartIndex-- (element.value === ZERO && !element.listWrap) ||
} else { element.listId !== preElement?.listId ||
element.titleId !== preElement?.titleId
) {
break break
} }
upCount++
upStartIndex--
} }
// 向下查询 // 向下查询
let downStartIndex = index + 1 let downStartIndex = index + 1
while (downStartIndex < elementList.length) { while (downStartIndex < elementList.length) {
const value = elementList[downStartIndex].value const element = elementList[downStartIndex]
if (value !== ZERO) { const nextElement = elementList[downStartIndex + 1]
downCount++ if (
downStartIndex++ (element.value === ZERO && !element.listWrap) ||
} else { element.listId !== nextElement?.listId ||
element.titleId !== nextElement?.titleId
) {
break break
} }
downCount++
downStartIndex++
} }
// 设置选中区域 // 设置选中区域-不选择段落首尾换行符
const rangeManager = draw.getRange() 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({ draw.render({
isSubmitHistory: false, isSubmitHistory: false,

Loading…
Cancel
Save