Parcourir la source

fix: 修复Note bug

liutian il y a 1 an
Parent
commit
46df2273c8

+ 4 - 7
packages/core/src/annotation/paint/freetext.js

@@ -48,16 +48,14 @@ export default class Freetext {
   // FreeText 画布重置
   reset() {
     const freetextElement = this.freetextElement
-    this.start = null
-    this.end = null
 
     this.svgElement.style.cursor = 'default'
     this.container.removeEventListener('click', this.onClick)
     if (freetextElement) {
-      freetextElement.remove()
-      freetextElement.removeEventListener('blur', this.onBlur)
-      this.freetextElement = null
+      this.handleFreetext()
     }
+    this.start = null
+    this.end = null
   }
 
   // FreeText 画布初始化
@@ -137,9 +135,8 @@ export default class Freetext {
       })
       this.layer.renderAnnotation(annotation, true)
     }
-
-    freetextElement.remove()
     freetextElement.removeEventListener('blur', this.onBlur)
+    freetextElement.remove()
     this.freetextElement = null
   }
 

+ 13 - 6
packages/core/src/annotation/text.js

@@ -36,6 +36,7 @@ export default class Text extends Base {
     this.initial = false
     this.outline = null
 
+    this.rect = null
     this.start = null
     this.end = null
 
@@ -62,7 +63,7 @@ export default class Text extends Base {
   render () {
     this.renderTextElement()
     this.renderTextEditor()
-    
+
     this.container.append(this.annotationContainer)
   }
 
@@ -231,6 +232,9 @@ export default class Text extends Base {
 
     this.annotationContainer.style.top = rect.top + 'px'
     this.annotationContainer.style.left = rect.left + 'px'
+
+    this.textEditorContainer.style.top = rect.top + 28 + 'px'
+    this.textEditorContainer.style.left = rect.left + 16 + 'px'
   }
 
   rectCalc ({start, end}) {
@@ -294,11 +298,10 @@ export default class Text extends Base {
     this.eventBus.dispatch('closeTextEditor', event.target.closest('.annotation.text'))
     if (this.popShow) return
     this.popShow = true
-    this.annotationContainer.append(this.textEditorContainer)
-    this.annotationContainer.style.zIndex = 7
+    this.layer.pageDiv.append(this.textEditorContainer)
     this.textEditorElement.focus()
     keepLastIndex(this.textEditorElement)
-    onClickOutside([this.annotationContainer], this.handleClickOutside.bind(this))
+    onClickOutside([this.annotationContainer, this.textEditorContainer], this.handleClickOutside.bind(this))
   }
 
   updateTool () {
@@ -337,6 +340,8 @@ export default class Text extends Base {
 
     const rect = this.rectCalc({start, end})
 
+    this.rect = rect
+
     let annotationContainer = document.createElement('div')
     annotationContainer.id = annotation.name
     annotationContainer.className = 'annotation text'
@@ -360,8 +365,10 @@ export default class Text extends Base {
     this.textEditorContainer = textEditorContainer
     this.setCss(textEditorContainer, {
       position: 'absolute',
-      left: '16px',
-      top: '28px',
+      left: this.rect.left + 16 + 'px',
+      top: this.rect.top + 28 + 'px',
+      zIndex: 2,
+      color: this.annotation.color.getColor() || '#FF0000',
       border: '2px solid',
       borderColor: this.annotation.color || '#FF0000',
       outline: 'none',

+ 7 - 0
packages/webview/src/assets/main.scss

@@ -195,6 +195,13 @@ input, textarea, select {
   }
 }
 
+.annotationContainer {
+  overflow: hidden;
+  position: relative;
+  width: 100%;
+  height: 100%;
+}
+
 .annotationContainer > div {
   position: absolute;
   cursor: pointer;

+ 23 - 3
packages/webview/src/components/DocumentContainer/DocumentContainer.vue

@@ -426,7 +426,6 @@ onMounted(async () => {
 .document .page {
   position: relative;
   margin: 20px auto;
-  overflow: hidden;
   background-clip: content-box;
   background-color: rgba(255, 255, 255, 1);
 
@@ -455,19 +454,22 @@ onMounted(async () => {
   }
 }
 
-.document.scrollHorizontal,
 .document.scrollHorizontal,
 .spread {
   white-space: nowrap;
   text-align: center;
 
-  .spread,
   .page {
     display: inline-block;
     margin: 20px;
     vertical-align: middle;
   }
 }
+.pdfPresentationMode .page {
+  margin: 2px;
+  display: inline-block;
+  vertical-align: middle;
+}
 
 .document.scrollHorizontal .spread {
   margin: 0px;
@@ -678,6 +680,24 @@ onMounted(async () => {
   display: none !important;
 }
 
+.document-container.pdfPresentationMode {
+  top: 0;
+  background-color: rgb(0 0 0);
+  width: 100%;
+  height: 100%;
+  overflow: hidden;
+  cursor: none;
+  user-select: none;
+}
+
+.document .dummyPage {
+  position: relative;
+  width: 0;
+  height: 100vh;
+  display: inline-block;
+  vertical-align: middle;
+}
+
 @keyframes caretanimation {
   0% {
     color: #000;

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

@@ -25,6 +25,13 @@
     isEditorPanelDisabled.value = !editTextPanelIsActive.value && !document.querySelector(".frame-container.editing")
   })
 
+  watch(toolMode, (newValue, oldValue) => {
+    if (oldValue === 'form' && newValue !== 'form') {
+      useViewer.closeElement(item.element)
+      core.toggleSidebar()
+    }
+  })
+
   const onClick = () => {
     setTimeout(() => {
       if (toolMode.value === 'form') {