Browse Source

:bug: typeWriteMode

Liyuan Li 5 years ago
parent
commit
fe2cfdcfc4
3 changed files with 11 additions and 13 deletions
  1. 1 0
      CHANGELOG.md
  2. 1 1
      demo/index.js
  3. 9 12
      src/ts/util/editorCommonEvent.ts

+ 1 - 0
CHANGELOG.md

@@ -59,6 +59,7 @@
 
 ### v3.1.5 / 2020-04-0x
 
+* [302](https://github.com/Vanessa219/vditor/issues/302) Editing Heading(IR mode) `修复缺陷`
 * [301](https://github.com/Vanessa219/vditor/issues/301) Add README in English `文档相关`
 
 ### v3.1.4 / 2020-04-10

+ 1 - 1
demo/index.js

@@ -15,7 +15,7 @@ window.vditor = new Vditor('vditor', {
   },
   counter: {
     enable: true,
-    max: 100,
+    type: 'text'
   },
   height: 500,
   hint: {

+ 9 - 12
src/ts/util/editorCommonEvent.ts

@@ -24,20 +24,17 @@ export const focusEvent = (vditor: IVditor, editorElement: HTMLElement) => {
 };
 
 export const scrollCenter = (vditor: IVditor) => {
-    if (vditor.options.typewriterMode && typeof vditor.options.height === "string"
-        && !vditor.element.classList.contains("vditor--fullscreen")) {
-        window.scrollTo(window.scrollX, vditor.element.clientHeight + vditor.element.offsetTop - window.innerHeight);
-
+    if (!vditor.options.typewriterMode) {
+        return
+    }
+    const editorElement = vditor[vditor.currentMode].element;
+    const cursorTop = getCursorPosition(editorElement).top;
+    if (typeof vditor.options.height === "string" && !vditor.element.classList.contains("vditor--fullscreen")) {
+        window.scrollTo(window.scrollX,
+            cursorTop + vditor.element.offsetTop + vditor.toolbar.element.offsetHeight - window.innerHeight / 2 + 10);
     }
     if (typeof vditor.options.height === "number" || vditor.element.classList.contains("vditor--fullscreen")) {
-        const editorElement = vditor[vditor.currentMode].element;
-        const cursorTop = getCursorPosition(editorElement).top;
-        const center = editorElement.clientHeight / 2;
-        if (cursorTop > center) {
-            editorElement.scrollTop = editorElement.scrollTop + (cursorTop - center) + 32;
-        } else if (cursorTop < 0) {
-            editorElement.scrollTop = editorElement.scrollTop + cursorTop;
-        }
+        editorElement.scrollTop = cursorTop + editorElement.scrollTop - editorElement.clientHeight / 2 + 10;
     }
 };