Merge pull request #77 from Hufe921/feature/paragraph-selection
feat:paragraph selection when clicked three times
This commit is contained in:
@@ -18,7 +18,7 @@ import { RangeManager } from '../range/RangeManager'
|
|||||||
import { LETTER_REG, NUMBER_LIKE_REG } from '../../dataset/constant/Regular'
|
import { LETTER_REG, NUMBER_LIKE_REG } from '../../dataset/constant/Regular'
|
||||||
import { Control } from '../draw/control/Control'
|
import { Control } from '../draw/control/Control'
|
||||||
import { CheckboxControl } from '../draw/control/checkbox/CheckboxControl'
|
import { CheckboxControl } from '../draw/control/checkbox/CheckboxControl'
|
||||||
import { splitText } from '../../utils'
|
import { splitText, threeClick } from '../../utils'
|
||||||
import { Previewer } from '../draw/particle/previewer/Previewer'
|
import { Previewer } from '../draw/particle/previewer/Previewer'
|
||||||
import { DeepRequired } from '../../interface/Common'
|
import { DeepRequired } from '../../interface/Common'
|
||||||
import { DateParticle } from '../draw/particle/date/DateParticle'
|
import { DateParticle } from '../draw/particle/date/DateParticle'
|
||||||
@@ -72,6 +72,7 @@ export class CanvasEvent {
|
|||||||
this.pageContainer.addEventListener('mouseleave', this.mouseleave.bind(this))
|
this.pageContainer.addEventListener('mouseleave', this.mouseleave.bind(this))
|
||||||
this.pageContainer.addEventListener('mousemove', this.mousemove.bind(this))
|
this.pageContainer.addEventListener('mousemove', this.mousemove.bind(this))
|
||||||
this.pageContainer.addEventListener('dblclick', this.dblclick.bind(this))
|
this.pageContainer.addEventListener('dblclick', this.dblclick.bind(this))
|
||||||
|
threeClick(this.pageContainer, this.threeClick.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
public setIsAllowDrag(payload: boolean) {
|
public setIsAllowDrag(payload: boolean) {
|
||||||
@@ -516,6 +517,46 @@ export class CanvasEvent {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public threeClick() {
|
||||||
|
const cursorPosition = this.position.getCursorPosition()
|
||||||
|
if (!cursorPosition) return
|
||||||
|
const { index } = cursorPosition
|
||||||
|
const elementList = this.draw.getElementList()
|
||||||
|
// 判断是否是零宽字符
|
||||||
|
let upCount = 0
|
||||||
|
let downCount = 0
|
||||||
|
// 向上查询
|
||||||
|
let upStartIndex = index - 1
|
||||||
|
while (upStartIndex > 0) {
|
||||||
|
const value = elementList[upStartIndex].value
|
||||||
|
if (value !== ZERO) {
|
||||||
|
upCount++
|
||||||
|
upStartIndex--
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 向下查询
|
||||||
|
let downStartIndex = index + 1
|
||||||
|
while (downStartIndex < elementList.length) {
|
||||||
|
const value = elementList[downStartIndex].value
|
||||||
|
if (value !== ZERO) {
|
||||||
|
downCount++
|
||||||
|
downStartIndex++
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置选中区域
|
||||||
|
this.range.setRange(index - upCount - 1, index + downCount)
|
||||||
|
// 刷新文档
|
||||||
|
this.draw.render({
|
||||||
|
isSubmitHistory: false,
|
||||||
|
isSetCursor: false,
|
||||||
|
isComputeRowList: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public input(data: string) {
|
public input(data: string) {
|
||||||
const isReadonly = this.draw.isReadonly()
|
const isReadonly = this.draw.isReadonly()
|
||||||
if (isReadonly) return
|
if (isReadonly) return
|
||||||
|
|||||||
@@ -66,4 +66,25 @@ export function downloadFile(href: string, fileName: string) {
|
|||||||
a.href = href
|
a.href = href
|
||||||
a.download = fileName
|
a.download = fileName
|
||||||
a.click()
|
a.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function threeClick(dom: HTMLElement, fn: (evt: MouseEvent) => any) {
|
||||||
|
nClickEvent(3, dom, fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
function nClickEvent(n: number, dom: HTMLElement, fn: (evt: MouseEvent) => any) {
|
||||||
|
let count = 0
|
||||||
|
let lastTime = 0
|
||||||
|
|
||||||
|
const handler = function (evt: MouseEvent) {
|
||||||
|
const currentTime = new Date().getTime()
|
||||||
|
count = (currentTime - lastTime < 300) ? count + 1 : 0
|
||||||
|
lastTime = new Date().getTime()
|
||||||
|
if (count >= n - 1) {
|
||||||
|
fn(evt)
|
||||||
|
count = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dom.addEventListener('click', handler)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user