|
@@ -33,6 +33,8 @@ export class TextEditor {
|
|
|
this.hidden = hidden
|
|
|
|
|
|
this.type = 'text'
|
|
|
+ this.deleteSvgStr = `<rect width="30" height="30" rx="2" fill="#DDE9FF"/>
|
|
|
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M19 6.5V9.5H24V10.5H21.5V23.5H8.5V10.5H6V9.5H11V6.5H19ZM9.5 10.5V22.5H20.5V10.5H9.5ZM18 7.5V9.5H12V7.5H18ZM13.5 13V20H12.5V13H13.5ZM17.5 20V13H16.5V20H17.5Z" fill="#333333"/>`
|
|
|
|
|
|
this.frame = null
|
|
|
this.canvas = null
|
|
@@ -153,6 +155,35 @@ export class TextEditor {
|
|
|
this.textContainer.addEventListener(this.mousedown, this.onMousedown)
|
|
|
this.textContainer.addEventListener(this.mouseup, this.onMouseup)
|
|
|
|
|
|
+ this.outerLineContainer = document.createElement('div')
|
|
|
+ this.outerLineContainer.className = 'outline-container'
|
|
|
+ this.outerLineContainer.style.position = 'absolute'
|
|
|
+
|
|
|
+ this.deletetButton = createSvg(
|
|
|
+ "svg",
|
|
|
+ {
|
|
|
+ width: "30",
|
|
|
+ height: "30",
|
|
|
+ viewBox: "0 0 30 30",
|
|
|
+ fill: "none",
|
|
|
+ class: 'delete-button'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ position: 'absolute',
|
|
|
+ width: '30px',
|
|
|
+ height: '30px',
|
|
|
+ cursor: 'pointer',
|
|
|
+ zIndex: 2
|
|
|
+ }
|
|
|
+ )
|
|
|
+ this.deletetButton.addEventListener('click', this.remove.bind(this))
|
|
|
+ this.deletetButton.innerHTML = this.deleteSvgStr
|
|
|
+
|
|
|
+ const left = (this.rect.left + this.rect.width - 30) + 'px'
|
|
|
+ const top = (this.rect.top + this.rect.height + 8) + 'px'
|
|
|
+ this.deletetButton.style.left = left
|
|
|
+ this.deletetButton.style.top = top
|
|
|
+
|
|
|
const outerLine = createSvg('svg', {
|
|
|
class: 'outerline'
|
|
|
}, {
|
|
@@ -302,6 +333,8 @@ export class TextEditor {
|
|
|
this.outerLine.append(this.rightRect)
|
|
|
this.outerLine.append(this.topRightRect)
|
|
|
this.outerLine.append(this.topRect)
|
|
|
+ this.outerLineContainer.append(this.outerLine)
|
|
|
+ this.outerLineContainer.append(this.deletetButton)
|
|
|
|
|
|
this.outerLine.addEventListener(this.mousedown, this.onMousedown)
|
|
|
this.outerLine.addEventListener(this.mouseup, this.onMouseup)
|
|
@@ -312,7 +345,7 @@ export class TextEditor {
|
|
|
this.newAdd = false
|
|
|
}
|
|
|
|
|
|
- this.updateCanvas()
|
|
|
+ await this.updateCanvas()
|
|
|
}
|
|
|
|
|
|
getActualRect (viewport, s, frame) {
|
|
@@ -500,7 +533,7 @@ export class TextEditor {
|
|
|
this.end = this.newEnd
|
|
|
}
|
|
|
|
|
|
- this.container.append(this.outerLine)
|
|
|
+ this.container.append(this.outerLineContainer)
|
|
|
|
|
|
if (this.mouseMoved) {
|
|
|
const { start, end } = this.getInitialPoint(this.start, this.end)
|
|
@@ -528,7 +561,7 @@ export class TextEditor {
|
|
|
}
|
|
|
|
|
|
if (this.state === 2) {
|
|
|
- this.outerLine.remove()
|
|
|
+ this.outerLineContainer.remove()
|
|
|
this.frameContainer.classList.add('editing')
|
|
|
|
|
|
let endPoint
|
|
@@ -559,6 +592,7 @@ export class TextEditor {
|
|
|
}
|
|
|
const { start, end } = await this.getCharsRange(this.startPoint, endPoint)
|
|
|
this.activeCharPlace = end
|
|
|
+ this.getTextStyle()
|
|
|
|
|
|
if (!this.cursor) {
|
|
|
const cursor = createSvg(
|
|
@@ -588,10 +622,6 @@ export class TextEditor {
|
|
|
this.clearSelectText()
|
|
|
}
|
|
|
|
|
|
- if (!this.selectedRects) {
|
|
|
- this.getTextStyle()
|
|
|
- }
|
|
|
-
|
|
|
this.textarea.focus()
|
|
|
this.textarea.addEventListener('blur', this.onBlur)
|
|
|
this.textarea.addEventListener('keydown', this.onKeydown)
|
|
@@ -608,6 +638,7 @@ export class TextEditor {
|
|
|
onClickOutsideUp([
|
|
|
this.textContainer,
|
|
|
this.outerLine,
|
|
|
+ this.deletetButton,
|
|
|
document.querySelector('.editor-panel'),
|
|
|
document.getElementById('propertyPanelButton'),
|
|
|
document.getElementById('undo'),
|
|
@@ -798,6 +829,7 @@ export class TextEditor {
|
|
|
onClickOutsideUp([
|
|
|
this.textContainer,
|
|
|
this.outerLine,
|
|
|
+ this.deletetButton,
|
|
|
document.querySelector('.editor-panel'),
|
|
|
document.getElementById('propertyPanelButton'),
|
|
|
document.getElementById('undo'),
|
|
@@ -816,7 +848,7 @@ export class TextEditor {
|
|
|
|
|
|
if (this.state === 0) {
|
|
|
this.frameContainer?.classList.remove('selected')
|
|
|
- this.outerLine?.remove()
|
|
|
+ this.outerLineContainer?.remove()
|
|
|
|
|
|
if (!this.removed) this.contentContainer.selectedFrameIndex = -1
|
|
|
|
|
@@ -839,10 +871,11 @@ export class TextEditor {
|
|
|
this.textContainer.removeEventListener(this.mousemove, this.onMousemove)
|
|
|
|
|
|
if (!this.hidden) {
|
|
|
- this.container.append(this.outerLine)
|
|
|
+ this.container.append(this.outerLineContainer)
|
|
|
onClickOutsideUp([
|
|
|
this.textContainer,
|
|
|
this.outerLine,
|
|
|
+ this.deletetButton,
|
|
|
document.querySelector('.editor-panel'),
|
|
|
document.getElementById('propertyPanelButton'),
|
|
|
document.getElementById('undo'),
|
|
@@ -868,7 +901,7 @@ export class TextEditor {
|
|
|
|
|
|
this.isToolKey = isToolKey
|
|
|
|
|
|
- if (keyCode === 8 || keyCode === 46) { // 8 delete键,46 backspace键
|
|
|
+ if (keyCode === 8 || keyCode === 46) { // 8 backspace键,46 delete键
|
|
|
if (this.activeCharPlace.SectionIndex === 0
|
|
|
&& this.activeCharPlace.LineIndex === 0
|
|
|
&& this.activeCharPlace.RunIndex === 0
|
|
@@ -1001,7 +1034,7 @@ export class TextEditor {
|
|
|
async updateCanvas(whole, oldRect) {
|
|
|
if (!this.removed) await this.getRect()
|
|
|
|
|
|
- if (this.frameContainer && this.outerLine) {
|
|
|
+ if (this.frameContainer && this.outerLineContainer) {
|
|
|
this.updateOutline({
|
|
|
start: this.start,
|
|
|
end: this.end
|
|
@@ -1233,6 +1266,11 @@ export class TextEditor {
|
|
|
height: rect.height + this.borderWidth + this.pointHeight / 2 + 'px',
|
|
|
})
|
|
|
|
|
|
+ const left = (rect.left + rect.width - 30) + 'px'
|
|
|
+ const top = (rect.top + rect.height + 8) + 'px'
|
|
|
+ this.deletetButton.style.left = left
|
|
|
+ this.deletetButton.style.top = top
|
|
|
+
|
|
|
this.moveRect.setAttribute('width', rect.width - this.borderWidth)
|
|
|
this.moveRect.setAttribute('height', rect.height - this.borderWidth)
|
|
|
|
|
@@ -1539,7 +1577,9 @@ export class TextEditor {
|
|
|
const fontStyle = props.fontStyle
|
|
|
|
|
|
await this.setCharsFontStyle('ClearCharsFontBold')
|
|
|
+ await this.refreshSelecedRange()
|
|
|
await this.setCharsFontStyle('ClearCharsFontItalic')
|
|
|
+ await this.refreshSelecedRange()
|
|
|
|
|
|
if (fontStyle === 1) {
|
|
|
await this.setCharsFontStyle('SetCharsFontBold')
|
|
@@ -1561,18 +1601,7 @@ export class TextEditor {
|
|
|
await this.updateCanvas(null, true)
|
|
|
|
|
|
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
|
|
|
- }
|
|
|
+ await this.refreshSelecedRange()
|
|
|
}
|
|
|
|
|
|
if (this.state === 2) {
|
|
@@ -1686,6 +1715,7 @@ export class TextEditor {
|
|
|
onClickOutsideUp([
|
|
|
this.textContainer,
|
|
|
this.outerLine,
|
|
|
+ this.deletetButton,
|
|
|
document.querySelector('.editor-panel'),
|
|
|
document.getElementById('propertyPanelButton'),
|
|
|
document.getElementById('undo'),
|
|
@@ -1698,7 +1728,7 @@ export class TextEditor {
|
|
|
this.state = 0
|
|
|
await this.handleOutside()
|
|
|
|
|
|
- await this.outerLine.remove()
|
|
|
+ await this.outerLineContainer.remove()
|
|
|
this.frameContainer.remove()
|
|
|
this.frameContainer = null
|
|
|
this.contentContainer.selectedFrameIndex = -1
|
|
@@ -1723,7 +1753,7 @@ export class TextEditor {
|
|
|
this.state = 0
|
|
|
// await this.handleOutside()
|
|
|
|
|
|
- this.outerLine?.remove()
|
|
|
+ this.outerLineContainer?.remove()
|
|
|
this.frameContainer?.remove()
|
|
|
this.frameContainer = null
|
|
|
this.contentContainer.selectedFrameIndex = -1
|
|
@@ -1778,7 +1808,7 @@ export class TextEditor {
|
|
|
async updateCanvasAfterUndoRedo() {
|
|
|
await this.getRect()
|
|
|
|
|
|
- if (this.frameContainer && this.outerLine) {
|
|
|
+ if (this.frameContainer && this.outerLineContainer) {
|
|
|
this.updateOutline({
|
|
|
start: this.start,
|
|
|
end: this.end
|
|
@@ -1823,4 +1853,20 @@ export class TextEditor {
|
|
|
this.getTextStyle()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 修改属性后,刷新选中范围的数据
|
|
|
+ async refreshSelecedRange() {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|