Skip to content

Commit 51096f6

Browse files
committed
feat: triple-click to select all content in the control #1293
1 parent a6c779b commit 51096f6

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/editor/core/draw/control/Control.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,52 @@ export class Control {
617617
}
618618
}
619619

620+
public selectValue(): boolean {
621+
const elementList = this.getElementList()
622+
const { startIndex } = this.getRange()
623+
const startElement = elementList[startIndex]
624+
if (
625+
!startElement?.controlId ||
626+
(startElement.controlComponent !== ControlComponent.VALUE &&
627+
elementList[startIndex + 1]?.controlComponent ===
628+
ControlComponent.VALUE)
629+
) {
630+
return false
631+
}
632+
// 向左查找
633+
let preIndex = startIndex
634+
while (preIndex > 0) {
635+
const preElement = elementList[preIndex]
636+
if (preElement.controlComponent !== ControlComponent.VALUE) break
637+
preIndex--
638+
}
639+
// 向右查找
640+
let nextIndex = startIndex + 1
641+
while (nextIndex < elementList.length) {
642+
const nextElement = elementList[nextIndex]
643+
if (nextElement.controlComponent !== ControlComponent.VALUE) {
644+
nextIndex--
645+
break
646+
}
647+
nextIndex++
648+
}
649+
if (preIndex !== nextIndex) {
650+
const range = this.range.getRange()
651+
this.range.replaceRange({
652+
...range,
653+
startIndex: preIndex,
654+
endIndex: nextIndex
655+
})
656+
this.draw.render({
657+
isCompute: false,
658+
isSetCursor: false,
659+
isSubmitHistory: false
660+
})
661+
return true
662+
}
663+
return false
664+
}
665+
620666
public moveCursor(position: IControlInitOption): IMoveCursorResult {
621667
const { index, trIndex, tdIndex, tdValueIndex } = position
622668
let elementList = this.draw.getOriginalElementList()

src/editor/core/event/handlers/click.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ function dblclick(host: CanvasEvent, evt: MouseEvent) {
152152

153153
function threeClick(host: CanvasEvent) {
154154
const draw = host.getDraw()
155+
// 优先选择控件内容
156+
const control = draw.getControl()
157+
if (control.getActiveControl() && control.selectValue()) return
158+
// 选择整个段落
155159
const position = draw.getPosition()
156160
const cursorPosition = position.getCursorPosition()
157161
if (!cursorPosition) return

0 commit comments

Comments
 (0)