Merge pull request #25 from Hufe921/feature/dblclick-selection
Feature/dblclick selection
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
outline: none;
|
outline: none;
|
||||||
background-color: #000000;
|
background-color: #000000;
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cursor--animation {
|
.cursor--animation {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { HistoryManager } from "../history/HistoryManager"
|
|||||||
import { Listener } from "../listener/Listener"
|
import { Listener } from "../listener/Listener"
|
||||||
import { Position } from "../position/Position"
|
import { Position } from "../position/Position"
|
||||||
import { RangeManager } from "../range/RangeManager"
|
import { RangeManager } from "../range/RangeManager"
|
||||||
|
import { LETTER_REG, NUMBER_LIKE_REG } from "../../dataset/constant/Regular"
|
||||||
|
|
||||||
export class CanvasEvent {
|
export class CanvasEvent {
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ export class CanvasEvent {
|
|||||||
this.pageContainer.addEventListener('mousedown', this.mousedown.bind(this))
|
this.pageContainer.addEventListener('mousedown', this.mousedown.bind(this))
|
||||||
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
public setIsAllowDrag(payload: boolean) {
|
public setIsAllowDrag(payload: boolean) {
|
||||||
@@ -376,6 +378,49 @@ export class CanvasEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public dblclick() {
|
||||||
|
const cursorPosition = this.position.getCursorPosition()
|
||||||
|
if (!cursorPosition) return
|
||||||
|
const { value, index } = cursorPosition
|
||||||
|
const elementList = this.draw.getElementList()
|
||||||
|
// 判断是否是数字或英文
|
||||||
|
let upCount = 0
|
||||||
|
let downCount = 0
|
||||||
|
const isNumber = NUMBER_LIKE_REG.test(value)
|
||||||
|
if (isNumber || LETTER_REG.test(value)) {
|
||||||
|
// 向上查询
|
||||||
|
let upStartIndex = index - 1
|
||||||
|
while (upStartIndex > 0) {
|
||||||
|
const value = elementList[upStartIndex].value
|
||||||
|
if ((isNumber && NUMBER_LIKE_REG.test(value)) || (!isNumber && LETTER_REG.test(value))) {
|
||||||
|
upCount++
|
||||||
|
upStartIndex--
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 向下查询
|
||||||
|
let downStartIndex = index + 1
|
||||||
|
while (downStartIndex < elementList.length) {
|
||||||
|
const value = elementList[downStartIndex].value
|
||||||
|
if ((isNumber && NUMBER_LIKE_REG.test(value)) || (!isNumber && LETTER_REG.test(value))) {
|
||||||
|
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
|
||||||
|
|||||||
@@ -148,8 +148,8 @@ export class Position {
|
|||||||
const isHead = x < this.options.margins[3]
|
const isHead = x < this.options.margins[3]
|
||||||
// 是否在头部
|
// 是否在头部
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
const headIndex = positionList.findIndex(p => p.rowNo === firstLetterList[j].rowNo)
|
const headIndex = positionList.findIndex(p => p.pageNo === curPageNo && p.rowNo === firstLetterList[j].rowNo)
|
||||||
curPositionIndex = ~headIndex ? headIndex : index
|
curPositionIndex = ~headIndex ? headIndex - 1 : index
|
||||||
} else {
|
} else {
|
||||||
curPositionIndex = index
|
curPositionIndex = index
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export const NUMBER_REG = /[0-9]/
|
||||||
|
export const LETTER_REG = /[a-zA-Z]/
|
||||||
|
export const NUMBER_LIKE_REG = /[0-9.]/
|
||||||
|
export const CHINESE_REG = /[\u4e00-\u9fa5]/
|
||||||
@@ -39,5 +39,5 @@ export function writeTextByElementList(elementList: IElement[]) {
|
|||||||
}
|
}
|
||||||
pickTextFromElement(elementList)
|
pickTextFromElement(elementList)
|
||||||
if (!text) return
|
if (!text) return
|
||||||
writeText(text)
|
writeText(text.replace(new RegExp(`^${ZERO}`), ''))
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user