|
@@ -3,8 +3,8 @@ import copy from 'copy-to-clipboard';
|
|
|
import { getAbsoluteCoordinate, getInitialPoint, getActualPoint } from './annotation/utils.js';
|
|
|
import { isMobileDevice } from './ui_utils';
|
|
|
|
|
|
-const markupType = isMobileDevice ? ['highlight', 'underline', 'squiggly', 'strikeout', 'selectText'] : ['highlight', 'underline', 'squiggly', 'strikeout', '']
|
|
|
-const markupTypeNotNull = ['highlight', 'underline', 'squiggly', 'strikeout']
|
|
|
+const markupType = isMobileDevice ? ['highlight', 'underline', 'squiggly', 'strikeout', 'selectText'] : ['highlight', 'underline', 'squiggly', 'strikeout', '', 'redaction', 'remove']
|
|
|
+const markupTypeNotNull = ['highlight', 'underline', 'squiggly', 'strikeout', 'redaction', 'remove']
|
|
|
type Point = {
|
|
|
x: number,
|
|
|
y: number
|
|
@@ -91,7 +91,7 @@ export default class TextSelection {
|
|
|
document.removeEventListener('touchmove', this.handleMouseMove)
|
|
|
document.removeEventListener('dblclick', this.handleDobuleClick)
|
|
|
|
|
|
- if (this.toolMode === 'view' || this.toolMode === 'annotation') {
|
|
|
+ if (['view', 'annotation', 'security'].includes(this.toolMode)) {
|
|
|
document.addEventListener('keydown', this.handleKeyDown)
|
|
|
document.addEventListener('mousedown', this.handleMouseDown)
|
|
|
document.addEventListener('touchstart', this.handleMouseDown)
|
|
@@ -166,7 +166,7 @@ export default class TextSelection {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- handleMouseDown(event: MouseEvent) {
|
|
|
+ async handleMouseDown(event: MouseEvent) {
|
|
|
// return的几种情况:
|
|
|
// 文本悬浮菜单下,且不清空选中文本
|
|
|
if (this.isTargetInElement(event.target, '.text-popup')) return
|
|
@@ -201,7 +201,8 @@ export default class TextSelection {
|
|
|
const { x, y } = inPage
|
|
|
const point = getInitialPoint({ x, y }, this.viewport, this.scale)
|
|
|
this.startPoint = point
|
|
|
- this.selecting = true
|
|
|
+ const isText = await this.isTextAtPoint(point)
|
|
|
+ this.selecting = !!isText
|
|
|
|
|
|
document.addEventListener('mouseup', this.handleMouseUp)
|
|
|
document.addEventListener('touchend', this.handleMouseUp)
|
|
@@ -215,12 +216,7 @@ export default class TextSelection {
|
|
|
}
|
|
|
const { x, y } = inPage
|
|
|
const point = getInitialPoint({ x, y }, this.viewport, this.scale)
|
|
|
-
|
|
|
- const isText = await this.messageHandler.sendWithPromise('GetCharIndexAtPos', {
|
|
|
- pagePtr: this.#pagePtr,
|
|
|
- textPtr: this.#textPtr,
|
|
|
- point
|
|
|
- })
|
|
|
+ const isText = await this.isTextAtPoint(point)
|
|
|
const startPoint = this.startPoint
|
|
|
if (startPoint && (startPoint.x === point.x || startPoint.y === point.y)) return
|
|
|
if (isText) {
|
|
@@ -252,13 +248,7 @@ export default class TextSelection {
|
|
|
}
|
|
|
const { x, y } = inPage
|
|
|
const point = getInitialPoint({ x, y }, this.viewport, this.scale)
|
|
|
-
|
|
|
- const isText = await this.messageHandler.sendWithPromise('GetCharIndexAtPos', {
|
|
|
- pagePtr: this.#pagePtr,
|
|
|
- textPtr: this.#textPtr,
|
|
|
- point
|
|
|
- })
|
|
|
-
|
|
|
+ const isText = await this.isTextAtPoint(point)
|
|
|
if (!isText) return
|
|
|
|
|
|
const selection = await this.messageHandler.sendWithPromise('GetSelectionForWordAtPos', {
|
|
@@ -278,7 +268,7 @@ export default class TextSelection {
|
|
|
handleMouseUp() {
|
|
|
if (this.selecting && this._selection && markupTypeNotNull.includes(this.tool)) {
|
|
|
const annotationData = {
|
|
|
- operate: "add-annot",
|
|
|
+ operate: 'add-annot',
|
|
|
type: this.tool,
|
|
|
pageIndex: this.pageIndex,
|
|
|
date: new Date(),
|
|
@@ -288,6 +278,12 @@ export default class TextSelection {
|
|
|
color: this.color,
|
|
|
contents: this._selection.textContent || undefined
|
|
|
}
|
|
|
+ if (this.tool === 'redaction' || this.tool === 'remove') {
|
|
|
+ annotationData.type = 'redact'
|
|
|
+ annotationData.erasure = this.tool === 'remove'
|
|
|
+ annotationData.fillColor = 'rgb(0, 0, 0)'
|
|
|
+ delete annotationData.opacity
|
|
|
+ }
|
|
|
|
|
|
this.eventBus.dispatch('annotationChange', {
|
|
|
type: 'add',
|
|
@@ -309,6 +305,7 @@ export default class TextSelection {
|
|
|
updateSelection() {
|
|
|
const textRects = this._selection.textRects
|
|
|
this.textContainer?.textContent = ''
|
|
|
+ const rects = []
|
|
|
const quadPoints = []
|
|
|
const topArray = []
|
|
|
const bottomArray = []
|
|
@@ -344,9 +341,11 @@ export default class TextSelection {
|
|
|
PointY: bottom
|
|
|
}
|
|
|
quadPoints.push(leftTop, rightTop, leftBottom, rightBottom)
|
|
|
+ rects.push(rect)
|
|
|
this.drawSelection(rect)
|
|
|
}
|
|
|
this.quadPoints = quadPoints
|
|
|
+ this.rects = rects
|
|
|
const top = Math.min(...topArray)
|
|
|
const bottom = Math.max(...bottomArray)
|
|
|
const left = Math.min(...leftArray)
|
|
@@ -468,4 +467,12 @@ export default class TextSelection {
|
|
|
if (el && el.contains(target)) return true
|
|
|
else return false
|
|
|
}
|
|
|
+
|
|
|
+ async isTextAtPoint(point: Point): boolean {
|
|
|
+ return await this.messageHandler.sendWithPromise('GetCharIndexAtPos', {
|
|
|
+ pagePtr: this.#pagePtr,
|
|
|
+ textPtr: this.#textPtr,
|
|
|
+ point
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|