Explorar o código

add: 内容编辑新增编辑后触发事件

liutian hai 7 meses
pai
achega
83c228a4d6

+ 1 - 0
packages/core/src/editor/content_container.js

@@ -373,6 +373,7 @@ export class ContentContainer {
   async handleOperateList(data) {
     const canUndo = await this.historyManager.canUndo()
     if (!canUndo) return
+    this.eventBus.dispatch('undoRedoStatusChanged')
     this.historyManager.undoList.push(data)
     this.historyManager.redoList.length = 0
 

+ 6 - 0
packages/core/src/editor/content_edit_history_manager.js

@@ -42,8 +42,11 @@ export class ContentEditHistoryManager {
       return false
     }
     const res = await this.messageHandler.sendWithPromise('Redo', this.editPagePtr)
+
     this.undoList.push(lastRedo)
     this.updateView(res)
+
+    this.eventBus.dispatch('undoRedoStatusChanged')
   }
 
   async undo() {
@@ -59,8 +62,11 @@ export class ContentEditHistoryManager {
     }
     const res = await this.messageHandler.sendWithPromise('Undo', this.editPagePtr)
     const canRedo = await this.canRedo()
+
     canRedo && this.redoList.push(lastUndo)
     this.updateView(res)
+
+    this.eventBus.dispatch('undoRedoStatusChanged')
   }
 
   async updateView(res) {

+ 12 - 2
packages/core/src/editor/text_editor.js

@@ -3,6 +3,7 @@ import { onClickOutsideUp, setCss, isMobileDevice } from '../ui_utils';
 import copy from 'copy-to-clipboard';
 
 export class TextEditor {
+  #editList = []
   constructor({
     eventBus,
     contentContainer,
@@ -31,7 +32,7 @@ export class TextEditor {
     this.newAdd = newAdd
     this.pageViewer = pageViewer
     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"/>`
@@ -998,17 +999,26 @@ export class TextEditor {
         return
       }
     }
+    this.#editList.push(data)
+    if (this.#editList.length > 1) return
+    this.handleInsertText()
+  }
 
+  async handleInsertText() {
     const newChar = await this.messageHandler.sendWithPromise('InsertText', {
       editAreaPtr: this.editAreaPtr,
       char: this.activeCharPlace,
-      text: data
+      text: this.#editList[0]
     })
     this.activeCharPlace = newChar
 
     this.addUndoHistory()
     this.updateCanvas()
     this.updateCursorLine()
+    this.#editList.length && this.#editList.shift()
+    if (this.#editList.length > 0) {
+      await this.handleInsertText()
+    }
   }
 
   // 兼容FireFox 监听中文输入

+ 3 - 6
packages/core/src/worker/compdfkit_worker.js

@@ -161,10 +161,6 @@ class CPDFWorker {
       if (data.fileList) {
         ComPDFKitJS.opened_Font[0] = data.fileList
       }
-
-      if (data.defaultFont) {
-        ComPDFKitJS.opened_DefFont[0] = data.defaultFont
-      }
       if (data.webFontURL !== './lib/fonts/') {
         webFontURL = data.webFontURL
       }
@@ -1165,19 +1161,20 @@ class CPDFWorker {
       return { start: EditCharPlace, end: EndEditCharPlace }
     })
 
-    messageHandler.on('InsertText', async (data) => {
+    messageHandler.on('InsertText', (data) => {
       const { editAreaPtr, char, text } = data
 
       EditCharPlace = {}
 
       let textPtr = stringToNewUTF8(text)
 
-      await Module._InsertText(
+      Module._InsertText(
         editAreaPtr,
         char.SectionIndex, char.LineIndex, char.RunIndex, char.CharIndex,
         textPtr,
         true
       )
+
       return EditCharPlace
     })
 

+ 4 - 0
packages/webview/src/components/ToggleRightPanelButton/index.vue

@@ -43,6 +43,10 @@
     core.eventBus().dispatch('isRightSidePanelOpened', newValue)
   })
 
+  watch(rightPanelButtonDisabled, (newValue, oldValue) => {
+    core.eventBus().dispatch('isRightPanelDisabled', newValue)
+  })
+
   const onClick = () => {
     setTimeout(() => {
       isDisabled.value = document.getElementsByClassName('outline-container').length === 0