From 8878fd7734ae0a566f16ca2db14e64ded5a05f38 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Sat, 3 Aug 2024 21:05:55 +0800 Subject: [PATCH] feat: set range using the shift shortcut key #728 --- src/editor/core/event/handlers/mousedown.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/editor/core/event/handlers/mousedown.ts b/src/editor/core/event/handlers/mousedown.ts index d3cc682..c1bf0ac 100644 --- a/src/editor/core/event/handlers/mousedown.ts +++ b/src/editor/core/event/handlers/mousedown.ts @@ -48,6 +48,8 @@ export function mousedown(evt: MouseEvent, host: CanvasEvent) { draw.setPageNo(Number(pageIndex)) } host.isAllowSelection = true + // 缓存旧上下文信息 + const oldPositionContext = deepClone(position.getPositionContext()) const positionResult = position.adjustPositionContext({ x: evt.offsetX, y: evt.offsetY @@ -79,7 +81,23 @@ export function mousedown(evt: MouseEvent, host: CanvasEvent) { const isDirectHitCheckbox = !!(isDirectHit && isCheckbox) const isDirectHitRadio = !!(isDirectHit && isRadio) if (~index) { - rangeManager.setRange(curIndex, curIndex) + let startIndex = curIndex + let endIndex = curIndex + // shift激活时进行选区处理 + if (evt.shiftKey) { + const { startIndex: oldStartIndex } = rangeManager.getRange() + if (~oldStartIndex) { + const newPositionContext = position.getPositionContext() + if (newPositionContext.tdId === oldPositionContext.tdId) { + if (curIndex > oldStartIndex) { + startIndex = oldStartIndex + } else { + endIndex = oldStartIndex + } + } + } + } + rangeManager.setRange(startIndex, endIndex) position.setCursorPosition(positionList[curIndex]) // 复选框 const isSetCheckbox = isDirectHitCheckbox && !isReadonly