|
@@ -1,5 +1,5 @@
|
|
import { getActualPoint, getClickPoint, createSvg, createElement } from '../annotation/utils';
|
|
import { getActualPoint, getClickPoint, createSvg, createElement } from '../annotation/utils';
|
|
-import { onClickOutside, setCss, isMobileDevice } from '../ui_utils';
|
|
|
|
|
|
+import { onClickOutsideUp, setCss, isMobileDevice } from '../ui_utils';
|
|
import copy from 'copy-to-clipboard';
|
|
import copy from 'copy-to-clipboard';
|
|
|
|
|
|
export class TextEditor {
|
|
export class TextEditor {
|
|
@@ -35,11 +35,17 @@ export class TextEditor {
|
|
this.borderWidth = 2
|
|
this.borderWidth = 2
|
|
this.pointWidth = 6
|
|
this.pointWidth = 6
|
|
this.pointHeight = 6
|
|
this.pointHeight = 6
|
|
- this.activeCharPlace = null
|
|
|
|
|
|
+ this.activeCharPlace = {
|
|
|
|
+ SectionIndex: 0,
|
|
|
|
+ LineIndex: 0,
|
|
|
|
+ RunIndex: 0,
|
|
|
|
+ CharIndex: 0
|
|
|
|
+ }
|
|
this.selectedRects = null
|
|
this.selectedRects = null
|
|
this.selectedCharRange = null
|
|
this.selectedCharRange = null
|
|
this.state = 0 // 0 未选中;1 已选中;2 编辑状态
|
|
this.state = 0 // 0 未选中;1 已选中;2 编辑状态
|
|
this.mouseDown = false
|
|
this.mouseDown = false
|
|
|
|
+ this.moving = false
|
|
this.ratio = window.devicePixelRatio || 1
|
|
this.ratio = window.devicePixelRatio || 1
|
|
|
|
|
|
this.start = null
|
|
this.start = null
|
|
@@ -440,6 +446,7 @@ export class TextEditor {
|
|
|
|
|
|
if (!this.mouseDown) return
|
|
if (!this.mouseDown) return
|
|
this.mouseDown = false
|
|
this.mouseDown = false
|
|
|
|
+ this.moving = false
|
|
|
|
|
|
if (e.type === 'touchend') {
|
|
if (e.type === 'touchend') {
|
|
document.body.style.overscrollBehavior = 'auto';
|
|
document.body.style.overscrollBehavior = 'auto';
|
|
@@ -450,7 +457,10 @@ export class TextEditor {
|
|
this.state = 1
|
|
this.state = 1
|
|
flag = false
|
|
flag = false
|
|
|
|
|
|
|
|
+ this.getTextStyle()
|
|
|
|
+
|
|
this.contentContainer.selectedFrameIndex = this.editAreaIndex
|
|
this.contentContainer.selectedFrameIndex = this.editAreaIndex
|
|
|
|
+ this.eventBus.dispatch('changeRightPanelBtnDisabled', false)
|
|
}
|
|
}
|
|
|
|
|
|
if (this.state === 1) {
|
|
if (this.state === 1) {
|
|
@@ -491,9 +501,7 @@ export class TextEditor {
|
|
|
|
|
|
} else if (!this.mouseMoved && flag) {
|
|
} else if (!this.mouseMoved && flag) {
|
|
this.state = 2
|
|
this.state = 2
|
|
- if (isMobileDevice) {
|
|
|
|
- this.eventBus.dispatch('changeIsEditorPanelDisabled')
|
|
|
|
- } else {
|
|
|
|
|
|
+ if (!isMobileDevice) {
|
|
this.eventBus.dispatch('contentPropertyChange', { type: 'text', isOpen: true })
|
|
this.eventBus.dispatch('contentPropertyChange', { type: 'text', isOpen: true })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -577,7 +585,7 @@ export class TextEditor {
|
|
this.frameContainer.classList.add('selected')
|
|
this.frameContainer.classList.add('selected')
|
|
|
|
|
|
if (this.state === 1) {
|
|
if (this.state === 1) {
|
|
- onClickOutside([this.textContainer, this.outerLine, document.querySelector('.editor-panel'), document.getElementById('propertyPanelButton')], this.handleOutside.bind(this))
|
|
|
|
|
|
+ onClickOutsideUp([this.textContainer, this.outerLine, document.querySelector('.editor-panel'), document.getElementById('propertyPanelButton')], this.handleOutside.bind(this))
|
|
}
|
|
}
|
|
|
|
|
|
document.removeEventListener(this.mousemove, this.onMousemove)
|
|
document.removeEventListener(this.mousemove, this.onMousemove)
|
|
@@ -588,6 +596,8 @@ export class TextEditor {
|
|
|
|
|
|
async handleMouseMove (e) {
|
|
async handleMouseMove (e) {
|
|
if (this.contentContainer.selectedFrameIndex !== -1 && this.contentContainer.selectedFrameIndex !== this.editAreaIndex && this.state === 0) return
|
|
if (this.contentContainer.selectedFrameIndex !== -1 && this.contentContainer.selectedFrameIndex !== this.editAreaIndex && this.state === 0) return
|
|
|
|
+
|
|
|
|
+ this.moving = true
|
|
|
|
|
|
if (e.type === 'touchmove') {
|
|
if (e.type === 'touchmove') {
|
|
document.body.style.overscrollBehavior = 'none';
|
|
document.body.style.overscrollBehavior = 'none';
|
|
@@ -762,27 +772,32 @@ export class TextEditor {
|
|
}
|
|
}
|
|
|
|
|
|
async handleOutside () {
|
|
async handleOutside () {
|
|
|
|
+ if (this.moving) return
|
|
|
|
+
|
|
this.state = this.state === 2 ? 1 : this.state === 1 ? 0 : this.state
|
|
this.state = this.state === 2 ? 1 : this.state === 1 ? 0 : this.state
|
|
|
|
|
|
this.frameContainer.classList.remove('editing')
|
|
this.frameContainer.classList.remove('editing')
|
|
|
|
|
|
- this.eventBus.dispatch('contentPropertyChange', { type: 'text', isOpen: false })
|
|
|
|
-
|
|
|
|
this.clearSelectText()
|
|
this.clearSelectText()
|
|
this.cursor?.remove()
|
|
this.cursor?.remove()
|
|
this.cursor = null
|
|
this.cursor = null
|
|
|
|
|
|
if (this.state === 0) {
|
|
if (this.state === 0) {
|
|
this.frameContainer.classList.remove('selected')
|
|
this.frameContainer.classList.remove('selected')
|
|
-
|
|
|
|
this.outerLine.remove()
|
|
this.outerLine.remove()
|
|
|
|
|
|
this.contentContainer.selectedFrameIndex = -1
|
|
this.contentContainer.selectedFrameIndex = -1
|
|
|
|
+
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ const hasItem = document.querySelector('.frame-container.selected')
|
|
|
|
+ if (!hasItem) {
|
|
|
|
+ this.eventBus.dispatch('contentPropertyChange', { type: 'text', isOpen: false })
|
|
|
|
+ this.eventBus.dispatch('changeRightPanelBtnDisabled', true)
|
|
|
|
+ }
|
|
|
|
+ }, 1)
|
|
}
|
|
}
|
|
|
|
|
|
if (this.state === 1) {
|
|
if (this.state === 1) {
|
|
- document.getElementById('propertyPanelButton').click()
|
|
|
|
-
|
|
|
|
const text = await this.getText()
|
|
const text = await this.getText()
|
|
if (text.length === 0) {
|
|
if (text.length === 0) {
|
|
await this.outerLine.remove()
|
|
await this.outerLine.remove()
|
|
@@ -795,7 +810,7 @@ export class TextEditor {
|
|
|
|
|
|
this.textContainer.removeEventListener(this.mousemove, this.onMousemove)
|
|
this.textContainer.removeEventListener(this.mousemove, this.onMousemove)
|
|
|
|
|
|
- onClickOutside([this.textContainer, this.outerLine, document.querySelector('.editor-panel'), document.getElementById('propertyPanelButton')], this.handleOutside.bind(this))
|
|
|
|
|
|
+ onClickOutsideUp([this.textContainer, this.outerLine, document.querySelector('.editor-panel'), document.getElementById('propertyPanelButton')], this.handleOutside.bind(this))
|
|
}
|
|
}
|
|
|
|
|
|
this.textarea.removeEventListener('blur', this.onBlur)
|
|
this.textarea.removeEventListener('blur', this.onBlur)
|
|
@@ -1092,7 +1107,7 @@ export class TextEditor {
|
|
|
|
|
|
const style = {
|
|
const style = {
|
|
color: `rgb(${textStyle.R}, ${textStyle.G}, ${textStyle.B})`,
|
|
color: `rgb(${textStyle.R}, ${textStyle.G}, ${textStyle.B})`,
|
|
- opacity: textStyle.Transparency * 100,
|
|
|
|
|
|
+ opacity: Math.round(textStyle.Transparency * 100),
|
|
fontStyle: textStyle.IsBold && textStyle.IsItalic ? 3 : !textStyle.IsBold && !textStyle.IsItalic ? 0 : textStyle.IsBold ? 1 : 2,
|
|
fontStyle: textStyle.IsBold && textStyle.IsItalic ? 3 : !textStyle.IsBold && !textStyle.IsItalic ? 0 : textStyle.IsBold ? 1 : 2,
|
|
fontSize: Math.round(textStyle.FontSize)
|
|
fontSize: Math.round(textStyle.FontSize)
|
|
}
|
|
}
|
|
@@ -1402,10 +1417,14 @@ export class TextEditor {
|
|
|
|
|
|
// 属性面板 修改属性
|
|
// 属性面板 修改属性
|
|
async handlePropertyPanelChanged (props) {
|
|
async handlePropertyPanelChanged (props) {
|
|
- if (this.state !== 2) return
|
|
|
|
|
|
+ if (this.state === 0) return
|
|
|
|
|
|
let changed = false
|
|
let changed = false
|
|
|
|
|
|
|
|
+ if (!this.selectedCharRange && this.state === 1) {
|
|
|
|
+ await this.selectAllText()
|
|
|
|
+ }
|
|
|
|
+
|
|
for (const item in props) {
|
|
for (const item in props) {
|
|
if (props[item] === this.textStyle[item]) continue
|
|
if (props[item] === this.textStyle[item]) continue
|
|
|
|
|
|
@@ -1426,7 +1445,7 @@ export class TextEditor {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (!this.selectedCharRange && item !== 'alignType') {
|
|
|
|
|
|
+ if (!this.selectedCharRange && item !== 'alignType' && this.state === 2) {
|
|
await this.selectAllText()
|
|
await this.selectAllText()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1491,20 +1510,25 @@ export class TextEditor {
|
|
const oldRect = this.rect
|
|
const oldRect = this.rect
|
|
await this.updateCanvas(null, oldRect)
|
|
await this.updateCanvas(null, oldRect)
|
|
|
|
|
|
- const { start, end } = await this.messageHandler.sendWithPromise('RefreshRange', {
|
|
|
|
- editAreaPtr: this.editAreaPtr,
|
|
|
|
- start: this.selectedCharRange.start,
|
|
|
|
- end: this.selectedCharRange.end,
|
|
|
|
- })
|
|
|
|
- this.selectedCharRange = { start, end }
|
|
|
|
|
|
+ if (this.selectedCharRange && this.state === 2) {
|
|
|
|
+ const { start, end } = await this.messageHandler.sendWithPromise('RefreshRange', {
|
|
|
|
+ editAreaPtr: this.editAreaPtr,
|
|
|
|
+ start: this.selectedCharRange.start,
|
|
|
|
+ end: this.selectedCharRange.end,
|
|
|
|
+ })
|
|
|
|
+ this.selectedCharRange = { start, end }
|
|
|
|
|
|
- if (this.activeCharPlace.CharIndex === start.CharIndex) {
|
|
|
|
- this.activeCharPlace = start
|
|
|
|
- } else {
|
|
|
|
- this.activeCharPlace = end
|
|
|
|
|
|
+ if (this.activeCharPlace.CharIndex === start.CharIndex) {
|
|
|
|
+ this.activeCharPlace = start
|
|
|
|
+ } else {
|
|
|
|
+ this.activeCharPlace = end
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- this.updateSelectedRect()
|
|
|
|
|
|
+ if (this.state === 2) {
|
|
|
|
+ this.updateSelectedRect()
|
|
|
|
+ this.updateCursorLine()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// 设置文本样式
|
|
// 设置文本样式
|
|
@@ -1609,7 +1633,7 @@ export class TextEditor {
|
|
this.textarea.addEventListener('compositionend', this.onCompositionend)
|
|
this.textarea.addEventListener('compositionend', this.onCompositionend)
|
|
}
|
|
}
|
|
|
|
|
|
- onClickOutside([this.textContainer, this.outerLine, document.querySelector('.editor-panel'), document.getElementById('propertyPanelButton')], this.handleOutside.bind(this))
|
|
|
|
|
|
+ onClickOutsideUp([this.textContainer, this.outerLine, document.querySelector('.editor-panel'), document.getElementById('propertyPanelButton')], this.handleOutside.bind(this))
|
|
}
|
|
}
|
|
|
|
|
|
// 删除区域
|
|
// 删除区域
|
|
@@ -1644,6 +1668,6 @@ export class TextEditor {
|
|
async selectAllText () {
|
|
async selectAllText () {
|
|
const { start, end } = await this.messageHandler.sendWithPromise('GetBeginAndEndCharPlace', this.editAreaPtr)
|
|
const { start, end } = await this.messageHandler.sendWithPromise('GetBeginAndEndCharPlace', this.editAreaPtr)
|
|
this.selectedCharRange = { start, end }
|
|
this.selectedCharRange = { start, end }
|
|
- this.selectedRectList = await this.getCharsRect(start, end)
|
|
|
|
|
|
+ if (this.state === 2) this.selectedRectList = await this.getCharsRect(start, end)
|
|
}
|
|
}
|
|
}
|
|
}
|