diff --git a/src/editor/core/event/handlers/click.ts b/src/editor/core/event/handlers/click.ts index ce9c727..1b31a6c 100644 --- a/src/editor/core/event/handlers/click.ts +++ b/src/editor/core/event/handlers/click.ts @@ -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) // 刷新文档 @@ -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,